Skip to content

The open alternative to Salesforce, designed for AI.

Fix blank pages and add error recovery in onboarding (#23069)

Raphaël Bosi0c964aee10b0
diff --git a/packages/twenty-front/src/modules/app/hooks/useCreateWorkspaceAppRouter.tsx b/packages/twenty-front/src/modules/app/hooks/useCreateWorkspaceAppRouter.tsx
index 32eb305abdb..977f105b86e 100644
--- a/packages/twenty-front/src/modules/app/hooks/useCreateWorkspaceAppRouter.tsx
+++ b/packages/twenty-front/src/modules/app/hooks/useCreateWorkspaceAppRouter.tsx
@@ -141,7 +141,10 @@ const createWorkspaceAppRouter = (
<Route element={<MinimalMetadataGate />}>
<Route element={<DefaultLayout />}>
<Route element={<MainAppLayoutWithSidePanel />}>
- <Route path={indexAppPath.getIndexAppPath()} element={<></>} />
+ <Route
+ path={indexAppPath.getIndexAppPath()}
+ element={<RecordIndexSkeletonLoader />}
+ />
<Route
path={AppPath.RecordIndexPage}
element={
@@ -208,7 +211,7 @@ const createWorkspaceAppRouter = (
<Route
path={AppPath.PlanRequiredSuccess}
element={
- <LazyRoute fallback={null}>
+ <LazyRoute fallback={<OnboardingPageLoader />}>
<PaymentSuccess />
</LazyRoute>
}
@@ -216,7 +219,7 @@ const createWorkspaceAppRouter = (
<Route
path={AppPath.BookCall}
element={
- <LazyRoute fallback={null}>
+ <LazyRoute fallback={<OnboardingPageLoader />}>
<BookCall />
</LazyRoute>
}
diff --git a/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx b/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx
index 91c52396f12..f25d7668256 100644
--- a/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx
+++ b/packages/twenty-front/src/modules/onboarding/components/OnboardingStepLayout.tsx
@@ -1,15 +1,14 @@
import { OnboardingLayout } from '@/onboarding/components/OnboardingLayout';
import { OnboardingTransitionOutlet } from '@/onboarding/components/OnboardingTransitionOutlet';
+import { PrefetchPlanRequiredStepEffect } from '@/onboarding/effect-components/PrefetchPlanRequiredStepEffect';
import { useOnboardingFreeCreditsTotal } from '@/onboarding/hooks/useOnboardingFreeCreditsTotal';
-import { usePreloadStripeForPlanRequiredStep } from '@/onboarding/hooks/usePreloadStripeForPlanRequiredStep';
export const OnboardingStepLayout = () => {
const freeCredits = useOnboardingFreeCreditsTotal();
- usePreloadStripeForPlanRequiredStep();
-
return (
<OnboardingLayout freeCredits={freeCredits}>
+ <PrefetchPlanRequiredStepEffect />
<OnboardingTransitionOutlet />
</OnboardingLayout>
);
diff --git a/packages/twenty-front/src/modules/onboarding/components/upgrade-free-trial/ChooseYourPlanErrorState.tsx b/packages/twenty-front/src/modules/onboarding/components/upgrade-free-trial/ChooseYourPlanErrorState.tsx
new file mode 100644
index 00000000000..02a892bf89b
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/components/upgrade-free-trial/ChooseYourPlanErrorState.tsx
@@ -0,0 +1,54 @@
+import { useAuth } from '@/auth/hooks/useAuth';
+import { OnboardingStepAnimatedItem } from '@/onboarding/components/OnboardingStepAnimatedItem';
+import { StyledOnboardingContentBlock } from '@/onboarding/components/StyledOnboardingContentBlock';
+import { StyledOnboardingStepHeading } from '@/onboarding/components/StyledOnboardingStepHeading';
+import { StyledOnboardingStepPage } from '@/onboarding/components/StyledOnboardingStepPage';
+import { StyledOnboardingStepSubtitle } from '@/onboarding/components/StyledOnboardingStepSubtitle';
+import { StyledOnboardingStepTitle } from '@/onboarding/components/StyledOnboardingStepTitle';
+import { styled } from '@linaria/react';
+import { Trans, useLingui } from '@lingui/react/macro';
+import { MainButton } from 'twenty-ui/input';
+import { ClickToActionLink } from 'twenty-ui/navigation';
+import { themeCssVariables } from 'twenty-ui/theme-constants';
+
+const StyledFooter = styled(StyledOnboardingContentBlock)`
+ align-items: center;
+ gap: ${themeCssVariables.spacing[4]};
+`;
+
+type ChooseYourPlanErrorStateProps = {
+ onRetry: () => void;
+};
+
+export const ChooseYourPlanErrorState = ({
+ onRetry,
+}: ChooseYourPlanErrorStateProps) => {
+ const { t } = useLingui();
+ const { signOut } = useAuth();
+
+ return (
+ <StyledOnboardingStepPage>
+ <StyledOnboardingStepHeading>
+ <OnboardingStepAnimatedItem index={0}>
+ <StyledOnboardingStepTitle>
+ {t`We couldn't load the plans`}
+ </StyledOnboardingStepTitle>
+ </OnboardingStepAnimatedItem>
+ <OnboardingStepAnimatedItem index={1}>
+ <StyledOnboardingStepSubtitle>
+ {t`Something went wrong while contacting our billing service. Please try again.`}
+ </StyledOnboardingStepSubtitle>
+ </OnboardingStepAnimatedItem>
+ </StyledOnboardingStepHeading>
+
+ <OnboardingStepAnimatedItem index={2}>
+ <StyledFooter>
+ <MainButton title={t`Try again`} onClick={onRetry} fullWidth />
+ <ClickToActionLink onClick={signOut}>
+ <Trans>Log out</Trans>
+ </ClickToActionLink>
+ </StyledFooter>
+ </OnboardingStepAnimatedItem>
+ </StyledOnboardingStepPage>
+ );
+};
diff --git a/packages/twenty-front/src/modules/onboarding/effect-components/PrefetchPlanRequiredStepEffect.tsx b/packages/twenty-front/src/modules/onboarding/effect-components/PrefetchPlanRequiredStepEffect.tsx
new file mode 100644
index 00000000000..89a928a6876
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/effect-components/PrefetchPlanRequiredStepEffect.tsx
@@ -0,0 +1,12 @@
+import { useIsPlanRequired } from '@/onboarding/hooks/useIsPlanRequired';
+import { usePreloadStripeForPlanRequiredStep } from '@/onboarding/hooks/usePreloadStripeForPlanRequiredStep';
+import { usePlans } from '@/settings/billing/hooks/usePlans';
+
+export const PrefetchPlanRequiredStepEffect = () => {
+ const isPlanRequired = useIsPlanRequired();
+
+ usePlans({ skip: !isPlanRequired });
+ usePreloadStripeForPlanRequiredStep();
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useIsPlanRequired.test.ts b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useIsPlanRequired.test.ts
new file mode 100644
index 00000000000..8c424da1603
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useIsPlanRequired.test.ts
@@ -0,0 +1,79 @@
+import { act, renderHook } from '@testing-library/react';
+import { Provider as JotaiProvider } from 'jotai';
+import { createElement } from 'react';
+
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
+import { billingState } from '@/client-config/states/billingState';
+import { useIsPlanRequired } from '@/onboarding/hooks/useIsPlanRequired';
+import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+import {
+ jotaiStore,
+ resetJotaiStore,
+} from '@/ui/utilities/state/jotai/jotaiStore';
+
+import { mockCurrentWorkspace } from '~/testing/mock-data/users';
+
+const Wrapper = ({ children }: { children: React.ReactNode }) =>
+ createElement(JotaiProvider, { store: jotaiStore }, children);
+
+type RenderHooksOptions = {
+ isBillingEnabled?: boolean;
+ withSubscription?: boolean;
+};
+
+const renderHooks = ({
+ isBillingEnabled = true,
+ withSubscription = false,
+}: RenderHooksOptions = {}) => {
+ const { result } = renderHook(
+ () => {
+ const setCurrentWorkspace = useSetAtomState(currentWorkspaceState);
+ const setBilling = useSetAtomState(billingState);
+ const isPlanRequired = useIsPlanRequired();
+ return { setCurrentWorkspace, setBilling, isPlanRequired };
+ },
+ {
+ wrapper: Wrapper,
+ },
+ );
+
+ act(() => {
+ result.current.setCurrentWorkspace({
+ ...mockCurrentWorkspace,
+ billingSubscriptions: withSubscription
+ ? mockCurrentWorkspace.billingSubscriptions
+ : [],
+ });
+ result.current.setBilling({
+ __typename: 'Billing',
+ isBillingEnabled,
+ trialPeriods: [],
+ });
+ });
+
+ return result;
+};
+
+describe('useIsPlanRequired', () => {
+ beforeEach(() => {
+ resetJotaiStore();
+ });
+
+ it('should be true when billing is enabled and the workspace has no subscription', () => {
+ const result = renderHooks();
+
+ expect(result.current.isPlanRequired).toBe(true);
+ });
+
+ it('should be false when billing is disabled', () => {
+ const result = renderHooks({ isBillingEnabled: false });
+
+ expect(result.current.isPlanRequired).toBe(false);
+ });
+
+ it('should be false when the workspace already has a subscription', () => {
+ const result = renderHooks({ withSubscription: true });
+
+ expect(result.current.isPlanRequired).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/useIsPlanRequired.ts b/packages/twenty-front/src/modules/onboarding/hooks/useIsPlanRequired.ts
new file mode 100644
index 00000000000..ba1afdb522e
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/hooks/useIsPlanRequired.ts
@@ -0,0 +1,14 @@
+import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
+import { billingState } from '@/client-config/states/billingState';
+import { getIsPlanRequired } from '@/onboarding/utils/getIsPlanRequired';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+
+export const useIsPlanRequired = () => {
+ const billing = useAtomStateValue(billingState);
+ const currentWorkspace = useAtomStateValue(currentWorkspaceState);
+
+ return getIsPlanRequired({
+ isBillingEnabled: billing?.isBillingEnabled ?? false,
+ currentWorkspace,
+ });
+};
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/usePreloadStripeForPlanRequiredStep.ts b/packages/twenty-front/src/modules/onboarding/hooks/usePreloadStripeForPlanRequiredStep.ts
index a73dec27ffd..5e30f6ba22d 100644
--- a/packages/twenty-front/src/modules/onboarding/hooks/usePreloadStripeForPlanRequiredStep.ts
+++ b/packages/twenty-front/src/modules/onboarding/hooks/usePreloadStripeForPlanRequiredStep.ts
@@ -1,20 +1,14 @@
import { isNonEmptyString } from '@sniptt/guards';
import { useEffect } from 'react';
-import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { billingState } from '@/client-config/states/billingState';
-import { getIsPlanRequired } from '@/onboarding/utils/getIsPlanRequired';
+import { useIsPlanRequired } from '@/onboarding/hooks/useIsPlanRequired';
import { getStripePromise } from '@/settings/billing/utils/getStripePromise';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
export const usePreloadStripeForPlanRequiredStep = () => {
const billing = useAtomStateValue(billingState);
- const currentWorkspace = useAtomStateValue(currentWorkspaceState);
-
- const isPlanRequired = getIsPlanRequired({
- isBillingEnabled: billing?.isBillingEnabled ?? false,
- currentWorkspace,
- });
+ const isPlanRequired = useIsPlanRequired();
const publishableKey = billing?.stripePublishableKey;
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPageLayout.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPageLayout.tsx
index 462acde0349..bbb2a40b54e 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPageLayout.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPageLayout.tsx
@@ -8,6 +8,7 @@ import { useSnackBarOnQueryError } from '@/apollo/hooks/useSnackBarOnQueryError'
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { billingState } from '@/client-config/states/billingState';
import { SettingsBillingContentSkeleton } from '@/settings/billing/components/SettingsBillingContentSkeleton';
+import { SettingsBillingPlansErrorState } from '@/settings/billing/components/SettingsBillingPlansErrorState';
import { SettingsBillingTabBar } from '@/settings/billing/components/SettingsBillingTabBar';
import { usePlans } from '@/settings/billing/hooks/usePlans';
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
@@ -29,6 +30,7 @@ export const SettingsBillingPageLayout = ({
error: plansError,
isPlansLoaded,
loading: arePlansLoading,
+ refetch: refetchPlans,
} = usePlans({ skip: !isBillingEnabled });
useSnackBarOnQueryError(plansError, t`Failed to load billing plans`);
@@ -56,7 +58,7 @@ export const SettingsBillingPageLayout = ({
) : isPlansLoaded ? (
children
) : (
- <></>
+ <SettingsBillingPlansErrorState onRetry={() => void refetchPlans()} />
)}
</SettingsPageLayout>
);
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansErrorState.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansErrorState.tsx
new file mode 100644
index 00000000000..b86b87b9728
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingPlansErrorState.tsx
@@ -0,0 +1,40 @@
+import { useLingui } from '@lingui/react/macro';
+import {
+ AnimatedPlaceholder,
+ AnimatedPlaceholderErrorContainer,
+ AnimatedPlaceholderErrorSubTitle,
+ AnimatedPlaceholderErrorTextContainer,
+ AnimatedPlaceholderErrorTitle,
+} from 'twenty-ui/feedback';
+import { IconRefresh } from 'twenty-ui/icon';
+import { Button } from 'twenty-ui/input';
+
+type SettingsBillingPlansErrorStateProps = {
+ onRetry: () => void;
+};
+
+export const SettingsBillingPlansErrorState = ({
+ onRetry,
+}: SettingsBillingPlansErrorStateProps) => {
+ const { t } = useLingui();
+
+ return (
+ <AnimatedPlaceholderErrorContainer>
+ <AnimatedPlaceholder type="errorIndex" />
+ <AnimatedPlaceholderErrorTextContainer>
+ <AnimatedPlaceholderErrorTitle>
+ {t`We couldn't load the plans`}
+ </AnimatedPlaceholderErrorTitle>
+ <AnimatedPlaceholderErrorSubTitle>
+ {t`Something went wrong while contacting our billing service.`}
+ </AnimatedPlaceholderErrorSubTitle>
+ </AnimatedPlaceholderErrorTextContainer>
+ <Button
+ Icon={IconRefresh}
+ title={t`Try again`}
+ variant="secondary"
+ onClick={onRetry}
+ />
+ </AnimatedPlaceholderErrorContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/usePlans.test.ts b/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/usePlans.test.ts
deleted file mode 100644
index ce90e0afd00..00000000000
--- a/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/usePlans.test.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { usePlans } from '@/settings/billing/hooks/usePlans';
-
-describe('usePlans', () => {
- it('should be a function', () => {
- expect(typeof usePlans).toBe('function');
- });
-});
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/usePlans.test.tsx b/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/usePlans.test.tsx
new file mode 100644
index 00000000000..930a61577a4
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/__tests__/usePlans.test.tsx
@@ -0,0 +1,96 @@
+import { MockedProvider } from '@apollo/client/testing/react';
+import { act, renderHook, waitFor } from '@testing-library/react';
+import { GraphQLError } from 'graphql';
+import { type ReactNode } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import { usePlans } from '@/settings/billing/hooks/usePlans';
+import { ListPlansDocument } from '~/generated-metadata/graphql';
+
+const listPlansSuccessMock = {
+ request: { query: ListPlansDocument },
+ result: { data: { listPlans: [] } },
+};
+
+const listPlansSlowSuccessMock = {
+ ...listPlansSuccessMock,
+ delay: 50,
+};
+
+const listPlansErrorMock = {
+ request: { query: ListPlansDocument },
+ result: { errors: [new GraphQLError('Internal server error')] },
+};
+
+const createWrapper =
+ (mocks: readonly unknown[]) =>
+ ({ children }: { children: ReactNode }) => (
+ <MockedProvider mocks={mocks as never}>{children}</MockedProvider>
+ );
+
+describe('usePlans', () => {
+ it('should expose the plans once the query resolves', async () => {
+ const { result } = renderHook(() => usePlans(), {
+ wrapper: createWrapper([listPlansSuccessMock]),
+ });
+
+ await waitFor(() => expect(result.current.isPlansLoaded).toBe(true));
+
+ expect(result.current.error).toBeUndefined();
+ });
+
+ it('should surface the error and leave the plans unloaded when the query fails', async () => {
+ const { result } = renderHook(() => usePlans(), {
+ wrapper: createWrapper([listPlansErrorMock]),
+ });
+
+ await waitFor(() => expect(result.current.error).toBeDefined());
+
+ expect(result.current.isPlansLoaded).toBe(false);
+ });
+
+ it('should report loading and clear the error while a refetch is in flight', async () => {
+ const renders: { loading: boolean; hasError: boolean }[] = [];
+
+ const { result } = renderHook(
+ () => {
+ const plans = usePlans();
+ renders.push({
+ loading: plans.loading,
+ hasError: isDefined(plans.error),
+ });
+ return plans;
+ },
+ {
+ wrapper: createWrapper([listPlansErrorMock, listPlansSlowSuccessMock]),
+ },
+ );
+
+ await waitFor(() => expect(result.current.error).toBeDefined());
+
+ renders.length = 0;
+
+ let refetching: Promise<unknown> | undefined;
+ act(() => {
+ refetching = result.current.refetch();
+ });
+
+ await act(async () => {
+ await refetching;
+ });
+
+ expect(renders).toContainEqual({ loading: true, hasError: false });
+
+ await waitFor(() => expect(result.current.isPlansLoaded).toBe(true));
+ expect(result.current.loading).toBe(false);
+ });
+
+ it('should not run the query when skipped', () => {
+ const { result } = renderHook(() => usePlans({ skip: true }), {
+ wrapper: createWrapper([]),
+ });
+
+ expect(result.current.isPlansLoaded).toBe(false);
+ expect(result.current.loading).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/billing/hooks/usePlans.ts b/packages/twenty-front/src/modules/settings/billing/hooks/usePlans.ts
index 5963bd3e118..538ab242d17 100644
--- a/packages/twenty-front/src/modules/settings/billing/hooks/usePlans.ts
+++ b/packages/twenty-front/src/modules/settings/billing/hooks/usePlans.ts
@@ -7,7 +7,7 @@ type UsePlansOptions = {
};
export const usePlans = (options?: UsePlansOptions) => {
- const { data, loading, error } = useQuery(ListPlansDocument, {
+ const { data, loading, error, refetch } = useQuery(ListPlansDocument, {
skip: options?.skip,
});
@@ -18,5 +18,5 @@ export const usePlans = (options?: UsePlansOptions) => {
return data.listPlans;
};
- return { loading, error, isPlansLoaded, listPlans };
+ return { loading, error, isPlansLoaded, listPlans, refetch };
};
diff --git a/packages/twenty-front/src/modules/ui/layout/page/components/BlankLayout.tsx b/packages/twenty-front/src/modules/ui/layout/page/components/BlankLayout.tsx
index 13af9650a37..0144424249c 100644
--- a/packages/twenty-front/src/modules/ui/layout/page/components/BlankLayout.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/page/components/BlankLayout.tsx
@@ -2,6 +2,9 @@ import { styled } from '@linaria/react';
import { Outlet } from 'react-router-dom';
import { themeCssVariables } from 'twenty-ui/theme-constants';
+import { AppErrorBoundary } from '@/error-handler/components/AppErrorBoundary';
+import { AppFullScreenErrorFallback } from '@/error-handler/components/AppFullScreenErrorFallback';
+
const StyledLayout = styled.div`
background: ${themeCssVariables.background.secondary};
display: flex;
@@ -15,7 +18,9 @@ const StyledLayout = styled.div`
export const BlankLayout = () => {
return (
<StyledLayout>
- <Outlet />
+ <AppErrorBoundary FallbackComponent={AppFullScreenErrorFallback}>
+ <Outlet />
+ </AppErrorBoundary>
</StyledLayout>
);
};
diff --git a/packages/twenty-front/src/pages/onboarding/ChooseYourPlan.tsx b/packages/twenty-front/src/pages/onboarding/ChooseYourPlan.tsx
index b7f699ee5e5..b8d12a5267a 100644
--- a/packages/twenty-front/src/pages/onboarding/ChooseYourPlan.tsx
+++ b/packages/twenty-front/src/pages/onboarding/ChooseYourPlan.tsx
@@ -1,19 +1,29 @@
import { billingState } from '@/client-config/states/billingState';
import { onboardingConfigState } from '@/client-config/states/onboardingConfigState';
+import { OnboardingStepPageLoader } from '@/onboarding/components/OnboardingStepPageLoader';
+import { ChooseYourPlanErrorState } from '@/onboarding/components/upgrade-free-trial/ChooseYourPlanErrorState';
import { usePlans } from '@/settings/billing/hooks/usePlans';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { isDefined } from 'twenty-shared/utils';
import { UpgradeFreeTrial } from '~/pages/onboarding/UpgradeFreeTrial';
export const ChooseYourPlan = () => {
- const { isPlansLoaded } = usePlans();
+ const { isPlansLoaded, error, refetch } = usePlans();
const billing = useAtomStateValue(billingState);
const onboardingConfig = useAtomStateValue(onboardingConfigState);
- return isDefined(billing) && isPlansLoaded ? (
- <UpgradeFreeTrial
- billing={billing}
- creditsReward={onboardingConfig?.upgradeCreditsReward}
- />
- ) : null;
+ if (isDefined(billing) && isPlansLoaded) {
+ return (
+ <UpgradeFreeTrial
+ billing={billing}
+ creditsReward={onboardingConfig?.upgradeCreditsReward}
+ />
+ );
+ }
+
+ if (isDefined(error)) {
+ return <ChooseYourPlanErrorState onRetry={() => void refetch()} />;
+ }
+
+ return <OnboardingStepPageLoader />;
};
diff --git a/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx b/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx
index 3910d1ca648..cf898dcb1cc 100644
--- a/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx
+++ b/packages/twenty-front/src/pages/onboarding/__stories__/ChooseYourPlan.stories.tsx
@@ -3,6 +3,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
import { HttpResponse, graphql } from 'msw';
import { within } from 'storybook/test';
+import { LIST_PLANS } from '@/settings/billing/graphql/queries/listPlans';
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
import { AppPath } from 'twenty-shared/types';
import { OnboardingStatus } from '~/generated-metadata/graphql';
@@ -12,6 +13,7 @@ import {
type PageDecoratorArgs,
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
+import { mockedApolloClient } from '~/testing/mockedApolloClient';
import { mockedOnboardingUserData } from '~/testing/mock-data/users';
const meta: Meta<PageDecoratorArgs> = {
@@ -19,6 +21,9 @@ const meta: Meta<PageDecoratorArgs> = {
component: ChooseYourPlan,
decorators: [PageDecorator],
args: { routePath: AppPath.PlanRequired },
+ beforeEach: async () => {
+ await mockedApolloClient.clearStore();
+ },
parameters: {
msw: {
handlers: [
@@ -48,3 +53,26 @@ export const Default: Story = {
});
},
};
+
+export const PlansQueryError: Story = {
+ parameters: {
+ msw: {
+ handlers: [
+ graphql.query(getOperationName(LIST_PLANS) ?? '', () => {
+ return HttpResponse.json({
+ errors: [{ message: 'Internal server error' }],
+ });
+ }),
+ ...(meta.parameters?.msw.handlers ?? []),
+ ],
+ },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement.ownerDocument.body);
+
+ await canvas.findByText("We couldn't load the plans", undefined, {
+ timeout: 3000,
+ });
+ await canvas.findByText('Try again');
+ },
+};