Skip to content

The open alternative to Salesforce, designed for AI.

Use existing component for AI chat warnings (#25519)

Thomas des Francs20653233a6e1
diff --git a/packages/twenty-front/src/modules/ai/components/AIChatNoMoreBillingCreditsBanner.tsx b/packages/twenty-front/src/modules/ai/components/AIChatNoMoreBillingCreditsBanner.tsx
index c8292ec6216..10512c10253 100644
--- a/packages/twenty-front/src/modules/ai/components/AIChatNoMoreBillingCreditsBanner.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AIChatNoMoreBillingCreditsBanner.tsx
@@ -1,4 +1,4 @@
-import { AiChatBanner } from '@/ai/components/AiChatBanner';
+import { AiChatInlineBanner } from '@/ai/components/AiChatInlineBanner';
import { useAiChatEndTrialPeriod } from '@/ai/hooks/useAiChatEndTrialPeriod';
import { AddCreditCardModal } from '@/settings/billing/components/AddCreditCardModal';
import { StartSubscriptionConfirmationModal } from '@/settings/billing/components/StartSubscriptionConfirmationModal';
@@ -48,19 +48,12 @@ export const AIChatNoMoreBillingCreditsBanner = () => {
if (!hasPermissionToManageBilling) {
return (
- <AiChatBanner
- message={t`Your workspace hit its AI usage limit. Ask an admin to upgrade the plan.`}
- variant="warning"
+ <AiChatInlineBanner
+ message={t`AI usage limit reached. Ask an admin to upgrade the plan.`}
/>
);
}
- const message = isTrialing
- ? t`You've hit your usage limit. Subscribe for more usage.`
- : isDefined(nextPrice)
- ? t`You've hit your usage limit. \nUpgrade to ${nextResourceCreditsAmount ?? ''} credits for $${nextResourceCreditPrice ?? ''}/${nextTierInterval ?? ''}.`
- : t`You've hit your usage limit. \nReach to our support team to upgrade.`;
-
const buttonTitle = isTrialing
? hasPaymentMethod === false
? t`Add Credit Card`
@@ -77,13 +70,22 @@ export const AIChatNoMoreBillingCreditsBanner = () => {
return (
<>
- <AiChatBanner
- message={message}
- variant="warning"
- buttonTitle={buttonTitle}
- buttonOnClick={handleButtonClick}
- isButtonLoading={
- (isTrialing && isEndTrialLoading) || (!isTrialing && isUpgrading)
+ <AiChatInlineBanner
+ message={
+ isTrialing || isDefined(nextPrice)
+ ? t`You’ve reached your AI usage limit.`
+ : t`AI usage limit reached. Contact support to upgrade.`
+ }
+ button={
+ isDefined(buttonTitle) && isDefined(handleButtonClick)
+ ? {
+ title: buttonTitle,
+ onClick: handleButtonClick,
+ disabled:
+ (isTrialing && isEndTrialLoading) ||
+ (!isTrialing && isUpgrading),
+ }
+ : undefined
}
/>
{isTrialing &&
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx b/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx
index ecab59509f0..30c5adf9991 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatApiKeyNotConfiguredMessage.tsx
@@ -1,4 +1,4 @@
-import { AiChatBanner } from '@/ai/components/AiChatBanner';
+import { AiChatInlineBanner } from '@/ai/components/AiChatInlineBanner';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { getDocumentationUrl } from '@/support/utils/getDocumentationUrl';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
@@ -18,12 +18,13 @@ export const AiChatApiKeyNotConfiguredMessage = () => {
};
return (
- <AiChatBanner
- message={t`AI not configured. Set OPENAI_API_KEY, ANTHROPIC_API_KEY, or XAI_API_KEY in your environment.`}
- variant="warning"
- buttonTitle={t`View Docs`}
- buttonIcon={IconExternalLink}
- buttonOnClick={handleDocsClick}
+ <AiChatInlineBanner
+ message={t`Add an API key to enable AI.`}
+ button={{
+ title: t`View Docs`,
+ Icon: IconExternalLink,
+ onClick: handleDocsClick,
+ }}
/>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatBanner.tsx b/packages/twenty-front/src/modules/ai/components/AiChatBanner.tsx
deleted file mode 100644
index cc15e247c5f..00000000000
--- a/packages/twenty-front/src/modules/ai/components/AiChatBanner.tsx
+++ /dev/null
@@ -1,112 +0,0 @@
-import { styled } from '@linaria/react';
-import { isDefined } from 'twenty-shared/utils';
-import {
- type IconComponent,
- IconAlertTriangle,
- IconInfoCircle,
-} from 'twenty-ui/icon';
-import { AppTooltip } from 'twenty-ui/surfaces';
-import { Button } from 'twenty-ui/input';
-import { themeCssVariables } from 'twenty-ui/theme-constants';
-
-type AiChatBannerVariant = 'default' | 'warning';
-
-const StyledBanner = styled.div<{ variant: AiChatBannerVariant }>`
- align-items: center;
- background-color: ${({ variant }) =>
- variant === 'warning'
- ? themeCssVariables.background.transparent.orange
- : themeCssVariables.accent.secondary};
- border-radius: ${themeCssVariables.border.radius.md};
- box-sizing: border-box;
- display: flex;
- gap: ${themeCssVariables.spacing[2]};
- padding: ${themeCssVariables.spacing[2]};
- width: 100%;
-`;
-
-const StyledIconContainer = styled.div<{ variant: AiChatBannerVariant }>`
- align-items: center;
- color: ${({ variant }) =>
- variant === 'warning'
- ? themeCssVariables.color.orange
- : themeCssVariables.color.blue};
- display: flex;
- flex-shrink: 0;
- height: 16px;
- justify-content: center;
- width: 16px;
-`;
-
-const StyledMessage = styled.p<{ variant: AiChatBannerVariant }>`
- color: ${({ variant }) =>
- variant === 'warning'
- ? themeCssVariables.color.orange
- : themeCssVariables.color.blue};
- flex-grow: 1;
- font-family: ${themeCssVariables.font.family};
- font-size: ${themeCssVariables.font.size.sm};
- font-style: normal;
- font-weight: ${themeCssVariables.font.weight.medium};
- line-height: 1.4;
- margin: 0;
- min-width: 0;
- white-space: pre-line;
-`;
-
-export type AiChatBannerProps = {
- message: string;
- variant?: AiChatBannerVariant;
- tooltipMessage?: string;
- buttonTitle?: string;
- buttonIcon?: IconComponent;
- buttonOnClick?: () => void;
- isButtonDisabled?: boolean;
- isButtonLoading?: boolean;
-};
-
-export const AiChatBanner = ({
- message,
- variant = 'default',
- tooltipMessage,
- buttonTitle,
- buttonIcon,
- buttonOnClick,
- isButtonDisabled = false,
- isButtonLoading = false,
-}: AiChatBannerProps) => {
- const tooltipId = 'ai-chat-banner-tooltip';
-
- return (
- <StyledBanner
- variant={variant}
- data-tooltip-id={tooltipMessage ? tooltipId : undefined}
- >
- <StyledIconContainer variant={variant}>
- {variant === 'default' ? (
- <IconInfoCircle size={16} />
- ) : (
- <IconAlertTriangle size={16} />
- )}
- </StyledIconContainer>
- <StyledMessage variant={variant}>{message}</StyledMessage>
- {isDefined(buttonTitle) && isDefined(buttonOnClick) && (
- <Button
- variant="secondary"
- size="small"
- Icon={buttonIcon}
- onClick={buttonOnClick}
- disabled={isButtonDisabled || isButtonLoading}
- title={buttonTitle}
- />
- )}
- {isDefined(tooltipMessage) && (
- <AppTooltip
- anchorSelect={`[data-tooltip-id='${tooltipId}']`}
- content={tooltipMessage}
- place="bottom"
- />
- )}
- </StyledBanner>
- );
-};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx b/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx
index b5505b57fe5..40592b4cc24 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatEditorSection.tsx
@@ -5,9 +5,10 @@ import { EditorContent } from '@tiptap/react';
import { useLingui } from '@lingui/react/macro';
import { themeCssVariables } from 'twenty-ui/theme-constants';
+import { SettingsPath } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
-import { AiChatBanner } from '@/ai/components/AiChatBanner';
+import { AiChatInlineBanner } from '@/ai/components/AiChatInlineBanner';
import { AiChatEmptyState } from '@/ai/components/AiChatEmptyState';
import { AiChatQuestionCard } from '@/ai/components/AiChatQuestionCard';
import { AIChatNoMoreBillingCreditsBanner } from '@/ai/components/AIChatNoMoreBillingCreditsBanner';
@@ -30,11 +31,15 @@ import { useHasReachedAiChatCreditsCap } from '@/ai/hooks/useHasReachedAiChatCre
import { useWorkspaceAiModelAvailability } from '@/ai/hooks/useWorkspaceAiModelAvailability';
import { agentChatUserSelectedModelState } from '@/ai/states/agentChatUserSelectedModelState';
import { agentChatPendingQuestionComponentSelector } from '@/ai/states/selectors/agentChatPendingQuestionComponentSelector';
+import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag';
import { Select } from '@/ui/input/components/Select';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import { useAtomComponentSelectorValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentSelectorValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { type SelectOption } from 'twenty-ui/input';
+import { PermissionFlagType } from '~/generated-metadata/graphql';
+import { useNavigateSettings } from '~/hooks/useNavigateSettings';
+import { SETTINGS_AI_TABS } from '~/pages/settings/ai/constants/SettingsAiTabs';
const StyledInputArea = styled.div<{ isMobile: boolean }>`
align-items: flex-end;
@@ -146,6 +151,10 @@ const StyledRightButtonsContainer = styled.div`
export const AiChatEditorSection = () => {
const { t } = useLingui();
+ const navigateSettings = useNavigateSettings();
+ const hasAiSettingsPermission = useHasPermissionFlag(
+ PermissionFlagType.AI_SETTINGS,
+ );
const isMobile = useIsMobile();
const isComposerCentered = useIsAiChatComposerCentered();
const hasReachedAiChatCreditsCap = useHasReachedAiChatCreditsCap();
@@ -191,9 +200,27 @@ export const AiChatEditorSection = () => {
<StyledInputArea isMobile={isMobile}>
<AgentChatContextPreview />
{hasNoEnabledModels && (
- <AiChatBanner
- message={t`No AI models are enabled in this workspace.`}
- variant="warning"
+ <AiChatInlineBanner
+ message={
+ hasAiSettingsPermission
+ ? t`No AI models are enabled.`
+ : t`Ask your workspace admin to enable an AI model.`
+ }
+ button={
+ hasAiSettingsPermission
+ ? {
+ title: t`Configure models`,
+ onClick: () =>
+ navigateSettings(
+ SettingsPath.AI,
+ undefined,
+ undefined,
+ undefined,
+ SETTINGS_AI_TABS.TABS_IDS.MODELS,
+ ),
+ }
+ : undefined
+ }
/>
)}
{hasReachedAiChatCreditsCap && <AIChatNoMoreBillingCreditsBanner />}
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatInlineBanner.tsx b/packages/twenty-front/src/modules/ai/components/AiChatInlineBanner.tsx
new file mode 100644
index 00000000000..1dff1fbd50a
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/AiChatInlineBanner.tsx
@@ -0,0 +1,14 @@
+import { type ComponentProps } from 'react';
+import { InlineBanner } from 'twenty-ui/feedback';
+
+type AiChatInlineBannerProps = Pick<
+ ComponentProps<typeof InlineBanner>,
+ 'message' | 'button'
+>;
+
+export const AiChatInlineBanner = ({
+ message,
+ button,
+}: AiChatInlineBannerProps) => (
+ <InlineBanner embedded color="danger" message={message} button={button} />
+);
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatBanner.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatBanner.stories.tsx
deleted file mode 100644
index 41681c540ee..00000000000
--- a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatBanner.stories.tsx
+++ /dev/null
@@ -1,39 +0,0 @@
-import { type Meta, type StoryObj } from '@storybook/react-vite';
-import { ComponentDecorator } from 'twenty-ui/testing';
-
-import { AiChatBanner } from '@/ai/components/AiChatBanner';
-
-const meta: Meta<typeof AiChatBanner> = {
- title: 'Modules/AI/AiChatBanner',
- component: AiChatBanner,
- decorators: [ComponentDecorator],
- parameters: {
- container: { width: 400 },
- },
-};
-
-export default meta;
-type Story = StoryObj<typeof AiChatBanner>;
-
-export const NoEnabledModels: Story = {
- args: {
- message: 'No AI models are enabled in this workspace.',
- variant: 'warning',
- },
-};
-
-export const Default: Story = {
- args: {
- message: 'This is an informational message.',
- variant: 'default',
- },
-};
-
-export const WithButton: Story = {
- args: {
- message: "You've hit your usage limit.",
- variant: 'warning',
- buttonTitle: 'Upgrade',
- buttonOnClick: () => {},
- },
-};
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatInlineBanner.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatInlineBanner.stories.tsx
new file mode 100644
index 00000000000..7b4949e100a
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatInlineBanner.stories.tsx
@@ -0,0 +1,73 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { IconExternalLink } from 'twenty-ui/icon';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { AiChatInlineBanner } from '@/ai/components/AiChatInlineBanner';
+
+const meta: Meta<typeof AiChatInlineBanner> = {
+ title: 'Modules/AI/AiChatInlineBanner',
+ component: AiChatInlineBanner,
+ decorators: [ComponentDecorator],
+ parameters: {
+ container: { width: 744 },
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof AiChatInlineBanner>;
+
+export const NoEnabledModels: Story = {
+ args: {
+ message: 'No AI models are enabled.',
+ button: { title: 'Configure models', onClick: () => {} },
+ },
+};
+
+export const NoSettingsPermission: Story = {
+ args: {
+ message: 'Ask your workspace admin to enable an AI model.',
+ },
+};
+
+export const UsageLimit: Story = {
+ args: {
+ message: 'You’ve reached your AI usage limit.',
+ button: { title: 'Upgrade', onClick: () => {} },
+ },
+};
+
+export const UsageLimitLoading: Story = {
+ args: {
+ message: 'You’ve reached your AI usage limit.',
+ button: { title: 'Upgrade', onClick: () => {}, disabled: true },
+ },
+};
+
+export const NoBillingPermission: Story = {
+ args: {
+ message: 'AI usage limit reached. Ask an admin to upgrade the plan.',
+ },
+};
+
+export const ApiKeyNotConfigured: Story = {
+ args: {
+ message: 'Add an API key to enable AI.',
+ button: {
+ title: 'View Docs',
+ Icon: IconExternalLink,
+ onClick: () => {},
+ },
+ },
+};
+
+export const NarrowComposer: Story = {
+ args: {
+ message: 'Add an API key to enable AI.',
+ button: {
+ title: 'View Docs',
+ Icon: IconExternalLink,
+ onClick: () => {},
+ },
+ },
+ parameters: { container: { width: 320 } },
+};
diff --git a/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss b/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss
index 23dbcdd0df4..630ef60fbd0 100644
--- a/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss
+++ b/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss
@@ -3,13 +3,23 @@
margin-bottom: var(--t-spacing-4);
}
+.embedded {
+ margin-bottom: 0;
+}
+
.bannerContent {
align-items: center;
display: flex;
flex: 1;
gap: var(--t-spacing-2);
+ min-width: 0;
+
+ > svg {
+ flex-shrink: 0;
+ }
}
.bannerText {
flex: 1;
+ overflow-wrap: anywhere;
}
diff --git a/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss.d.ts b/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss.d.ts
index c3c16a1e1b9..cb3a98933f8 100644
--- a/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss.d.ts
+++ b/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.module.scss.d.ts
@@ -1,5 +1,6 @@
declare const classNames: {
readonly banner: 'banner';
+ readonly embedded: 'embedded';
readonly bannerContent: 'bannerContent';
readonly bannerText: 'bannerText';
};
diff --git a/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.tsx b/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.tsx
index cfcee4e3333..b6f9a8fc703 100644
--- a/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.tsx
+++ b/packages/twenty-ui/src/feedback/InlineBanner/InlineBanner.tsx
@@ -10,10 +10,13 @@ import styles from './InlineBanner.module.scss';
type InlineBannerProps = {
color?: BannerColor;
message: string;
+ embedded?: boolean;
button?: {
title?: string;
onClick?: () => void;
hidden?: boolean;
+ disabled?: boolean;
+ Icon?: IconComponent;
};
LeftIcon?: IconComponent;
className?: string;
@@ -22,6 +25,7 @@ type InlineBannerProps = {
export const InlineBanner = ({
color,
message,
+ embedded = false,
button,
LeftIcon = IconInfoCircle,
className,
@@ -30,7 +34,7 @@ export const InlineBanner = ({
return (
<Banner
- className={clsx(styles.banner, className)}
+ className={clsx(styles.banner, embedded && styles.embedded, className)}
color={color}
variant={'secondary'}
>
@@ -45,6 +49,8 @@ export const InlineBanner = ({
accent={color}
title={button?.title}
onClick={button?.onClick}
+ disabled={button.disabled}
+ Icon={button.Icon}
/>
)}
</Banner>
diff --git a/packages/twenty-ui/src/feedback/InlineBanner/__stories__/InlineBanner.stories.tsx b/packages/twenty-ui/src/feedback/InlineBanner/__stories__/InlineBanner.stories.tsx
new file mode 100644
index 00000000000..fcfc6c25224
--- /dev/null
+++ b/packages/twenty-ui/src/feedback/InlineBanner/__stories__/InlineBanner.stories.tsx
@@ -0,0 +1,86 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, fn, userEvent, within } from 'storybook/test';
+
+import { InlineBanner } from '@ui/feedback/InlineBanner/InlineBanner';
+import { IconExternalLink } from '@ui/icon';
+import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';
+
+const meta: Meta<typeof InlineBanner> = {
+ title: 'UI/Feedback/InlineBanner',
+ component: InlineBanner,
+ decorators: [ComponentDecorator],
+ parameters: {
+ a11y: A11Y_DEFER_COLOR_CONTRAST,
+ container: { width: 744 },
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof InlineBanner>;
+
+export const Default: Story = {
+ args: {
+ color: 'danger',
+ message: 'No AI models are enabled.',
+ button: { title: 'Configure models', onClick: fn() },
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const button = await canvas.findByRole('button', {
+ name: /Configure models/,
+ });
+
+ await expect(button).toBeEnabled();
+ await userEvent.click(button);
+ await expect(args.button?.onClick).toHaveBeenCalledTimes(1);
+ },
+};
+
+export const DisabledAction: Story = {
+ args: {
+ color: 'danger',
+ message: 'You’ve reached your AI usage limit.',
+ button: { title: 'Upgrade', onClick: fn(), disabled: true },
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const button = await canvas.findByRole('button', { name: /Upgrade/ });
+
+ await expect(button).toBeDisabled();
+ await userEvent.click(button);
+ await expect(args.button?.onClick).not.toHaveBeenCalled();
+ },
+};
+
+export const WithoutAction: Story = {
+ args: {
+ color: 'danger',
+ message: 'Ask your workspace admin to enable an AI model.',
+ },
+};
+
+export const DocumentationAction: Story = {
+ args: {
+ color: 'danger',
+ message: 'Add an API key to enable AI.',
+ button: { title: 'View Docs', Icon: IconExternalLink, onClick: fn() },
+ },
+};
+
+export const Narrow: Story = {
+ args: {
+ color: 'danger',
+ message: 'No AI models are enabled.',
+ button: { title: 'Configure models', onClick: fn() },
+ },
+ parameters: { container: { width: 320 } },
+};
+
+export const Embedded: Story = {
+ args: {
+ color: 'danger',
+ message: 'No AI models are enabled.',
+ button: { title: 'Configure models', onClick: fn() },
+ embedded: true,
+ },
+};