Skip to content

The open alternative to Salesforce, designed for AI.

Show the onboarding welcome animation on sign-up only (#23057)

Raphaël Bosidd57842187df
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 bf1b7b0e45a..6e277d833a4 100644
--- a/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
+++ b/packages/twenty-front/src/modules/app/effect-components/PageChangeEffect.tsx
@@ -1,7 +1,5 @@
import { useExecuteTasksOnAnyLocationChange } from '@/app/hooks/useExecuteTasksOnAnyLocationChange';
import { isAppEffectRedirectEnabledState } from '@/app/states/isAppEffectRedirectEnabledState';
-import { ONBOARDING_PATHS } from '@/auth/constants/OnboardingPaths';
-import { ONGOING_USER_CREATION_PATHS } from '@/auth/constants/OngoingUserCreationPaths';
import { useReturnToPath } from '@/auth/hooks/useReturnToPath';
import { useIsOnAuthOrOnboardingPage } from '@/auth/hooks/useIsOnAuthOrOnboardingPage';
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
@@ -21,9 +19,6 @@ import { useActiveRecordTableRow } from '@/object-record/record-table/hooks/useA
import { useFocusedRecordTableRow } from '@/object-record/record-table/hooks/useFocusedRecordTableRow';
import { useOpenNewRecordTitleCell } from '@/object-record/record-title-cell/hooks/useOpenNewRecordTitleCell';
import { getRecordIndexIdFromObjectNamePluralAndViewId } from '@/object-record/utils/getRecordIndexIdFromObjectNamePluralAndViewId';
-import { useOnboardingStatus } from '@/onboarding/hooks/useOnboardingStatus';
-import { isWelcomeAnimationVisibleState } from '@/onboarding/states/isWelcomeAnimationVisibleState';
-import { shouldShowWelcomeAnimationOnNavigate } from '@/onboarding/utils/shouldShowWelcomeAnimationOnNavigate';
import { PageFocusId } from '@/types/PageFocusId';
import { useResetFocusStackToFocusItem } from '@/ui/utilities/focus/hooks/useResetFocusStackToFocusItem';
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
@@ -44,12 +39,6 @@ import { usePageChangeEffectNavigateLocation } from '~/hooks/usePageChangeEffect
import { getPageLayoutIdForLocation } from '~/modules/app/utils/getPageLayoutIdForLocation';
import { isMatchingLocation } from '~/utils/isMatchingLocation';
-const ONBOARDING_OR_AUTH_NAVIGATE_PATHS = [
- ...ONBOARDING_PATHS,
- ...ONGOING_USER_CREATION_PATHS,
- AppPath.ResetPassword,
-];
-
// TODO: break down into smaller functions and / or hooks
// - moved usePageChangeEffectNavigateLocation into dedicated hook
export const PageChangeEffect = () => {
@@ -106,12 +95,6 @@ export const PageChangeEffect = () => {
const isOnAuthOrOnboardingPage = useIsOnAuthOrOnboardingPage();
- const onboardingStatus = useOnboardingStatus();
-
- const isOnOnboardingPage = ONBOARDING_PATHS.some((appPath) =>
- isMatchingLocation(location, appPath),
- );
-
const closeSidePanelUnlessNotRelevant = useCallback(() => {
const currentPage = store.get(sidePanelPageState.atom);
@@ -169,21 +152,6 @@ export const PageChangeEffect = () => {
const consumedReturnToPath =
getReturnToPath() === pageChangeEffectNavigateLocation;
- const isNavigatingToOnboardingOrAuthPath =
- ONBOARDING_OR_AUTH_NAVIGATE_PATHS.some(
- (appPath) => pageChangeEffectNavigateLocation === appPath,
- );
-
- if (
- shouldShowWelcomeAnimationOnNavigate({
- onboardingStatus,
- isOnOnboardingPage,
- isNavigatingToOnboardingOrAuthPath,
- })
- ) {
- store.set(isWelcomeAnimationVisibleState.atom, true);
- }
-
navigate(pageChangeEffectNavigateLocation);
if (consumedReturnToPath) {
@@ -195,12 +163,9 @@ export const PageChangeEffect = () => {
pageChangeEffectNavigateLocation,
isAppEffectRedirectEnabled,
isOnAuthOrOnboardingPage,
- isOnOnboardingPage,
- onboardingStatus,
saveReturnToPath,
getReturnToPath,
clearReturnToPath,
- store,
]);
useEffect(() => {
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts
index c22fccd74a7..2b696b42dc9 100644
--- a/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts
+++ b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useSetNextOnboardingStatus.test.ts
@@ -7,7 +7,9 @@ import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceSta
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { billingState } from '@/client-config/states/billingState';
import { useSetNextOnboardingStatus } from '@/onboarding/hooks/useSetNextOnboardingStatus';
+import { isWelcomeAnimationVisibleState } from '@/onboarding/states/isWelcomeAnimationVisibleState';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import {
jotaiStore,
@@ -30,7 +32,7 @@ type RenderHooksOptions = {
};
const renderHooks = (
- onboardingStatus: OnboardingStatus,
+ onboardingStatus: OnboardingStatus | null,
{
withSubscription = false,
isBillingEnabled = false,
@@ -46,6 +48,9 @@ const renderHooks = (
const setCurrentWorkspace = useSetAtomState(currentWorkspaceState);
const setBilling = useSetAtomState(billingState);
const setNextOnboardingStatus = useSetNextOnboardingStatus();
+ const isWelcomeAnimationVisible = useAtomStateValue(
+ isWelcomeAnimationVisibleState,
+ );
return {
currentUser,
setCurrentUser,
@@ -53,6 +58,7 @@ const renderHooks = (
setCurrentUserWorkspace,
setBilling,
setNextOnboardingStatus,
+ isWelcomeAnimationVisible,
};
},
{
@@ -78,7 +84,10 @@ const renderHooks = (
act(() => {
result.current.setNextOnboardingStatus();
});
- return result.current.currentUser?.onboardingStatus;
+ return {
+ nextOnboardingStatus: result.current.currentUser?.onboardingStatus,
+ isWelcomeAnimationVisible: result.current.isWelcomeAnimationVisible,
+ };
};
describe('useSetNextOnboardingStatus', () => {
@@ -87,41 +96,50 @@ describe('useSetNextOnboardingStatus', () => {
});
it('should sync emails right after workspace activation', () => {
- const nextOnboardingStatus = renderHooks(
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
OnboardingStatus.WORKSPACE_ACTIVATION,
);
expect(nextOnboardingStatus).toEqual(OnboardingStatus.SYNC_EMAIL);
+ expect(isWelcomeAnimationVisible).toBe(false);
});
it('should install apps after syncing emails', () => {
- const nextOnboardingStatus = renderHooks(OnboardingStatus.SYNC_EMAIL);
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
+ OnboardingStatus.SYNC_EMAIL,
+ );
expect(nextOnboardingStatus).toEqual(OnboardingStatus.APPS_INSTALLATION);
+ expect(isWelcomeAnimationVisible).toBe(false);
});
it('should create profile after installing apps', () => {
- const nextOnboardingStatus = renderHooks(
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
OnboardingStatus.APPS_INSTALLATION,
);
expect(nextOnboardingStatus).toEqual(OnboardingStatus.PROFILE_CREATION);
+ expect(isWelcomeAnimationVisible).toBe(false);
});
it('should invite the team right after profile creation', () => {
- const nextOnboardingStatus = renderHooks(OnboardingStatus.PROFILE_CREATION);
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
+ OnboardingStatus.PROFILE_CREATION,
+ );
expect(nextOnboardingStatus).toEqual(OnboardingStatus.INVITE_TEAM);
+ expect(isWelcomeAnimationVisible).toBe(false);
});
it('should complete after profile creation when more than 1 workspaceMember exist', () => {
- const nextOnboardingStatus = renderHooks(
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
OnboardingStatus.PROFILE_CREATION,
{
withOneWorkspaceMember: false,
},
);
expect(nextOnboardingStatus).toEqual(OnboardingStatus.COMPLETED);
+ expect(isWelcomeAnimationVisible).toBe(true);
});
it('should require a plan after profile creation when billing is enabled and the workspace has no subscription', () => {
- const nextOnboardingStatus = renderHooks(
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
OnboardingStatus.PROFILE_CREATION,
{
withOneWorkspaceMember: false,
@@ -130,26 +148,53 @@ describe('useSetNextOnboardingStatus', () => {
},
);
expect(nextOnboardingStatus).toEqual(OnboardingStatus.PLAN_REQUIRED);
+ expect(isWelcomeAnimationVisible).toBe(false);
});
it('should complete after inviting the team when billing is disabled', () => {
- const nextOnboardingStatus = renderHooks(OnboardingStatus.INVITE_TEAM);
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
+ OnboardingStatus.INVITE_TEAM,
+ );
expect(nextOnboardingStatus).toEqual(OnboardingStatus.COMPLETED);
+ expect(isWelcomeAnimationVisible).toBe(true);
});
it('should complete after inviting the team when the workspace already has a subscription', () => {
- const nextOnboardingStatus = renderHooks(OnboardingStatus.INVITE_TEAM, {
- isBillingEnabled: true,
- withSubscription: true,
- });
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
+ OnboardingStatus.INVITE_TEAM,
+ {
+ isBillingEnabled: true,
+ withSubscription: true,
+ },
+ );
expect(nextOnboardingStatus).toEqual(OnboardingStatus.COMPLETED);
+ expect(isWelcomeAnimationVisible).toBe(true);
});
it('should require a plan after inviting the team when billing is enabled and the workspace has no subscription', () => {
- const nextOnboardingStatus = renderHooks(OnboardingStatus.INVITE_TEAM, {
- isBillingEnabled: true,
- withSubscription: false,
- });
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
+ OnboardingStatus.INVITE_TEAM,
+ {
+ isBillingEnabled: true,
+ withSubscription: false,
+ },
+ );
expect(nextOnboardingStatus).toEqual(OnboardingStatus.PLAN_REQUIRED);
+ expect(isWelcomeAnimationVisible).toBe(false);
+ });
+
+ it('should not show the welcome animation when the onboarding was already completed', () => {
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } = renderHooks(
+ OnboardingStatus.COMPLETED,
+ );
+ expect(nextOnboardingStatus).toEqual(OnboardingStatus.COMPLETED);
+ expect(isWelcomeAnimationVisible).toBe(false);
+ });
+
+ it('should not show the welcome animation when the onboarding status is unknown', () => {
+ const { nextOnboardingStatus, isWelcomeAnimationVisible } =
+ renderHooks(null);
+ expect(nextOnboardingStatus).toEqual(OnboardingStatus.COMPLETED);
+ expect(isWelcomeAnimationVisible).toBe(false);
});
});
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useShowWelcomeAnimationAfterOnboardingCheckout.test.ts b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useShowWelcomeAnimationAfterOnboardingCheckout.test.ts
new file mode 100644
index 00000000000..431b0925bab
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/hooks/__tests__/useShowWelcomeAnimationAfterOnboardingCheckout.test.ts
@@ -0,0 +1,99 @@
+import { act, renderHook } from '@testing-library/react';
+import { Provider as JotaiProvider } from 'jotai';
+import { createElement } from 'react';
+
+import { currentUserState } from '@/auth/states/currentUserState';
+import { useShowWelcomeAnimationAfterOnboardingCheckout } from '@/onboarding/hooks/useShowWelcomeAnimationAfterOnboardingCheckout';
+import { isOnboardingCheckoutPendingState } from '@/onboarding/states/isOnboardingCheckoutPendingState';
+import { isWelcomeAnimationVisibleState } from '@/onboarding/states/isWelcomeAnimationVisibleState';
+import {
+ jotaiStore,
+ resetJotaiStore,
+} from '@/ui/utilities/state/jotai/jotaiStore';
+
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+import { mockedUserData } from '~/testing/mock-data/users';
+
+const Wrapper = ({ children }: { children: React.ReactNode }) =>
+ createElement(JotaiProvider, { store: jotaiStore }, children);
+
+const renderAndShow = ({
+ isOnboardingCheckoutPending,
+ onboardingStatus,
+}: {
+ isOnboardingCheckoutPending: boolean;
+ onboardingStatus: OnboardingStatus;
+}) => {
+ jotaiStore.set(currentUserState.atom, {
+ ...mockedUserData,
+ onboardingStatus,
+ });
+ jotaiStore.set(
+ isOnboardingCheckoutPendingState.atom,
+ isOnboardingCheckoutPending,
+ );
+
+ const { result } = renderHook(
+ () => useShowWelcomeAnimationAfterOnboardingCheckout(),
+ { wrapper: Wrapper },
+ );
+
+ act(() => {
+ result.current();
+ });
+};
+
+describe('useShowWelcomeAnimationAfterOnboardingCheckout', () => {
+ beforeEach(() => {
+ resetJotaiStore();
+ });
+
+ it('should show the welcome animation when the onboarding checkout is confirmed', () => {
+ renderAndShow({
+ isOnboardingCheckoutPending: true,
+ onboardingStatus: OnboardingStatus.COMPLETED,
+ });
+
+ expect(jotaiStore.get(isWelcomeAnimationVisibleState.atom)).toBe(true);
+ });
+
+ it('should not show the welcome animation when no onboarding checkout is pending', () => {
+ renderAndShow({
+ isOnboardingCheckoutPending: false,
+ onboardingStatus: OnboardingStatus.COMPLETED,
+ });
+
+ expect(jotaiStore.get(isWelcomeAnimationVisibleState.atom)).toBe(false);
+ });
+
+ it('should not show the welcome animation while the onboarding is not completed yet', () => {
+ renderAndShow({
+ isOnboardingCheckoutPending: true,
+ onboardingStatus: OnboardingStatus.PLAN_REQUIRED,
+ });
+
+ expect(jotaiStore.get(isWelcomeAnimationVisibleState.atom)).toBe(false);
+ });
+
+ it('should consume the pending onboarding checkout so it cannot replay', () => {
+ renderAndShow({
+ isOnboardingCheckoutPending: true,
+ onboardingStatus: OnboardingStatus.COMPLETED,
+ });
+
+ expect(jotaiStore.get(isOnboardingCheckoutPendingState.atom)).toBe(false);
+
+ jotaiStore.set(isWelcomeAnimationVisibleState.atom, false);
+
+ const { result } = renderHook(
+ () => useShowWelcomeAnimationAfterOnboardingCheckout(),
+ { wrapper: Wrapper },
+ );
+
+ act(() => {
+ result.current();
+ });
+
+ expect(jotaiStore.get(isWelcomeAnimationVisibleState.atom)).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts b/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts
index 0f96a393837..691ec6e3993 100644
--- a/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts
+++ b/packages/twenty-front/src/modules/onboarding/hooks/useSetNextOnboardingStatus.ts
@@ -9,6 +9,8 @@ import {
currentWorkspaceState,
} from '@/auth/states/currentWorkspaceState';
import { billingState } from '@/client-config/states/billingState';
+import { isWelcomeAnimationVisibleState } from '@/onboarding/states/isWelcomeAnimationVisibleState';
+import { getHasJustCompletedOnboarding } from '@/onboarding/utils/getHasJustCompletedOnboarding';
import { getIsPlanRequired } from '@/onboarding/utils/getIsPlanRequired';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
@@ -82,5 +84,14 @@ export const useSetNextOnboardingStatus = () => {
}
return current;
});
+
+ if (
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: currentUser?.onboardingStatus,
+ nextOnboardingStatus,
+ })
+ ) {
+ store.set(isWelcomeAnimationVisibleState.atom, true);
+ }
}, [currentUser, currentWorkspace, isBillingEnabled, store]);
};
diff --git a/packages/twenty-front/src/modules/onboarding/hooks/useShowWelcomeAnimationAfterOnboardingCheckout.ts b/packages/twenty-front/src/modules/onboarding/hooks/useShowWelcomeAnimationAfterOnboardingCheckout.ts
new file mode 100644
index 00000000000..4127cc8113a
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/hooks/useShowWelcomeAnimationAfterOnboardingCheckout.ts
@@ -0,0 +1,24 @@
+import { currentUserState } from '@/auth/states/currentUserState';
+import { isOnboardingCheckoutPendingState } from '@/onboarding/states/isOnboardingCheckoutPendingState';
+import { isWelcomeAnimationVisibleState } from '@/onboarding/states/isWelcomeAnimationVisibleState';
+import { useStore } from 'jotai';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+export const useShowWelcomeAnimationAfterOnboardingCheckout = () => {
+ const store = useStore();
+
+ return () => {
+ if (!store.get(isOnboardingCheckoutPendingState.atom)) {
+ return;
+ }
+
+ const onboardingStatus = store.get(currentUserState.atom)?.onboardingStatus;
+
+ if (onboardingStatus !== OnboardingStatus.COMPLETED) {
+ return;
+ }
+
+ store.set(isOnboardingCheckoutPendingState.atom, false);
+ store.set(isWelcomeAnimationVisibleState.atom, true);
+ };
+};
diff --git a/packages/twenty-front/src/modules/onboarding/states/isOnboardingCheckoutPendingState.ts b/packages/twenty-front/src/modules/onboarding/states/isOnboardingCheckoutPendingState.ts
new file mode 100644
index 00000000000..ea6495a1466
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/states/isOnboardingCheckoutPendingState.ts
@@ -0,0 +1,7 @@
+import { createAtomState } from '@/ui/utilities/state/jotai/utils/createAtomState';
+
+export const isOnboardingCheckoutPendingState = createAtomState<boolean>({
+ key: 'isOnboardingCheckoutPendingState',
+ defaultValue: false,
+ useSessionStorage: true,
+});
diff --git a/packages/twenty-front/src/modules/onboarding/utils/__tests__/getHasJustCompletedOnboarding.test.ts b/packages/twenty-front/src/modules/onboarding/utils/__tests__/getHasJustCompletedOnboarding.test.ts
new file mode 100644
index 00000000000..6832b28c772
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/utils/__tests__/getHasJustCompletedOnboarding.test.ts
@@ -0,0 +1,58 @@
+import { getHasJustCompletedOnboarding } from '@/onboarding/utils/getHasJustCompletedOnboarding';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+describe('getHasJustCompletedOnboarding', () => {
+ it('should return true when the last onboarding step is completed', () => {
+ expect(
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: OnboardingStatus.INVITE_TEAM,
+ nextOnboardingStatus: OnboardingStatus.COMPLETED,
+ }),
+ ).toBe(true);
+ });
+
+ it('should return true when the profile creation step completes the onboarding', () => {
+ expect(
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: OnboardingStatus.PROFILE_CREATION,
+ nextOnboardingStatus: OnboardingStatus.COMPLETED,
+ }),
+ ).toBe(true);
+ });
+
+ it('should return false when an intermediate onboarding step is completed', () => {
+ expect(
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: OnboardingStatus.SYNC_EMAIL,
+ nextOnboardingStatus: OnboardingStatus.APPS_INSTALLATION,
+ }),
+ ).toBe(false);
+ });
+
+ it('should return false when the onboarding was already completed', () => {
+ expect(
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: OnboardingStatus.COMPLETED,
+ nextOnboardingStatus: OnboardingStatus.COMPLETED,
+ }),
+ ).toBe(false);
+ });
+
+ it('should return false when the previous onboarding status is undefined', () => {
+ expect(
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: undefined,
+ nextOnboardingStatus: OnboardingStatus.COMPLETED,
+ }),
+ ).toBe(false);
+ });
+
+ it('should return false when the previous onboarding status is null', () => {
+ expect(
+ getHasJustCompletedOnboarding({
+ previousOnboardingStatus: null,
+ nextOnboardingStatus: OnboardingStatus.COMPLETED,
+ }),
+ ).toBe(false);
+ });
+});
diff --git a/packages/twenty-front/src/modules/onboarding/utils/__tests__/shouldShowWelcomeAnimationOnNavigate.test.ts b/packages/twenty-front/src/modules/onboarding/utils/__tests__/shouldShowWelcomeAnimationOnNavigate.test.ts
deleted file mode 100644
index c49df3a1f0a..00000000000
--- a/packages/twenty-front/src/modules/onboarding/utils/__tests__/shouldShowWelcomeAnimationOnNavigate.test.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import { shouldShowWelcomeAnimationOnNavigate } from '@/onboarding/utils/shouldShowWelcomeAnimationOnNavigate';
-import { OnboardingStatus } from '~/generated-metadata/graphql';
-
-describe('shouldShowWelcomeAnimationOnNavigate', () => {
- it('should return true when leaving an onboarding page for the workspace after completion', () => {
- expect(
- shouldShowWelcomeAnimationOnNavigate({
- onboardingStatus: OnboardingStatus.COMPLETED,
- isOnOnboardingPage: true,
- isNavigatingToOnboardingOrAuthPath: false,
- }),
- ).toBe(true);
- });
-
- it('should return false when onboarding is not yet completed', () => {
- expect(
- shouldShowWelcomeAnimationOnNavigate({
- onboardingStatus: OnboardingStatus.INVITE_TEAM,
- isOnOnboardingPage: true,
- isNavigatingToOnboardingOrAuthPath: false,
- }),
- ).toBe(false);
- });
-
- it('should return false when navigating to another onboarding or auth path', () => {
- expect(
- shouldShowWelcomeAnimationOnNavigate({
- onboardingStatus: OnboardingStatus.COMPLETED,
- isOnOnboardingPage: true,
- isNavigatingToOnboardingOrAuthPath: true,
- }),
- ).toBe(false);
- });
-
- it('should return false when the current page is not an onboarding page', () => {
- expect(
- shouldShowWelcomeAnimationOnNavigate({
- onboardingStatus: OnboardingStatus.COMPLETED,
- isOnOnboardingPage: false,
- isNavigatingToOnboardingOrAuthPath: false,
- }),
- ).toBe(false);
- });
-
- it('should return false when the onboarding status is undefined', () => {
- expect(
- shouldShowWelcomeAnimationOnNavigate({
- onboardingStatus: undefined,
- isOnOnboardingPage: true,
- isNavigatingToOnboardingOrAuthPath: false,
- }),
- ).toBe(false);
- });
-});
diff --git a/packages/twenty-front/src/modules/onboarding/utils/getHasJustCompletedOnboarding.ts b/packages/twenty-front/src/modules/onboarding/utils/getHasJustCompletedOnboarding.ts
new file mode 100644
index 00000000000..9149c3439b5
--- /dev/null
+++ b/packages/twenty-front/src/modules/onboarding/utils/getHasJustCompletedOnboarding.ts
@@ -0,0 +1,15 @@
+import { isDefined } from 'twenty-shared/utils';
+import { OnboardingStatus } from '~/generated-metadata/graphql';
+
+type GetHasJustCompletedOnboardingArgs = {
+ previousOnboardingStatus: OnboardingStatus | null | undefined;
+ nextOnboardingStatus: OnboardingStatus;
+};
+
+export const getHasJustCompletedOnboarding = ({
+ previousOnboardingStatus,
+ nextOnboardingStatus,
+}: GetHasJustCompletedOnboardingArgs): boolean =>
+ nextOnboardingStatus === OnboardingStatus.COMPLETED &&
+ isDefined(previousOnboardingStatus) &&
+ previousOnboardingStatus !== OnboardingStatus.COMPLETED;
diff --git a/packages/twenty-front/src/modules/onboarding/utils/shouldShowWelcomeAnimationOnNavigate.ts b/packages/twenty-front/src/modules/onboarding/utils/shouldShowWelcomeAnimationOnNavigate.ts
deleted file mode 100644
index 4a29f06a611..00000000000
--- a/packages/twenty-front/src/modules/onboarding/utils/shouldShowWelcomeAnimationOnNavigate.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { OnboardingStatus } from '~/generated-metadata/graphql';
-
-type ShouldShowWelcomeAnimationOnNavigateArgs = {
- onboardingStatus: OnboardingStatus | null | undefined;
- isOnOnboardingPage: boolean;
- isNavigatingToOnboardingOrAuthPath: boolean;
-};
-
-export const shouldShowWelcomeAnimationOnNavigate = ({
- onboardingStatus,
- isOnOnboardingPage,
- isNavigatingToOnboardingOrAuthPath,
-}: ShouldShowWelcomeAnimationOnNavigateArgs): boolean =>
- onboardingStatus === OnboardingStatus.COMPLETED &&
- isOnOnboardingPage &&
- !isNavigatingToOnboardingOrAuthPath;
diff --git a/packages/twenty-front/src/pages/onboarding/PaymentSuccess.tsx b/packages/twenty-front/src/pages/onboarding/PaymentSuccess.tsx
index 9ab5b16dd62..499e1fee345 100644
--- a/packages/twenty-front/src/pages/onboarding/PaymentSuccess.tsx
+++ b/packages/twenty-front/src/pages/onboarding/PaymentSuccess.tsx
@@ -3,6 +3,7 @@ import { currentUserState } from '@/auth/states/currentUserState';
import { OnboardingAnimatedReveal } from '@/onboarding/components/OnboardingAnimatedReveal';
import { OnboardingVerifyLayout } from '@/onboarding/components/OnboardingVerifyLayout';
import { useOnboardingMotionTransition } from '@/onboarding/hooks/useOnboardingMotionTransition';
+import { useShowWelcomeAnimationAfterOnboardingCheckout } from '@/onboarding/hooks/useShowWelcomeAnimationAfterOnboardingCheckout';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';
@@ -30,6 +31,8 @@ export const PaymentSuccess = () => {
fetchPolicy: 'network-only',
});
const setCurrentUser = useSetAtomState(currentUserState);
+ const showWelcomeAnimationAfterOnboardingCheckout =
+ useShowWelcomeAnimationAfterOnboardingCheckout();
const { enqueueErrorSnackBar } = useSnackBar();
const [hasTimedOut, setHasTimedOut] = useState(false);
const [confirmationRunIndex, setConfirmationRunIndex] = useState(0);
@@ -45,6 +48,7 @@ export const PaymentSuccess = () => {
}
if (isDefined(subscriptionStatus)) {
+ showWelcomeAnimationAfterOnboardingCheckout();
return;
}
@@ -60,6 +64,7 @@ export const PaymentSuccess = () => {
if (isDefined(currentUser) && isDefined(refreshedSubscriptionStatus)) {
setCurrentUser(currentUser);
+ showWelcomeAnimationAfterOnboardingCheckout();
return;
}
diff --git a/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx b/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx
index ab72cf2a109..a0a5a0711e0 100644
--- a/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx
+++ b/packages/twenty-front/src/pages/onboarding/UpgradeFreeTrial.tsx
@@ -13,6 +13,7 @@ import { OnboardingStepAnimatedItem } from '@/onboarding/components/OnboardingSt
import { OnboardingCreditsRewardTag } from '@/onboarding/components/import-contacts/OnboardingCreditsRewardTag';
import { OnboardingPlanCard } from '@/onboarding/components/upgrade-free-trial/OnboardingPlanCard';
import { OnboardingTrialExtensionTag } from '@/onboarding/components/upgrade-free-trial/OnboardingTrialExtensionTag';
+import { isOnboardingCheckoutPendingState } from '@/onboarding/states/isOnboardingCheckoutPendingState';
import { useBaseLicensedPriceByPlanKeyAndInterval } from '@/settings/billing/hooks/useBaseLicensedPriceByPlanKeyAndInterval';
import { useHandleCheckoutSession } from '@/settings/billing/hooks/useHandleCheckoutSession';
import { useStripeAppearance } from '@/settings/billing/hooks/useStripeAppearance';
@@ -20,6 +21,7 @@ import { useStripePromise } from '@/settings/billing/hooks/useStripePromise';
import { useSubmitSubscriptionPayment } from '@/settings/billing/hooks/useSubmitSubscriptionPayment';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { styled } from '@linaria/react';
import { Trans, useLingui } from '@lingui/react/macro';
import { Elements, PaymentElement } from '@stripe/react-stripe-js';
@@ -89,10 +91,19 @@ const UpgradeFreeTrialSubmitButton = ({
recurringInterval,
});
+ const setIsOnboardingCheckoutPending = useSetAtomState(
+ isOnboardingCheckoutPendingState,
+ );
+
+ const handleSubmit = () => {
+ setIsOnboardingCheckoutPending(true);
+ void submit();
+ };
+
return (
<MainButton
title={t`Continue`}
- onClick={submit}
+ onClick={handleSubmit}
fullWidth
Icon={() => (isSubmitting ? <Loader /> : null)}
disabled={!isStripeReady || isSubmitting}
@@ -142,6 +153,15 @@ const UpgradeFreeTrialContent = ({
successUrlPath: AppPath.PlanRequiredSuccess,
});
+ const setIsOnboardingCheckoutPending = useSetAtomState(
+ isOnboardingCheckoutPendingState,
+ );
+
+ const handleCheckoutSessionClick = () => {
+ setIsOnboardingCheckoutPending(true);
+ void handleCheckoutSession();
+ };
+
const selectTrialPeriod = (withCreditCard: boolean) => () => {
if (
isDefined(baseProductPrice) &&
@@ -213,7 +233,7 @@ const UpgradeFreeTrialContent = ({
) : (
<MainButton
title={t`Continue`}
- onClick={handleCheckoutSession}
+ onClick={handleCheckoutSessionClick}
fullWidth
Icon={() => (isCheckoutSubmitting ? <Loader /> : null)}
disabled={isCheckoutSubmitting}