Skip to content

The open alternative to Salesforce, designed for AI.

Open onboarding AI chat beside the workspace homepage (#25614)

Thomas des Francs41be22f46823
diff --git a/packages/twenty-front/src/hooks/__tests__/usePageChangeEffectNavigateLocation.test.ts b/packages/twenty-front/src/hooks/__tests__/usePageChangeEffectNavigateLocation.test.ts
index fad87a7e43a..a59c95f72a3 100644
--- a/packages/twenty-front/src/hooks/__tests__/usePageChangeEffectNavigateLocation.test.ts
+++ b/packages/twenty-front/src/hooks/__tests__/usePageChangeEffectNavigateLocation.test.ts
@@ -105,7 +105,6 @@ const setupMockState = (
currentWorkspace: object | null = { id: 'mock-workspace-id' },
isBillingEnabled: boolean = true,
isMinimalMetadataReady: boolean = true,
- shouldOpenAiChatAfterOnboarding: boolean = false,
isOnboardingCheckoutPending: boolean = false,
) => {
jest
@@ -116,7 +115,6 @@ const setupMockState = (
.mockReturnValueOnce(isMinimalMetadataReady)
.mockReturnValueOnce(verifyEmailRedirectPath)
.mockReturnValueOnce(returnToPath ?? '')
- .mockReturnValueOnce(shouldOpenAiChatAfterOnboarding)
.mockReturnValueOnce(isOnboardingCheckoutPending);
};
@@ -136,7 +134,6 @@ const testCases: {
useQueryResult?: { data?: unknown; loading?: boolean };
isBillingEnabled?: boolean;
isMinimalMetadataReady?: boolean;
- shouldOpenAiChatAfterOnboarding?: boolean;
isOnboardingCheckoutPending?: boolean;
}[] = [
{ loc: AppPath.Verify, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.PLAN_REQUIRED, res: AppPath.PlanRequired },
@@ -452,10 +449,6 @@ const testCases: {
{ loc: AppPath.SignInUp, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, returnToPath: '/objects/tasks', res: '/objects/tasks' },
{ loc: AppPath.Index, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, returnToPath: '/settings/api-keys', res: '/settings/api-keys' },
- { loc: AppPath.InviteTeam, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, isBillingEnabled: false, shouldOpenAiChatAfterOnboarding: true, res: getAppPath(AppPath.AiChat, { threadId: null }) },
- { loc: AppPath.InviteTeam, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, isBillingEnabled: false, shouldOpenAiChatAfterOnboarding: false, res: defaultHomePagePath },
- { loc: AppPath.PlanRequiredSuccess, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, shouldOpenAiChatAfterOnboarding: true, res: getAppPath(AppPath.AiChat, { threadId: null }) },
- { loc: AppPath.SignInUp, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, shouldOpenAiChatAfterOnboarding: true, returnToPath: '/objects/tasks', res: '/objects/tasks' },
{ loc: AppPath.PlanRequiredSuccess, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, isOnboardingCheckoutPending: true, res: undefined },
{ loc: AppPath.Verify, isLogged: true, isWorkspaceSuspended: false, onboardingStatus: OnboardingStatus.COMPLETED, isOnboardingCheckoutPending: true, res: defaultHomePagePath },
@@ -482,7 +475,6 @@ describe('usePageChangeEffectNavigateLocation', () => {
useQueryResult,
isBillingEnabled,
isMinimalMetadataReady,
- shouldOpenAiChatAfterOnboarding,
isOnboardingCheckoutPending,
res,
}) => {
@@ -501,7 +493,6 @@ describe('usePageChangeEffectNavigateLocation', () => {
undefined,
isBillingEnabled ?? true,
isMinimalMetadataReady ?? true,
- shouldOpenAiChatAfterOnboarding ?? false,
isOnboardingCheckoutPending ?? false,
);
@@ -534,10 +525,6 @@ describe('usePageChangeEffectNavigateLocation', () => {
'billingDisabled:planRequiredCompleted',
].length +
[
- 'workspaceSetupPending:inviteTeamCompleted',
- 'workspaceSetupNotPending:inviteTeamCompleted',
- 'workspaceSetupPending:paymentSuccessCompleted',
- 'workspaceSetupPending:returnToPathWins',
'checkoutPending:paymentSuccessDefersRedirect',
'checkoutPending:verifyStillRedirects',
].length,
diff --git a/packages/twenty-front/src/hooks/usePageChangeEffectNavigateLocation.ts b/packages/twenty-front/src/hooks/usePageChangeEffectNavigateLocation.ts
index 16929ad42a1..39841aac1df 100644
--- a/packages/twenty-front/src/hooks/usePageChangeEffectNavigateLocation.ts
+++ b/packages/twenty-front/src/hooks/usePageChangeEffectNavigateLocation.ts
@@ -11,7 +11,6 @@ import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePat
import { objectMetadataItemsSelector } from '@/object-metadata/states/objectMetadataItemsSelector';
import { useOnboardingStatus } from '@/onboarding/hooks/useOnboardingStatus';
import { isOnboardingCheckoutPendingState } from '@/onboarding/states/isOnboardingCheckoutPendingState';
-import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useIsWorkspaceActivationStatusEqualsTo } from '@/workspace/hooks/useIsWorkspaceActivationStatusEqualsTo';
import { isValidReturnToPath } from '@/auth/utils/isValidReturnToPath';
@@ -19,7 +18,7 @@ import { useQuery } from '@apollo/client/react';
import { isNonEmptyString } from '@sniptt/guards';
import { matchPath, useLocation } from 'react-router-dom';
import { AppPath, SettingsPath } from 'twenty-shared/types';
-import { isDefined, getAppPath } from 'twenty-shared/utils';
+import { isDefined } from 'twenty-shared/utils';
import { WorkspaceActivationStatus } from 'twenty-shared/workspace';
import {
FindOnePageLayoutTypeDocument,
@@ -82,13 +81,6 @@ export const usePageChangeEffectNavigateLocation = () => {
? returnToPath
: readReturnToPathFromUrlSearchParams();
- const shouldOpenAiChatAfterOnboarding = useAtomStateValue(
- shouldOpenAiChatAfterOnboardingState,
- );
- const onboardingCompletedPath = shouldOpenAiChatAfterOnboarding
- ? getAppPath(AppPath.AiChat, { threadId: null })
- : defaultHomePagePath;
-
const isOnboardingCheckoutPending = useAtomStateValue(
isOnboardingCheckoutPendingState,
);
@@ -198,7 +190,7 @@ export const usePageChangeEffectNavigateLocation = () => {
return;
}
- return resolvedReturnToPath ?? onboardingCompletedPath;
+ return resolvedReturnToPath ?? defaultHomePagePath;
}
if (isMatchingLocation(location, AppPath.Index) && isLogged) {
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatPageHeader.tsx b/packages/twenty-front/src/modules/ai/components/AiChatPageHeader.tsx
index ab38f9ef106..43644550ccf 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatPageHeader.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatPageHeader.tsx
@@ -43,11 +43,7 @@ const StyledHeaderTitle = styled.div`
white-space: nowrap;
`;
-type AiChatPageHeaderProps = {
- isOnboarding: boolean;
-};
-
-export const AiChatPageHeader = ({ isOnboarding }: AiChatPageHeaderProps) => {
+export const AiChatPageHeader = () => {
const { t } = useLingui();
const isMobile = useIsMobile();
const isNavigationDrawerExpanded = useNavigationDrawerExpanded();
@@ -64,21 +60,15 @@ export const AiChatPageHeader = ({ isOnboarding }: AiChatPageHeaderProps) => {
{!isNavigationDrawerExpanded && !isMobile && (
<NavigationDrawerCollapseButton direction="right" />
)}
- {isDefined(currentAiChatThreadData) && !isOnboarding ? (
+ {isDefined(currentAiChatThreadData) ? (
<AiChatPageThreadHeader
key={currentAiChatThreadData.id}
thread={currentAiChatThreadData}
/>
) : (
- <StyledHeaderTitle>
- {isOnboarding ? t`Onboarding` : isNewChat ? t`New chat` : null}
- </StyledHeaderTitle>
- )}
- {isMobile ? (
- <AiChatCloseButton variant="primary" />
- ) : (
- isOnboarding && <AiChatCloseButton />
+ <StyledHeaderTitle>{isNewChat ? t`New chat` : null}</StyledHeaderTitle>
)}
+ {isMobile && <AiChatCloseButton variant="primary" />}
<AiChatThreadDeleteConfirmationModal
surface={AI_CHAT_THREAD_ACTIONS_SURFACE.PAGE_HEADER}
/>
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatTab.tsx b/packages/twenty-front/src/modules/ai/components/AiChatTab.tsx
index 34f716c69c9..a8d60fc3cba 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatTab.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatTab.tsx
@@ -1,3 +1,7 @@
+import { AiChatMessageListPreambleContext } from '@/ai/contexts/AiChatMessageListPreambleContext';
+import { useIsWorkspaceSetupChat } from '@/ai/hooks/useIsWorkspaceSetupChat';
+import { WorkspaceSetupChatPreamble } from '@/onboarding/components/WorkspaceSetupChatPreamble';
+import { WorkspaceSetupChatKickoffEffect } from '@/onboarding/effect-components/WorkspaceSetupChatKickoffEffect';
import { styled } from '@linaria/react';
import { type DragEvent, useState } from 'react';
import { themeCssVariables } from 'twenty-ui/theme-constants';
@@ -26,6 +30,7 @@ const StyledContainer = styled.div<{ isDraggingFile: boolean }>`
`;
export const AiChatTab = () => {
+ const isWorkspaceSetupChat = useIsWorkspaceSetupChat();
const [isDraggingFile, setIsDraggingFile] = useState(false);
const currentAiChatThread = useAtomStateValue(currentAiChatThreadState);
const threadIdCreatedFromDraft = useAtomStateValue(
@@ -64,6 +69,7 @@ export const AiChatTab = () => {
onDragOver={(event) => event.preventDefault()}
onDrop={handleDrop}
>
+ {isWorkspaceSetupChat && <WorkspaceSetupChatKickoffEffect />}
<AgentChatHasBeenOpenedEffect />
<AgentChatStreamingPartsDiffSyncEffect />
{isDraggingFile && (
@@ -73,11 +79,13 @@ export const AiChatTab = () => {
/>
)}
{!isDraggingFile && (
- <>
+ <AiChatMessageListPreambleContext.Provider
+ value={isWorkspaceSetupChat ? <WorkspaceSetupChatPreamble /> : null}
+ >
<AiChatTabMessageList />
<AiChatQueuedMessages />
<AiChatEditorSection key={editorSectionKey} />
- </>
+ </AiChatMessageListPreambleContext.Provider>
)}
</StyledContainer>
);
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx b/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx
index 1a169c127f9..f4d7fce4fae 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatTabMessageList.tsx
@@ -1,3 +1,4 @@
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
import { MarkdownLoadingSkeleton } from '@/ai/components/LazyMarkdownRenderer';
import { StyledAiChatContentContainer } from '@/ai/components/StyledAiChatContentContainer';
import { AiChatErrorUnderMessageList } from '@/ai/components/AiChatErrorUnderMessageList';
@@ -51,8 +52,9 @@ export const AiChatTabMessageList = () => {
agentChatHasMessageComponentSelector,
);
- const scrollWrapperInstanceId =
- getAiChatScrollWrapperInstanceId(aiChatSurface);
+ const scrollWrapperInstanceId = getAiChatScrollWrapperInstanceId(
+ aiChatSurface ?? AI_CHAT_SURFACE.SIDE_PANEL,
+ );
if (!agentChatHasMessage) {
if (!isDefined(messageListPreamble)) {
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx
new file mode 100644
index 00000000000..69598b5b468
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatTab.stories.tsx
@@ -0,0 +1,91 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { useStore } from 'jotai';
+import { Suspense, useEffect, useState } from 'react';
+import { expect, waitFor, within } from 'storybook/test';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { AiChatTab } from '@/ai/components/AiChatTab';
+import { AGENT_CHAT_INSTANCE_ID } from '@/ai/constants/AgentChatInstanceId';
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
+import { AgentChatComponentInstanceContext } from '@/ai/contexts/AgentChatComponentInstanceContext';
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
+import { hasRequestedWorkspaceSetupChatState } from '@/onboarding/states/hasRequestedWorkspaceSetupChatState';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
+import { RootDecorator } from '~/testing/decorators/RootDecorator';
+import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';
+import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
+
+const WorkspaceSetupChatStory = () => {
+ const store = useStore();
+ const [isReady, setIsReady] = useState(false);
+
+ useEffect(() => {
+ store.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ store.set(hasRequestedWorkspaceSetupChatState.atom, true);
+ setIsReady(true);
+
+ return () => {
+ store.set(shouldOpenAiChatAfterOnboardingState.atom, false);
+ store.set(hasRequestedWorkspaceSetupChatState.atom, false);
+ };
+ }, [store]);
+
+ return isReady ? (
+ <AgentChatComponentInstanceContext.Provider
+ value={{ instanceId: AGENT_CHAT_INSTANCE_ID }}
+ >
+ <AiChatSurfaceContext.Provider value={AI_CHAT_SURFACE.SIDE_PANEL}>
+ <Suspense fallback={null}>
+ <AiChatTab />
+ </Suspense>
+ </AiChatSurfaceContext.Provider>
+ </AgentChatComponentInstanceContext.Provider>
+ ) : null;
+};
+
+const meta = {
+ title: 'Modules/AI/AiChatTab',
+ component: AiChatTab,
+ decorators: [
+ ComponentDecorator,
+ RootDecorator,
+ SnackBarDecorator,
+ MemoryRouterDecorator,
+ ],
+ parameters: { container: { width: 480, height: 700 } },
+} satisfies Meta<typeof AiChatTab>;
+
+export default meta;
+type Story = StoryObj<typeof meta>;
+
+export const WorkspaceSetup: Story = {
+ render: () => <WorkspaceSetupChatStory />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ await expect(
+ await canvas.findByText('Welcome to your workspace'),
+ ).toBeVisible();
+ await expect(canvas.getByRole('textbox')).toBeVisible();
+ },
+};
+
+export const WorkspaceSetupCompletion: Story = {
+ render: () => <WorkspaceSetupChatStory />,
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ await expect(
+ await canvas.findByText('Welcome to your workspace'),
+ ).toBeVisible();
+ await expect(canvas.getByRole('textbox')).toBeVisible();
+
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, false);
+
+ await waitFor(() =>
+ expect(
+ canvas.queryByText('Welcome to your workspace'),
+ ).not.toBeInTheDocument(),
+ );
+ await expect(canvas.getByRole('textbox')).toBeVisible();
+ },
+};
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx
index d78688747db..e517566ae77 100644
--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatPageHeader.test.tsx
@@ -97,7 +97,7 @@ describe('AiChatPageHeader', () => {
'hides conversation actions on the new-chat page (%s)',
(threadId) => {
jotaiStore.set(currentAiChatThreadState.atom, threadId);
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
expect(screen.getByText('New chat')).toBeVisible();
expect(screen.queryByRole('button', { name: /^New chat/ })).toBeNull();
@@ -107,7 +107,7 @@ describe('AiChatPageHeader', () => {
it('starts a new chat from the current conversation', async () => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
expect(screen.getByText('Best leads')).toBeVisible();
await user.click(screen.getByRole('button', { name: /^New chat/ }));
@@ -119,7 +119,7 @@ describe('AiChatPageHeader', () => {
it('does not label an existing chat as new while its metadata loads', () => {
setThreads([]);
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
expect(screen.queryByText('New chat')).toBeNull();
expect(screen.queryByRole('button', { name: 'Chat actions' })).toBeNull();
@@ -134,7 +134,7 @@ describe('AiChatPageHeader', () => {
'keeps New chat hidden without messages regardless of token usage (%s)',
(conversationSize) => {
setThreads([{ ...THREAD, lastMessageAt: null, conversationSize }]);
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
expect(screen.queryByRole('button', { name: /^New chat/ })).toBeNull();
},
@@ -143,7 +143,7 @@ describe('AiChatPageHeader', () => {
it('shows New chat as soon as messages load without a last-message timestamp', () => {
setThreads([{ ...THREAD, lastMessageAt: null }]);
jotaiStore.set(agentChatDisplayedThreadState.atom, THREAD.id);
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
expect(screen.queryByRole('button', { name: /^New chat/ })).toBeNull();
@@ -170,7 +170,7 @@ describe('AiChatPageHeader', () => {
}),
[{ id: 'previous-message', role: 'user', parts: [] }],
);
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
expect(screen.queryByRole('button', { name: /^New chat/ })).toBeNull();
@@ -187,19 +187,23 @@ describe('AiChatPageHeader', () => {
expect(screen.getByRole('button', { name: /^New chat/ })).toBeVisible();
});
- it('keeps onboarding single-threaded', () => {
- render(<AiChatPageHeader isOnboarding />, { wrapper: Wrapper });
+ it('offers the standard conversation actions', async () => {
+ const user = userEvent.setup();
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
- expect(screen.getByText('Onboarding')).toBeVisible();
- expect(screen.queryByRole('button', { name: /^New chat/ })).toBeNull();
- expect(screen.queryByRole('button', { name: 'Chat actions' })).toBeNull();
- expect(screen.getByRole('button', { name: 'Close chat' })).toBeVisible();
+ expect(screen.getByText('Best leads')).toBeVisible();
+ await user.click(screen.getByRole('button', { name: /^New chat/ }));
+ expect(switchToNewChat).toHaveBeenCalledTimes(1);
+ await user.click(screen.getByRole('button', { name: 'Chat actions' }));
+ expect(screen.getByText('Rename')).toBeVisible();
+ expect(screen.getByText('Archive')).toBeVisible();
+ expect(screen.getByText('Delete')).toBeVisible();
});
it('uses the generated title before metadata refreshes and prefers later renames', async () => {
setThreads([{ ...THREAD, title: null }]);
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
act(() => {
jotaiStore.set(
@@ -232,7 +236,7 @@ describe('AiChatPageHeader', () => {
it('offers archive and unarchive even when the current chat is filtered out of the sidebar', async () => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Archive'));
@@ -248,7 +252,7 @@ describe('AiChatPageHeader', () => {
it('renames the current chat and discards the rename editor when switching threads', async () => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Rename'));
@@ -271,7 +275,7 @@ describe('AiChatPageHeader', () => {
'saves once and leaves the rename editor on %s',
async (key) => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Rename'));
@@ -290,7 +294,7 @@ describe('AiChatPageHeader', () => {
it('saves when clicking outside without swallowing the next action', async () => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Rename'));
@@ -306,7 +310,7 @@ describe('AiChatPageHeader', () => {
it('discards the draft on Escape without saving', async () => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Rename'));
@@ -321,7 +325,7 @@ describe('AiChatPageHeader', () => {
it('preserves the draft for retry when saving fails', async () => {
renameChatThread.mockResolvedValueOnce(false);
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Rename'));
@@ -343,7 +347,7 @@ describe('AiChatPageHeader', () => {
it('requires confirmation before deleting the current chat', async () => {
const user = userEvent.setup();
- render(<AiChatPageHeader isOnboarding={false} />, { wrapper: Wrapper });
+ render(<AiChatPageHeader />, { wrapper: Wrapper });
await user.click(screen.getByRole('button', { name: 'Chat actions' }));
await user.click(screen.getByText('Delete'));
diff --git a/packages/twenty-front/src/modules/ai/contexts/AiChatSurfaceContext.ts b/packages/twenty-front/src/modules/ai/contexts/AiChatSurfaceContext.ts
index aa4ddf0035d..3abed61f99d 100644
--- a/packages/twenty-front/src/modules/ai/contexts/AiChatSurfaceContext.ts
+++ b/packages/twenty-front/src/modules/ai/contexts/AiChatSurfaceContext.ts
@@ -1,8 +1,7 @@
import { createContext } from 'react';
-import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
import { type AiChatSurface } from '@/ai/types/AiChatSurface';
-export const AiChatSurfaceContext = createContext<AiChatSurface>(
- AI_CHAT_SURFACE.SIDE_PANEL,
+export const AiChatSurfaceContext = createContext<AiChatSurface | undefined>(
+ undefined,
);
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useAgentChatModelId.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useAgentChatModelId.test.tsx
index 4dcc0b9bd67..210c3b71a81 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useAgentChatModelId.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useAgentChatModelId.test.tsx
@@ -1,6 +1,9 @@
import { act, renderHook } from '@testing-library/react';
import { Provider as JotaiProvider } from 'jotai';
import { MemoryRouter } from 'react-router-dom';
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
+import { type AiChatSurface } from '@/ai/types/AiChatSurface';
import { AppPath } from 'twenty-shared/types';
import { getAppPath } from 'twenty-shared/utils';
@@ -16,19 +19,25 @@ import {
} from '@/ui/utilities/state/jotai/jotaiStore';
const getWrapper =
- (pathname: string) =>
+ (pathname: string, surface?: AiChatSurface) =>
({ children }: { children: React.ReactNode }) => (
<MemoryRouter initialEntries={[pathname]}>
- <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>
+ <JotaiProvider store={jotaiStore}>
+ <AiChatSurfaceContext.Provider value={surface}>
+ {children}
+ </AiChatSurfaceContext.Provider>
+ </JotaiProvider>
</MemoryRouter>
);
const renderHooks = ({
pathname,
userSelectedModel = null,
+ surface,
}: {
pathname: string;
userSelectedModel?: string | null;
+ surface?: AiChatSurface;
}) => {
const { result } = renderHook(
() => {
@@ -45,7 +54,7 @@ const renderHooks = ({
...useAgentChatModelId(),
};
},
- { wrapper: getWrapper(pathname) },
+ { wrapper: getWrapper(pathname, surface) },
);
act(() => {
@@ -72,13 +81,16 @@ describe('useAgentChatModelId', () => {
resetJotaiStore();
});
- it('should request the workspace fast model during the onboarding chat', () => {
- jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ it.each([onboardingChatPath, '/objects/companies'])(
+ 'should request the workspace fast model during onboarding on %s',
+ (pathname) => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
- const result = renderHooks({ pathname: onboardingChatPath });
+ const result = renderHooks({ pathname });
- expect(result.current.modelIdForRequest).toBe('openai/gpt-5-mini');
- });
+ expect(result.current.modelIdForRequest).toBe('openai/gpt-5-mini');
+ },
+ );
it('should request no model on a plain chat page', () => {
const result = renderHooks({ pathname: onboardingChatPath });
@@ -86,6 +98,22 @@ describe('useAgentChatModelId', () => {
expect(result.current.modelIdForRequest).toBeUndefined();
});
+ it.each([undefined, AI_CHAT_SURFACE.PAGE, AI_CHAT_SURFACE.SIDE_PANEL])(
+ 'keeps sends, retries and answers on the fast model in surface %s',
+ (surface) => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ const result = renderHooks({ pathname: onboardingChatPath, surface });
+
+ expect(result.current.modelIdForRequest).toBe('openai/gpt-5-mini');
+
+ act(() =>
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, false),
+ );
+
+ expect(result.current.modelIdForRequest).toBeUndefined();
+ },
+ );
+
it('should request no model elsewhere so the server falls back to the smart model', () => {
const result = renderHooks({ pathname: '/objects/companies' });
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useAiModelOptions.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useAiModelOptions.test.tsx
index 8b2c9948ec6..cb1451fd982 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useAiModelOptions.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useAiModelOptions.test.tsx
@@ -1,6 +1,8 @@
import { act, renderHook } from '@testing-library/react';
import { Provider as JotaiProvider } from 'jotai';
import { MemoryRouter } from 'react-router-dom';
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
import { AppPath } from 'twenty-shared/types';
import { getAppPath } from 'twenty-shared/utils';
@@ -18,7 +20,11 @@ const getWrapper =
(pathname: string) =>
({ children }: { children: React.ReactNode }) => (
<MemoryRouter initialEntries={[pathname]}>
- <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>
+ <JotaiProvider store={jotaiStore}>
+ <AiChatSurfaceContext.Provider value={AI_CHAT_SURFACE.SIDE_PANEL}>
+ {children}
+ </AiChatSurfaceContext.Provider>
+ </JotaiProvider>
</MemoryRouter>
);
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useIsWorkspaceSetupChat.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useIsWorkspaceSetupChat.test.tsx
new file mode 100644
index 00000000000..9519fde0567
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useIsWorkspaceSetupChat.test.tsx
@@ -0,0 +1,33 @@
+import { renderHook } from '@testing-library/react';
+import { Provider } from 'jotai';
+import { type ReactNode } from 'react';
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
+import { useIsWorkspaceSetupChat } from '@/ai/hooks/useIsWorkspaceSetupChat';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
+import {
+ jotaiStore,
+ resetJotaiStore,
+} from '@/ui/utilities/state/jotai/jotaiStore';
+
+describe('useIsWorkspaceSetupChat', () => {
+ beforeEach(() => resetJotaiStore());
+
+ it.each([AI_CHAT_SURFACE.PAGE, AI_CHAT_SURFACE.SIDE_PANEL, undefined])(
+ 'only enables setup within a chat surface: %s',
+ (surface) => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <Provider store={jotaiStore}>
+ <AiChatSurfaceContext.Provider value={surface}>
+ {children}
+ </AiChatSurfaceContext.Provider>
+ </Provider>
+ );
+ const { result } = renderHook(() => useIsWorkspaceSetupChat(), {
+ wrapper,
+ });
+ expect(result.current).toBe(surface !== undefined);
+ },
+ );
+});
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useProcessWorkspaceSetupCompletion.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useProcessWorkspaceSetupCompletion.test.tsx
index 53f2792ed82..ced8c7f5974 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useProcessWorkspaceSetupCompletion.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useProcessWorkspaceSetupCompletion.test.tsx
@@ -1,3 +1,6 @@
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { act, renderHook } from '@testing-library/react';
import { Provider as JotaiProvider } from 'jotai';
import { type ReactNode } from 'react';
@@ -20,8 +23,9 @@ jest.mock('react-router-dom', () => ({
useLocation: () => ({ state: null }),
}));
+let defaultHomePagePath = '/objects/people';
jest.mock('@/navigation/hooks/useDefaultHomePagePath', () => ({
- useDefaultHomePagePath: () => ({ defaultHomePagePath: '/objects/people' }),
+ useDefaultHomePagePath: () => ({ defaultHomePagePath }),
}));
const closeSidePanelMenuMock = jest.fn();
@@ -43,7 +47,9 @@ const Wrapper = ({ children }: { children: ReactNode }) => (
<AgentChatComponentInstanceContext.Provider
value={{ instanceId: INSTANCE_ID }}
>
- {children}
+ <AiChatSurfaceContext.Provider value={AI_CHAT_SURFACE.PAGE}>
+ {children}
+ </AiChatSurfaceContext.Provider>
</AgentChatComponentInstanceContext.Provider>
</JotaiProvider>
);
@@ -76,9 +82,36 @@ describe('useProcessWorkspaceSetupCompletion', () => {
sessionStorage.clear();
resetJotaiStore();
isWorkspaceSetupChat = true;
+ defaultHomePagePath = '/objects/people';
});
- it('should redirect to the companies view and move the chat to the side panel', () => {
+ it('keeps the current page and side panel open when setup finishes there', () => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ const { result } = renderHook(() => useProcessWorkspaceSetupCompletion(), {
+ wrapper: ({ children }) => (
+ <Wrapper>
+ <AiChatSurfaceContext.Provider value={AI_CHAT_SURFACE.SIDE_PANEL}>
+ {children}
+ </AiChatSurfaceContext.Provider>
+ </Wrapper>
+ ),
+ });
+
+ act(() =>
+ result.current.processWorkspaceSetupCompletion(
+ buildCompletionMessage('side-panel-call'),
+ ),
+ );
+
+ expect(navigateMock).not.toHaveBeenCalled();
+ expect(closeSidePanelMenuMock).not.toHaveBeenCalled();
+ expect(jotaiStore.get(shouldOpenAiChatAfterOnboardingState.atom)).toBe(
+ false,
+ );
+ expect(getProcessedToolCallIds()).toEqual(['side-panel-call']);
+ });
+
+ it('should redirect to the available homepage and move the chat to the side panel', () => {
jotaiStore.set(shouldContinueAiChatInSidePanelState.atom, true);
const { result } = renderHook(() => useProcessWorkspaceSetupCompletion(), {
@@ -91,7 +124,7 @@ describe('useProcessWorkspaceSetupCompletion', () => {
);
});
- expect(navigateMock).toHaveBeenCalledWith('/objects/companies');
+ expect(navigateMock).toHaveBeenCalledWith('/objects/people');
expect(closeSidePanelMenuMock).not.toHaveBeenCalled();
expect(jotaiStore.get(shouldContinueAiChatInSidePanelState.atom)).toBe(
true,
@@ -114,6 +147,30 @@ describe('useProcessWorkspaceSetupCompletion', () => {
expect(navigateMock).toHaveBeenCalledTimes(1);
});
+ it('returns to settings and ends setup when no readable object homepage exists', () => {
+ defaultHomePagePath = '/settings/profile';
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ jotaiStore.set(shouldContinueAiChatInSidePanelState.atom, true);
+ const { result } = renderHook(() => useProcessWorkspaceSetupCompletion(), {
+ wrapper: Wrapper,
+ });
+
+ act(() =>
+ result.current.processWorkspaceSetupCompletion(
+ buildCompletionMessage('fallback-call'),
+ ),
+ );
+
+ expect(navigateMock).toHaveBeenCalledWith('/settings/profile');
+ expect(jotaiStore.get(shouldOpenAiChatAfterOnboardingState.atom)).toBe(
+ false,
+ );
+ expect(jotaiStore.get(shouldContinueAiChatInSidePanelState.atom)).toBe(
+ false,
+ );
+ expect(closeSidePanelMenuMock).toHaveBeenCalledTimes(1);
+ });
+
it('should not redirect when the chat already left the setup page', () => {
isWorkspaceSetupChat = false;
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useSelectAiChatThread.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useSelectAiChatThread.test.tsx
new file mode 100644
index 00000000000..37d081ac534
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useSelectAiChatThread.test.tsx
@@ -0,0 +1,60 @@
+import { act, renderHook } from '@testing-library/react';
+import { Provider as JotaiProvider } from 'jotai';
+import { type ReactNode } from 'react';
+
+import { useSelectAiChatThread } from '@/ai/hooks/useSelectAiChatThread';
+import { AGENT_CHAT_NEW_THREAD_DRAFT_KEY } from '@/ai/states/agentChatDraftsByThreadIdState';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
+import {
+ jotaiStore,
+ resetJotaiStore,
+} from '@/ui/utilities/state/jotai/jotaiStore';
+
+jest.mock('@/ai/hooks/useProjectAiChatThreadToUrl', () => ({
+ useProjectAiChatThreadToUrl: () => ({ projectAiChatThreadToUrl: jest.fn() }),
+}));
+
+const Wrapper = ({ children }: { children: ReactNode }) => (
+ <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>
+);
+
+describe('useSelectAiChatThread', () => {
+ beforeEach(() => {
+ resetJotaiStore();
+ });
+
+ it.each([AGENT_CHAT_NEW_THREAD_DRAFT_KEY, 'other-thread'])(
+ 'leaves onboarding when selecting %s',
+ (threadId) => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ jotaiStore.set(currentAiChatThreadState.atom, 'onboarding-thread');
+ const { result } = renderHook(() => useSelectAiChatThread(), {
+ wrapper: Wrapper,
+ });
+
+ act(() => result.current.selectAiChatThread(threadId));
+
+ expect(jotaiStore.get(currentAiChatThreadState.atom)).toBe(threadId);
+ expect(jotaiStore.get(shouldOpenAiChatAfterOnboardingState.atom)).toBe(
+ false,
+ );
+ },
+ );
+ it('preserves onboarding when reselecting the current setup conversation', () => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ jotaiStore.set(currentAiChatThreadState.atom, 'onboarding-thread');
+ const { result } = renderHook(() => useSelectAiChatThread(), {
+ wrapper: Wrapper,
+ });
+
+ act(() => result.current.selectAiChatThread('onboarding-thread'));
+
+ expect(jotaiStore.get(currentAiChatThreadState.atom)).toBe(
+ 'onboarding-thread',
+ );
+ expect(jotaiStore.get(shouldOpenAiChatAfterOnboardingState.atom)).toBe(
+ true,
+ );
+ });
+});
diff --git a/packages/twenty-front/src/modules/ai/hooks/useAgentChatModelId.ts b/packages/twenty-front/src/modules/ai/hooks/useAgentChatModelId.ts
index 7d9ef550c8d..2262bb73224 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useAgentChatModelId.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useAgentChatModelId.ts
@@ -1,6 +1,6 @@
import { isAutoSelectModelId, isDefined } from 'twenty-shared/utils';
-import { useIsWorkspaceSetupChat } from '@/ai/hooks/useIsWorkspaceSetupChat';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { useWorkspaceAiModelAvailability } from '@/ai/hooks/useWorkspaceAiModelAvailability';
import { agentChatUserSelectedModelState } from '@/ai/states/agentChatUserSelectedModelState';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
@@ -12,7 +12,10 @@ export const useAgentChatModelId = () => {
agentChatUserSelectedModelState,
);
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
- const isWorkspaceSetupChat = useIsWorkspaceSetupChat();
+ // The shared sender mounts above the chat surface providers.
+ const shouldOpenAiChatAfterOnboarding = useAtomStateValue(
+ shouldOpenAiChatAfterOnboardingState,
+ );
const isUserModelAvailable =
!isDefined(agentChatUserSelectedModel) ||
@@ -23,7 +26,7 @@ export const useAgentChatModelId = () => {
? agentChatUserSelectedModel
: null;
- const workspaceSetupModelId = isWorkspaceSetupChat
+ const workspaceSetupModelId = shouldOpenAiChatAfterOnboarding
? currentWorkspace?.fastModel
: null;
diff --git a/packages/twenty-front/src/modules/ai/hooks/useDeleteChatThread.ts b/packages/twenty-front/src/modules/ai/hooks/useDeleteChatThread.ts
index 43bbdd06f98..143078fbf01 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useDeleteChatThread.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useDeleteChatThread.ts
@@ -12,6 +12,7 @@ import { agentChatVisibleThreadsSelector } from '@/ai/states/selectors/agentChat
import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
import { sortChatThreadsByLastActivityDesc } from '@/ai/utils/sortChatThreadsByLastActivityDesc';
import { useUpdateMetadataStoreDraft } from '@/metadata-store/hooks/useUpdateMetadataStoreDraft';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { DeleteChatThreadDocument } from '~/generated-metadata/graphql';
@@ -40,6 +41,8 @@ export const useDeleteChatThread = () => {
return;
}
+ store.set(shouldOpenAiChatAfterOnboardingState.atom, false);
+
const remaining = sortChatThreadsByLastActivityDesc(
store
.get(agentChatVisibleThreadsSelector.atom)
diff --git a/packages/twenty-front/src/modules/ai/hooks/useIsWorkspaceSetupChat.ts b/packages/twenty-front/src/modules/ai/hooks/useIsWorkspaceSetupChat.ts
index 073a4c7c122..383ab64b6e5 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useIsWorkspaceSetupChat.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useIsWorkspaceSetupChat.ts
@@ -1,14 +1,14 @@
-import { useLocation } from 'react-router-dom';
-
+import { useContext } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
-import { isAiChatPath } from '~/utils/isAiChatPath';
export const useIsWorkspaceSetupChat = () => {
- const { pathname } = useLocation();
+ const surface = useContext(AiChatSurfaceContext);
const shouldOpenAiChatAfterOnboarding = useAtomStateValue(
shouldOpenAiChatAfterOnboardingState,
);
- return shouldOpenAiChatAfterOnboarding && isAiChatPath(pathname);
+ return shouldOpenAiChatAfterOnboarding && isDefined(surface);
};
diff --git a/packages/twenty-front/src/modules/ai/hooks/useProcessWorkspaceSetupCompletion.ts b/packages/twenty-front/src/modules/ai/hooks/useProcessWorkspaceSetupCompletion.ts
index 96b4b44849b..326f2507597 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useProcessWorkspaceSetupCompletion.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useProcessWorkspaceSetupCompletion.ts
@@ -1,23 +1,26 @@
+import { useContext } from 'react';
+import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
+import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { useIsWorkspaceSetupChat } from '@/ai/hooks/useIsWorkspaceSetupChat';
import { useReturnFromExpandedAiChat } from '@/ai/hooks/useReturnFromExpandedAiChat';
import { processedToolExecutionPartIdsComponentState } from '@/ai/states/processedToolExecutionPartIdsComponentState';
import { extractCompletedWorkspaceSetupToolParts } from '@/ai/utils/extractCompletedWorkspaceSetupToolParts';
-import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
+import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
+import { isSettingsPath } from '~/utils/isSettingsPath';
import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';
import { isNonEmptyArray } from '@sniptt/guards';
import { useStore } from 'jotai';
import { type ExtendedUIMessage } from 'twenty-shared/ai';
-import { AppPath } from 'twenty-shared/types';
-import { getAppPath } from 'twenty-shared/utils';
export const useProcessWorkspaceSetupCompletion = () => {
const isWorkspaceSetupChat = useIsWorkspaceSetupChat();
+ const aiChatSurface = useContext(AiChatSurfaceContext);
+ const { defaultHomePagePath } = useDefaultHomePagePath();
const returnFromExpandedAiChat = useReturnFromExpandedAiChat({
- reopenSidePanel: true,
- destinationPath: getAppPath(AppPath.RecordIndexPage, {
- objectNamePlural: CoreObjectNamePlural.Company,
- }),
+ reopenSidePanel: !isSettingsPath(defaultHomePagePath),
+ destinationPath: defaultHomePagePath,
});
const processedToolExecutionPartIdsCallbackState =
@@ -55,7 +58,11 @@ export const useProcessWorkspaceSetupCompletion = () => {
return;
}
- returnFromExpandedAiChat();
+ if (aiChatSurface === AI_CHAT_SURFACE.PAGE) {
+ returnFromExpandedAiChat();
+ } else {
+ store.set(shouldOpenAiChatAfterOnboardingState.atom, false);
+ }
};
return {
diff --git a/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts b/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts
index e7ba9a5a052..cb24813e2e6 100644
--- a/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts
+++ b/packages/twenty-front/src/modules/ai/hooks/useSelectAiChatThread.ts
@@ -1,11 +1,20 @@
+import { useStore } from 'jotai';
+
import { useProjectAiChatThreadToUrl } from '@/ai/hooks/useProjectAiChatThreadToUrl';
import { useSwitchAgentChatThreadWithDraft } from '@/ai/hooks/useSwitchAgentChatThreadWithDraft';
+import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
export const useSelectAiChatThread = () => {
+ const store = useStore();
const { switchThreadWithDraft } = useSwitchAgentChatThreadWithDraft();
const { projectAiChatThreadToUrl } = useProjectAiChatThreadToUrl();
const selectAiChatThread = (toThreadId: string) => {
+ if (store.get(currentAiChatThreadState.atom) !== toThreadId) {
+ store.set(shouldOpenAiChatAfterOnboardingState.atom, false);
+ }
+
switchThreadWithDraft(toThreadId);
projectAiChatThreadToUrl(toThreadId);
};
diff --git a/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx b/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
index 8a281f06432..1f65b2184f5 100644
--- a/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
+++ b/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
@@ -13,7 +13,6 @@ import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/
import { contextStoreCurrentViewTypeComponentState } from '@/context-store/states/contextStoreCurrentViewTypeComponentState';
import { ContextStoreViewType } from '@/context-store/types/ContextStoreViewType';
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
-import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { useActiveRecordBoardCard } from '@/object-record/record-board/hooks/useActiveRecordBoardCard';
import { useFocusedRecordBoardCard } from '@/object-record/record-board/hooks/useFocusedRecordBoardCard';
import { useResetRecordBoardSelection } from '@/object-record/record-board/hooks/useResetRecordBoardSelection';
@@ -38,7 +37,6 @@ import { AppBasePath, AppPath, SidePanelPages } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { usePageChangeEffectNavigateLocation } from '~/hooks/usePageChangeEffectNavigateLocation';
import { getPageLayoutIdForLocation } from '~/modules/app/utils/getPageLayoutIdForLocation';
-import { isAiChatPath } from '~/utils/isAiChatPath';
import { isMatchingLocation } from '~/utils/isMatchingLocation';
// TODO: break down into smaller functions and / or hooks
@@ -173,13 +171,6 @@ export const PageChangeEffect = () => {
if (consumedReturnToPath) {
clearReturnToPath();
}
-
- if (
- store.get(shouldOpenAiChatAfterOnboardingState.atom) &&
- !isAiChatPath(pageChangeEffectNavigateLocation)
- ) {
- store.set(shouldOpenAiChatAfterOnboardingState.atom, false);
- }
}
}, [
navigate,
diff --git a/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatKickoffEffect.tsx b/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatKickoffEffect.tsx
index 0e236371055..7a5801d7525 100644
--- a/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatKickoffEffect.tsx
+++ b/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatKickoffEffect.tsx
@@ -12,6 +12,7 @@ import { skipMessagesSkeletonUntilLoadedState } from '@/ai/states/skipMessagesSk
import { useUpdateMetadataStoreDraft } from '@/metadata-store/hooks/useUpdateMetadataStoreDraft';
import { type FlatAgentChatThread } from '@/metadata-store/types/FlatAgentChatThread';
import { WORKSPACE_SETUP_CHAT_ENRICHMENT_MAX_WAIT_MS } from '@/onboarding/constants/WorkspaceSetupChatEnrichmentMaxWaitMs';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { companyEnrichmentState } from '@/onboarding/states/companyEnrichmentState';
import { hasRequestedWorkspaceSetupChatState } from '@/onboarding/states/hasRequestedWorkspaceSetupChatState';
import { isCompanyEnrichmentFetchInFlightState } from '@/onboarding/states/isCompanyEnrichmentFetchInFlightState';
@@ -81,6 +82,10 @@ export const WorkspaceSetupChatKickoffEffect = () => {
return;
}
+ if (!store.get(shouldOpenAiChatAfterOnboardingState.atom)) {
+ return;
+ }
+
const workspaceSetupThread: FlatAgentChatThread = {
id: thread.id,
title: thread.title ?? null,
diff --git a/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatSidePanelEffect.tsx b/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatSidePanelEffect.tsx
new file mode 100644
index 00000000000..c410b45e9a2
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/effect-components/WorkspaceSetupChatSidePanelEffect.tsx
@@ -0,0 +1,64 @@
+import { useLayoutEffect } from 'react';
+import { useStore } from 'jotai';
+
+import { hasOpenedWorkspaceSetupChatSidePanelState } from '@/onboarding/states/hasOpenedWorkspaceSetupChatSidePanelState';
+import { shouldContinueAiChatInSidePanelState } from '@/ai/states/shouldContinueAiChatInSidePanelState';
+import { useDefaultHomePagePath } from '@/navigation/hooks/useDefaultHomePagePath';
+import { Navigate, useLocation } from 'react-router-dom';
+import { AppPath } from 'twenty-shared/types';
+import { getAppPath } from 'twenty-shared/utils';
+
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
+import { useOpenAskAiPageInSidePanel } from '@/side-panel/hooks/useOpenAskAiPageInSidePanel';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { isAiChatPath } from '~/utils/isAiChatPath';
+import { isSettingsPath } from '~/utils/isSettingsPath';
+
+export const WorkspaceSetupChatSidePanelEffect = () => {
+ const shouldOpenAiChatAfterOnboarding = useAtomStateValue(
+ shouldOpenAiChatAfterOnboardingState,
+ );
+ const store = useStore();
+ const { pathname } = useLocation();
+ const { defaultHomePagePath } = useDefaultHomePagePath();
+ const { openAskAiPage } = useOpenAskAiPageInSidePanel();
+
+ useLayoutEffect(() => {
+ if (!shouldOpenAiChatAfterOnboarding) {
+ store.set(hasOpenedWorkspaceSetupChatSidePanelState.atom, false);
+ return;
+ }
+
+ if (
+ store.get(hasOpenedWorkspaceSetupChatSidePanelState.atom) ||
+ isAiChatPath(pathname) ||
+ isSettingsPath(pathname) ||
+ store.get(shouldContinueAiChatInSidePanelState.atom)
+ ) {
+ return;
+ }
+
+ store.set(hasOpenedWorkspaceSetupChatSidePanelState.atom, true);
+ openAskAiPage({ resetNavigationStack: true });
+ }, [shouldOpenAiChatAfterOnboarding, store, pathname, openAskAiPage]);
+
+ if (
+ shouldOpenAiChatAfterOnboarding &&
+ !store.get(hasOpenedWorkspaceSetupChatSidePanelState.atom) &&
+ !store.get(shouldContinueAiChatInSidePanelState.atom) &&
+ isSettingsPath(pathname)
+ ) {
+ return (
+ <Navigate
+ to={
+ isSettingsPath(defaultHomePagePath)
+ ? getAppPath(AppPath.AiChat, { threadId: null })
+ : defaultHomePagePath
+ }
+ replace
+ />
+ );
+ }
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/onboarding/effect-components/__tests__/WorkspaceSetupChatKickoffEffect.test.tsx b/packages/twenty-front/src/modules/onboarding/effect-components/__tests__/WorkspaceSetupChatKickoffEffect.test.tsx
index cfec12eb369..85830cd28d7 100644
--- a/packages/twenty-front/src/modules/onboarding/effect-components/__tests__/WorkspaceSetupChatKickoffEffect.test.tsx
+++ b/packages/twenty-front/src/modules/onboarding/effect-components/__tests__/WorkspaceSetupChatKickoffEffect.test.tsx
@@ -14,6 +14,7 @@ import { currentAiChatThreadTitleComponentFamilyState } from '@/ai/states/curren
import { hasInitializedAgentChatThreadsState } from '@/ai/states/hasInitializedAgentChatThreadsState';
import { skipMessagesSkeletonUntilLoadedState } from '@/ai/states/skipMessagesSkeletonUntilLoadedState';
import { WorkspaceSetupChatKickoffEffect } from '@/onboarding/effect-components/WorkspaceSetupChatKickoffEffect';
+import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
import { companyEnrichmentState } from '@/onboarding/states/companyEnrichmentState';
import { isCompanyEnrichmentFetchInFlightState } from '@/onboarding/states/isCompanyEnrichmentFetchInFlightState';
import { personEnrichmentState } from '@/onboarding/states/personEnrichmentState';
@@ -114,12 +115,39 @@ describe('WorkspaceSetupChatKickoffEffect', () => {
resetJotaiStore();
sessionStorage.clear();
localStorage.clear();
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
});
afterEach(() => {
jest.clearAllMocks();
});
+ it('preserves the selected conversation when setup finishes after leaving onboarding', async () => {
+ const mocks = [{ ...buildKickoffMock({ outcome: 'STARTED' }), delay: 50 }];
+ const tree = (showSetup: boolean) => (
+ <MockedProvider mocks={mocks as never}>
+ <JotaiProvider store={jotaiStore}>
+ {showSetup && <WorkspaceSetupChatKickoffEffect />}
+ </JotaiProvider>
+ </MockedProvider>
+ );
+ const { rerender } = render(tree(true));
+
+ act(() => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, false);
+ jotaiStore.set(currentAiChatThreadState.atom, 'new-conversation');
+ });
+ rerender(tree(false));
+ await flushMutation();
+
+ expect(jotaiStore.get(currentAiChatThreadState.atom)).toBe(
+ 'new-conversation',
+ );
+ expect(jotaiStore.get(skipMessagesSkeletonUntilLoadedState.atom)).toBe(
+ false,
+ );
+ });
+
it('should wait for an in-flight company enrichment before starting the chat', async () => {
jotaiStore.set(isCompanyEnrichmentFetchInFlightState.atom, true);
diff --git a/packages/twenty-front/src/modules/onboarding/states/hasOpenedWorkspaceSetupChatSidePanelState.ts b/packages/twenty-front/src/modules/onboarding/states/hasOpenedWorkspaceSetupChatSidePanelState.ts
new file mode 100644
index 00000000000..092381ff78e
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/states/hasOpenedWorkspaceSetupChatSidePanelState.ts
@@ -0,0 +1,7 @@
+import { createAtomState } from '@/ui/utilities/state/jotai/utils/createAtomState';
+
+export const hasOpenedWorkspaceSetupChatSidePanelState =
+ createAtomState<boolean>({
+ key: 'hasOpenedWorkspaceSetupChatSidePanelState',
+ defaultValue: false,
+ });
diff --git a/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelAskAiHandoffEffect.test.tsx b/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelAskAiHandoffEffect.test.tsx
index 19e69a64d49..6e4082c8403 100644
--- a/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelAskAiHandoffEffect.test.tsx
+++ b/packages/twenty-front/src/modules/side-panel/components/__tests__/SidePanelAskAiHandoffEffect.test.tsx
@@ -1,16 +1,22 @@
-import { act, render } from '@testing-library/react';
+import { act, render, screen } from '@testing-library/react';
import { Provider as JotaiProvider } from 'jotai';
import { MemoryRouter, Route, Routes, useNavigate } from 'react-router-dom';
import { AiChatPageContinueInSidePanelEffect } from '@/ai/components/AiChatPageContinueInSidePanelEffect';
import { shouldContinueAiChatInSidePanelState } from '@/ai/states/shouldContinueAiChatInSidePanelState';
import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
+import { WorkspaceSetupChatSidePanelEffect } from '@/onboarding/effect-components/WorkspaceSetupChatSidePanelEffect';
import { SidePanelAskAiHandoffEffect } from '@/side-panel/components/SidePanelAskAiHandoffEffect';
import {
jotaiStore,
resetJotaiStore,
} from '@/ui/utilities/state/jotai/jotaiStore';
+let defaultHomePagePath = '/objects/companies';
+jest.mock('@/navigation/hooks/useDefaultHomePagePath', () => ({
+ useDefaultHomePagePath: () => ({ defaultHomePagePath }),
+}));
+
const openAskAiPageMock = jest.fn();
jest.mock('@/side-panel/hooks/useOpenAskAiPageInSidePanel', () => ({
@@ -27,19 +33,28 @@ const ChatPageRoute = () => {
navigateAwayFromChatPage = (pathname = '/objects/companies') =>
navigate(pathname);
- return <AiChatPageContinueInSidePanelEffect />;
+ return (
+ <>
+ <AiChatPageContinueInSidePanelEffect />
+ <div>Setup conversation</div>
+ </>
+ );
};
const RouterUnderTest = ({ initialPath }: { initialPath: string }) => (
<JotaiProvider store={jotaiStore}>
<MemoryRouter initialEntries={[initialPath]}>
{/* The handoff lives in the persistent layout, outside the routes. */}
+ <WorkspaceSetupChatSidePanelEffect />
<SidePanelAskAiHandoffEffect
onContinueChatFromFullWidth={onContinueChatFromFullWidthMock}
/>
<Routes>
<Route path="/chat/:threadId?" element={<ChatPageRoute />} />
- <Route path="/objects/companies" element={<div />} />
+ <Route
+ path="/objects/companies"
+ element={<div>Companies homepage</div>}
+ />
<Route path="/settings/*" element={<div />} />
</Routes>
</MemoryRouter>
@@ -52,6 +67,38 @@ describe('SidePanelAskAiHandoffEffect', () => {
sessionStorage.clear();
resetJotaiStore();
navigateAwayFromChatPage = undefined;
+ defaultHomePagePath = '/objects/companies';
+ });
+
+ it('opens setup on the homepage after returning to settings', () => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ render(<RouterUnderTest initialPath="/settings/profile" />);
+ expect(screen.getByText('Companies homepage')).toBeInTheDocument();
+ expect(openAskAiPageMock).toHaveBeenCalledTimes(1);
+ });
+
+ it('uses the chat page when no readable object homepage exists', () => {
+ defaultHomePagePath = '/settings/profile';
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ render(<RouterUnderTest initialPath="/settings/profile" />);
+ expect(screen.getByText('Setup conversation')).toBeInTheDocument();
+ expect(openAskAiPageMock).not.toHaveBeenCalled();
+ expect(jotaiStore.get(shouldOpenAiChatAfterOnboardingState.atom)).toBe(
+ true,
+ );
+ });
+
+ it('preserves dismissal across remounts but opens again after an application reload', () => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ const first = render(<RouterUnderTest initialPath="/objects/companies" />);
+ first.unmount();
+ const second = render(<RouterUnderTest initialPath="/objects/companies" />);
+ expect(openAskAiPageMock).toHaveBeenCalledTimes(1);
+ second.unmount();
+ resetJotaiStore();
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
+ render(<RouterUnderTest initialPath="/objects/companies" />);
+ expect(openAskAiPageMock).toHaveBeenCalledTimes(2);
});
it('should continue the chat in the side panel on the navigation leaving the chat page', () => {
@@ -68,6 +115,7 @@ describe('SidePanelAskAiHandoffEffect', () => {
navigateAwayFromChatPage?.();
});
+ expect(openAskAiPageMock).toHaveBeenCalledTimes(1);
expect(openAskAiPageMock).toHaveBeenCalledWith({
resetNavigationStack: true,
});
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx
index 9260d2f5659..0a34704dc13 100644
--- a/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/MainAppLayoutWithSidePanel.tsx
@@ -1,3 +1,4 @@
+import { WorkspaceSetupChatSidePanelEffect } from '@/onboarding/effect-components/WorkspaceSetupChatSidePanelEffect';
import { CommandMenuForMobile } from '@/command-menu/components/CommandMenuForMobile';
import { useCommandMenuHotKeys } from '@/command-menu/hooks/useCommandMenuHotKeys';
import { RouteContextStoreProvider } from '@/context-store/components/RouteContextStoreProvider';
@@ -51,6 +52,7 @@ export const MainAppLayoutWithSidePanel = () => {
<StyledRow>
<RouteContextStoreProvider />
<SidePanelPathUrlSyncEffect />
+ <WorkspaceSetupChatSidePanelEffect />
<StyledContent>
<Outlet />
</StyledContent>
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/__tests__/MainAppLayoutWithSidePanel.test.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/__tests__/MainAppLayoutWithSidePanel.test.tsx
index 0b224c7cf79..8a06bf3ef12 100644
--- a/packages/twenty-front/src/modules/ui/layout/page/components/__tests__/MainAppLayoutWithSidePanel.test.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/__tests__/MainAppLayoutWithSidePanel.test.tsx
@@ -1,3 +1,10 @@
+jest.mock(
+ '@/onboarding/effect-components/WorkspaceSetupChatSidePanelEffect',
+ () => ({
+ WorkspaceSetupChatSidePanelEffect: () => null,
+ }),
+);
+
import { act, render, screen, waitFor } from '@testing-library/react';
import { useEffect } from 'react';
import {
diff --git a/packages/twenty-front/src/pages/ai-chat/AiChatPage.tsx b/packages/twenty-front/src/pages/ai-chat/AiChatPage.tsx
index 6fcc8f7d263..13e317058ef 100644
--- a/packages/twenty-front/src/pages/ai-chat/AiChatPage.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/AiChatPage.tsx
@@ -7,12 +7,7 @@ import { AiChatPageHeader } from '@/ai/components/AiChatPageHeader';
import { AiChatPageThreadUrlSyncEffect } from '@/ai/components/AiChatPageThreadUrlSyncEffect';
import { AiChatTab } from '@/ai/components/AiChatTab';
import { AI_CHAT_SURFACE } from '@/ai/constants/AiChatSurface';
-import { AiChatMessageListPreambleContext } from '@/ai/contexts/AiChatMessageListPreambleContext';
import { AiChatSurfaceContext } from '@/ai/contexts/AiChatSurfaceContext';
-import { WorkspaceSetupChatPreamble } from '@/onboarding/components/WorkspaceSetupChatPreamble';
-import { WorkspaceSetupChatKickoffEffect } from '@/onboarding/effect-components/WorkspaceSetupChatKickoffEffect';
-import { shouldOpenAiChatAfterOnboardingState } from '@/onboarding/states/shouldOpenAiChatAfterOnboardingState';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
const PANEL_CORNER_RADIUS_DERIVED_FROM_THEME_SCALE = `calc(${themeCssVariables.border.radius.md} + ${themeCssVariables.spacing[1]})`;
@@ -39,29 +34,16 @@ const StyledChatContainer = styled.div`
`;
export const AiChatPage = () => {
- const shouldOpenAiChatAfterOnboarding = useAtomStateValue(
- shouldOpenAiChatAfterOnboardingState,
- );
-
return (
<StyledPanel>
<AiChatPageThreadUrlSyncEffect />
<AiChatPageCloseAskAiPanelEffect />
<AiChatPageContinueInSidePanelEffect />
- {shouldOpenAiChatAfterOnboarding && <WorkspaceSetupChatKickoffEffect />}
- <AiChatPageHeader isOnboarding={shouldOpenAiChatAfterOnboarding} />
+ <AiChatPageHeader />
<StyledChatContainer>
- <AiChatMessageListPreambleContext.Provider
- value={
- shouldOpenAiChatAfterOnboarding ? (
- <WorkspaceSetupChatPreamble />
- ) : null
- }
- >
- <AiChatSurfaceContext.Provider value={AI_CHAT_SURFACE.PAGE}>
- <AiChatTab />
- </AiChatSurfaceContext.Provider>
- </AiChatMessageListPreambleContext.Provider>
+ <AiChatSurfaceContext.Provider value={AI_CHAT_SURFACE.PAGE}>
+ <AiChatTab />
+ </AiChatSurfaceContext.Provider>
</StyledChatContainer>
</StyledPanel>
);
diff --git a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatPage.test.tsx b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatPage.test.tsx
index 1b86085130e..27d4def05c0 100644
--- a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatPage.test.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatPage.test.tsx
@@ -19,25 +19,18 @@ i18n.activate(SOURCE_LOCALE);
jest.mock('@/ai/components/AiChatTab', () => {
const { useContext } = jest.requireActual('react');
- const { AiChatMessageListPreambleContext } = jest.requireActual(
- '@/ai/contexts/AiChatMessageListPreambleContext',
+ const { AiChatSurfaceContext } = jest.requireActual(
+ '@/ai/contexts/AiChatSurfaceContext',
);
return {
AiChatTab: () => (
- <div data-testid="ai-chat-tab">
- {useContext(AiChatMessageListPreambleContext)}
- </div>
+ <div data-testid="ai-chat-tab">{useContext(AiChatSurfaceContext)}</div>
),
};
});
-const headerMock = jest.fn();
-
jest.mock('@/ai/components/AiChatPageHeader', () => ({
- AiChatPageHeader: ({ isOnboarding }: { isOnboarding: boolean }) => {
- headerMock(isOnboarding);
- return null;
- },
+ AiChatPageHeader: () => <div>Chat header</div>,
}));
jest.mock('@/ai/components/AiChatPageThreadUrlSyncEffect', () => ({
@@ -48,19 +41,6 @@ jest.mock('@/ai/components/AiChatPageCloseAskAiPanelEffect', () => ({
AiChatPageCloseAskAiPanelEffect: () => null,
}));
-jest.mock('@/onboarding/components/WorkspaceSetupChatPreamble', () => ({
- WorkspaceSetupChatPreamble: () => <div data-testid="preamble" />,
-}));
-
-jest.mock(
- '@/onboarding/effect-components/WorkspaceSetupChatKickoffEffect',
- () => ({
- WorkspaceSetupChatKickoffEffect: () => (
- <div data-testid="chat-kickoff-effect" />
- ),
- }),
-);
-
const Wrapper = ({ children }: { children: ReactNode }) => (
<JotaiProvider store={jotaiStore}>
<I18nProvider i18n={i18n}>{children}</I18nProvider>
@@ -74,27 +54,18 @@ describe('AiChatPage', () => {
resetJotaiStore();
});
- it('should dress the chat for onboarding when the post-onboarding hint is set', () => {
- jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, true);
-
- const { getByTestId } = render(<AiChatPage />, { wrapper: Wrapper });
-
- expect(getByTestId('ai-chat-tab')).toBeInTheDocument();
- expect(getByTestId('preamble')).toBeInTheDocument();
- expect(getByTestId('chat-kickoff-effect')).toBeInTheDocument();
- expect(headerMock).toHaveBeenCalledWith(true);
- });
-
- it('should render a plain chat when the post-onboarding hint is not set', () => {
- const { getByTestId, queryByTestId } = render(<AiChatPage />, {
- wrapper: Wrapper,
- });
-
- expect(getByTestId('ai-chat-tab')).toBeInTheDocument();
- expect(queryByTestId('preamble')).not.toBeInTheDocument();
- expect(queryByTestId('chat-kickoff-effect')).not.toBeInTheDocument();
- expect(headerMock).toHaveBeenCalledWith(false);
- });
+ it.each([true, false])(
+ 'renders the shared header and page chat with onboarding set to %s',
+ (isOnboarding) => {
+ jotaiStore.set(shouldOpenAiChatAfterOnboardingState.atom, isOnboarding);
+ const { getByText, getByTestId } = render(<AiChatPage />, {
+ wrapper: Wrapper,
+ });
+
+ expect(getByText('Chat header')).toBeInTheDocument();
+ expect(getByTestId('ai-chat-tab')).toHaveTextContent('page');
+ },
+ );
it('should mark the chat for side panel continuation while mounted', () => {
const { unmount } = render(<AiChatPage />, { wrapper: Wrapper });