From f5f4326b2e7adeb9fa074a79ef484632d74b83d9 Mon Sep 17 00:00:00 2001 From: martmull Date: Wed, 31 Jan 2024 11:21:37 +0100 Subject: [PATCH] Update onboarding status --- .../src/effect-components/PageChangeEffect.tsx | 2 +- .../auth/sign-in-up/hooks/useSignInUp.tsx | 16 ++++++++-------- .../modules/auth/utils/getOnboardingStatus.ts | 11 +++++++---- .../src/pages/auth/PasswordReset.tsx | 4 ++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/packages/twenty-front/src/effect-components/PageChangeEffect.tsx b/packages/twenty-front/src/effect-components/PageChangeEffect.tsx index 9a165f349f7..989d8377325 100644 --- a/packages/twenty-front/src/effect-components/PageChangeEffect.tsx +++ b/packages/twenty-front/src/effect-components/PageChangeEffect.tsx @@ -101,7 +101,7 @@ export const PageChangeEffect = () => { onboardingStatus === OnboardingStatus.Completed && isMatchingOnboardingRoute ) { - navigate('/'); + navigate(AppPath.Index); } else if (isMatchingLocation(AppPath.Invite)) { const inviteHash = matchPath({ path: '/invite/:workspaceInviteHash' }, location.pathname) diff --git a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx index a2192f77691..9843b28c155 100644 --- a/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx +++ b/packages/twenty-front/src/modules/auth/sign-in-up/hooks/useSignInUp.tsx @@ -141,18 +141,18 @@ export const useSignInUp = () => { if ( billing?.isBillingEnabled && - currentWorkspace.subscriptionStatus !== 'active' + (!currentWorkspace || + currentWorkspace.subscriptionStatus !== 'active') ) { - navigate('/plan-required'); + navigate(AppPath.PlanRequired); + return; + } + if (currentWorkspace?.displayName) { + navigate(AppPath.Index); return; } - if (currentWorkspace.displayName) { - navigate('/'); - return; - } - - navigate('/create/workspace'); + navigate(AppPath.CreateWorkspace); } catch (err: any) { enqueueSnackBar(err?.message, { variant: 'error', diff --git a/packages/twenty-front/src/modules/auth/utils/getOnboardingStatus.ts b/packages/twenty-front/src/modules/auth/utils/getOnboardingStatus.ts index 4d8f533ef0f..e6c7b081f04 100644 --- a/packages/twenty-front/src/modules/auth/utils/getOnboardingStatus.ts +++ b/packages/twenty-front/src/modules/auth/utils/getOnboardingStatus.ts @@ -27,12 +27,15 @@ export const getOnboardingStatus = ({ if (!isLoggedIn) { return OnboardingStatus.OngoingUserCreation; } - // if the user has not been fetched yet, we can't know the onboarding status - if (!currentWorkspaceMember) { + if (currentWorkspace && !currentWorkspaceMember) { return undefined; } + if (!currentWorkspace && isBillingEnabled) { + return OnboardingStatus.Incomplete; + } + if ( isBillingEnabled && currentWorkspace?.subscriptionStatus === 'incomplete' @@ -48,8 +51,8 @@ export const getOnboardingStatus = ({ return OnboardingStatus.OngoingWorkspaceCreation; } if ( - !currentWorkspaceMember.name.firstName || - !currentWorkspaceMember.name.lastName + !currentWorkspaceMember?.name.firstName || + !currentWorkspaceMember?.name.lastName ) { return OnboardingStatus.OngoingProfileCreation; } diff --git a/packages/twenty-front/src/pages/auth/PasswordReset.tsx b/packages/twenty-front/src/pages/auth/PasswordReset.tsx index 72d8816950f..b28e361ab70 100644 --- a/packages/twenty-front/src/pages/auth/PasswordReset.tsx +++ b/packages/twenty-front/src/pages/auth/PasswordReset.tsx @@ -157,13 +157,13 @@ export const PasswordReset = () => { if ( billing?.isBillingEnabled && - currentWorkspace.subscriptionStatus !== 'active' + (!currentWorkspace || currentWorkspace.subscriptionStatus !== 'active') ) { navigate(AppPath.PlanRequired); return; } - if (currentWorkspace.displayName) { + if (currentWorkspace?.displayName) { navigate(AppPath.Index); return; }