5095 move onboardingstatus computation from frontend to backend (#5954)
- move front `onboardingStatus` computing to server side - add logic to `useSetNextOnboardingStatus` - update some missing redirections in `usePageChangeEffectNavigateLocation` - separate subscriptionStatus from onboardingStatus
This commit is contained in:
@ -1,174 +0,0 @@
|
||||
import { CurrentUser } from '@/auth/states/currentUserState';
|
||||
import { CurrentWorkspace } from '@/auth/states/currentWorkspaceState';
|
||||
import { WorkspaceMember } from '@/workspace-member/types/WorkspaceMember';
|
||||
import { OnboardingStep } from '~/generated/graphql';
|
||||
|
||||
import { getOnboardingStatus } from '../getOnboardingStatus';
|
||||
|
||||
describe('getOnboardingStatus', () => {
|
||||
it('should return the correct status', () => {
|
||||
const ongoingUserCreation = getOnboardingStatus({
|
||||
isLoggedIn: false,
|
||||
currentWorkspaceMember: null,
|
||||
currentWorkspace: null,
|
||||
currentUser: null,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const ongoingWorkspaceActivation = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: null,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'inactive',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: null,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const ongoingProfileCreation = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: null,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const ongoingSyncEmail = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: OnboardingStep.SyncEmail,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const ongoingInviteTeam = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: OnboardingStep.InviteTeam,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const completed = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: null,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const incomplete = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
subscriptionStatus: 'incomplete',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: null,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: true,
|
||||
});
|
||||
|
||||
const incompleteButBillingDisabled = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
subscriptionStatus: 'incomplete',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: null,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: false,
|
||||
});
|
||||
|
||||
const canceled = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
activationStatus: 'active',
|
||||
subscriptionStatus: 'canceled',
|
||||
} as CurrentWorkspace,
|
||||
currentUser: {
|
||||
onboardingStep: null,
|
||||
} as CurrentUser,
|
||||
isBillingEnabled: true,
|
||||
});
|
||||
|
||||
expect(ongoingUserCreation).toBe('ongoing_user_creation');
|
||||
expect(ongoingWorkspaceActivation).toBe('ongoing_workspace_activation');
|
||||
expect(ongoingProfileCreation).toBe('ongoing_profile_creation');
|
||||
expect(ongoingSyncEmail).toBe('ongoing_sync_email');
|
||||
expect(ongoingInviteTeam).toBe('ongoing_invite_team');
|
||||
expect(completed).toBe('completed');
|
||||
expect(incomplete).toBe('incomplete');
|
||||
expect(canceled).toBe('canceled');
|
||||
expect(incompleteButBillingDisabled).toBe('completed');
|
||||
});
|
||||
});
|
||||
@ -1,89 +0,0 @@
|
||||
import { CurrentUser } from '@/auth/states/currentUserState';
|
||||
import { CurrentWorkspace } from '@/auth/states/currentWorkspaceState';
|
||||
import { WorkspaceMember } from '@/workspace-member/types/WorkspaceMember';
|
||||
import { OnboardingStep } from '~/generated/graphql';
|
||||
|
||||
export enum OnboardingStatus {
|
||||
Incomplete = 'incomplete',
|
||||
Canceled = 'canceled',
|
||||
Unpaid = 'unpaid',
|
||||
PastDue = 'past_due',
|
||||
OngoingUserCreation = 'ongoing_user_creation',
|
||||
OngoingWorkspaceActivation = 'ongoing_workspace_activation',
|
||||
OngoingProfileCreation = 'ongoing_profile_creation',
|
||||
OngoingSyncEmail = 'ongoing_sync_email',
|
||||
OngoingInviteTeam = 'ongoing_invite_team',
|
||||
Completed = 'completed',
|
||||
CompletedWithoutSubscription = 'completed_without_subscription',
|
||||
}
|
||||
|
||||
export const getOnboardingStatus = ({
|
||||
isLoggedIn,
|
||||
currentWorkspaceMember,
|
||||
currentWorkspace,
|
||||
currentUser,
|
||||
isBillingEnabled,
|
||||
}: {
|
||||
isLoggedIn: boolean;
|
||||
currentWorkspaceMember: Omit<
|
||||
WorkspaceMember,
|
||||
'createdAt' | 'updatedAt' | 'userId' | 'userEmail' | '__typename'
|
||||
> | null;
|
||||
currentWorkspace: CurrentWorkspace | null;
|
||||
currentUser: CurrentUser | null;
|
||||
isBillingEnabled: boolean;
|
||||
}) => {
|
||||
if (!isLoggedIn) {
|
||||
return OnboardingStatus.OngoingUserCreation;
|
||||
}
|
||||
|
||||
// After SignInUp, the user should have a current workspace assigned.
|
||||
// If not, it indicates that the data is still being requested.
|
||||
if (!currentWorkspace || !currentUser) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
isBillingEnabled &&
|
||||
currentWorkspace.subscriptionStatus === 'incomplete'
|
||||
) {
|
||||
return OnboardingStatus.Incomplete;
|
||||
}
|
||||
|
||||
if (currentWorkspace.activationStatus !== 'active') {
|
||||
return OnboardingStatus.OngoingWorkspaceActivation;
|
||||
}
|
||||
|
||||
if (
|
||||
!currentWorkspaceMember?.name.firstName ||
|
||||
!currentWorkspaceMember?.name.lastName
|
||||
) {
|
||||
return OnboardingStatus.OngoingProfileCreation;
|
||||
}
|
||||
|
||||
if (currentUser.onboardingStep === OnboardingStep.SyncEmail) {
|
||||
return OnboardingStatus.OngoingSyncEmail;
|
||||
}
|
||||
|
||||
if (currentUser.onboardingStep === OnboardingStep.InviteTeam) {
|
||||
return OnboardingStatus.OngoingInviteTeam;
|
||||
}
|
||||
|
||||
if (isBillingEnabled && currentWorkspace.subscriptionStatus === 'canceled') {
|
||||
return OnboardingStatus.Canceled;
|
||||
}
|
||||
|
||||
if (isBillingEnabled && currentWorkspace.subscriptionStatus === 'past_due') {
|
||||
return OnboardingStatus.PastDue;
|
||||
}
|
||||
|
||||
if (isBillingEnabled && currentWorkspace.subscriptionStatus === 'unpaid') {
|
||||
return OnboardingStatus.Unpaid;
|
||||
}
|
||||
|
||||
if (isBillingEnabled && !currentWorkspace.currentBillingSubscription) {
|
||||
return OnboardingStatus.CompletedWithoutSubscription;
|
||||
}
|
||||
|
||||
return OnboardingStatus.Completed;
|
||||
};
|
||||
Reference in New Issue
Block a user