3628 timebox separate user creation from workspace creation (#3737)
* Remove workspace schema creation from signUp * Set user workspaceMember nullable * Remove workspace creation * Handle null workspace in tokens * Update onboarding status * Generate types * Move createWorkspace to workspace resolver * Create workspace after signup * Update createWorkspace return type * Update createWorkspace return type * Create core.workspace at signup * WIP * Fix create workspace * Fix create workspace * Clean code * Remove useless recoil set * Simplify create workspace request * Set currentWorkspace at login * Fix tests * Create a recoil value for is workspaceSchema created * Rename createWorkspace to createWorkspaceSchema * Code review returns * Use AppPath when possible * Try without state * Fix * Fixes * Rename createWorkspaceSchema to activateWorkspace * Remove defaultAvatarUrl from user * Add defaultAvatarUrl to core user This reverts commit 1701c30eb18804558293cc42043aedf96ea888df. * Add defaultAvatarUrl to core user This reverts commit 1701c30eb18804558293cc42043aedf96ea888df. * Fix ci * Fix tests * Fix storybook * Fix test * Remove useless query * Fix test * Fix test * Fix mock data * Fix test * Clean Mock Requests * Fix tentative * Revert "Clean Mock Requests" This reverts commit 8aa20a34363ffddfdee24f18fc80b27ea0ad5e1d. * Fix * Revert "Fix" This reverts commit 2df7e9b6569b8bfb53f6a45391db725e28d16a18. * Revert "Revert "Clean Mock Requests"" This reverts commit 3aefef8e9600d161434a047e845563d1b8e0692e. * Revert "Fix tentative" This reverts commit 13e7748d6f3b3858d30fb08adbc8ad347c5556ee. * Update filename --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -66,16 +66,6 @@ describe('useOnboardingStatus', () => {
|
||||
expect(result.current.onboardingStatus).toBe('ongoing_user_creation');
|
||||
});
|
||||
|
||||
it('should return undefined when currentWorkspaceMember in undefined', async () => {
|
||||
const { result } = renderHooks();
|
||||
|
||||
act(() => {
|
||||
result.current.setTokenPair(tokenPair);
|
||||
});
|
||||
|
||||
expect(result.current.onboardingStatus).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should return "incomplete"', async () => {
|
||||
const { result } = renderHooks();
|
||||
const {
|
||||
@ -120,14 +110,9 @@ describe('useOnboardingStatus', () => {
|
||||
expect(result.current.onboardingStatus).toBe('canceled');
|
||||
});
|
||||
|
||||
it('should return "ongoing_workspace_creation"', async () => {
|
||||
it('should return "ongoing_workspace_activation"', async () => {
|
||||
const { result } = renderHooks();
|
||||
const {
|
||||
setTokenPair,
|
||||
setBilling,
|
||||
setCurrentWorkspace,
|
||||
setCurrentWorkspaceMember,
|
||||
} = result.current;
|
||||
const { setTokenPair, setBilling, setCurrentWorkspace } = result.current;
|
||||
|
||||
act(() => {
|
||||
setTokenPair(tokenPair);
|
||||
@ -135,12 +120,31 @@ describe('useOnboardingStatus', () => {
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
displayName: '',
|
||||
subscriptionStatus: 'completed',
|
||||
subscriptionStatus: 'active',
|
||||
});
|
||||
setCurrentWorkspaceMember(currentWorkspaceMember);
|
||||
});
|
||||
|
||||
expect(result.current.onboardingStatus).toBe('ongoing_workspace_creation');
|
||||
expect(result.current.onboardingStatus).toBe(
|
||||
'ongoing_workspace_activation',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return "ongoing_workspace_activation"', async () => {
|
||||
const { result } = renderHooks();
|
||||
const { setTokenPair, setBilling, setCurrentWorkspace } = result.current;
|
||||
|
||||
act(() => {
|
||||
setTokenPair(tokenPair);
|
||||
setBilling(billing);
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
subscriptionStatus: 'active',
|
||||
});
|
||||
});
|
||||
|
||||
expect(result.current.onboardingStatus).toBe(
|
||||
'ongoing_workspace_activation',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return "ongoing_profile_creation"', async () => {
|
||||
@ -157,7 +161,7 @@ describe('useOnboardingStatus', () => {
|
||||
setBilling(billing);
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
subscriptionStatus: 'completed',
|
||||
subscriptionStatus: 'active',
|
||||
});
|
||||
setCurrentWorkspaceMember(currentWorkspaceMember);
|
||||
});
|
||||
@ -179,7 +183,7 @@ describe('useOnboardingStatus', () => {
|
||||
setBilling(billing);
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
subscriptionStatus: 'completed',
|
||||
subscriptionStatus: 'active',
|
||||
});
|
||||
setCurrentWorkspaceMember({
|
||||
...currentWorkspaceMember,
|
||||
|
||||
@ -89,13 +89,16 @@ export const useAuth = () => {
|
||||
setTokenPair(verifyResult.data?.verify.tokens);
|
||||
|
||||
const user = verifyResult.data?.verify.user;
|
||||
const workspaceMember = {
|
||||
...user.workspaceMember,
|
||||
colorScheme: user.workspaceMember?.colorScheme as ColorScheme,
|
||||
};
|
||||
const workspace = user.defaultWorkspace ?? null;
|
||||
let workspaceMember = null;
|
||||
setCurrentUser(user);
|
||||
setCurrentWorkspaceMember(workspaceMember);
|
||||
if (user.workspaceMember) {
|
||||
workspaceMember = {
|
||||
...user.workspaceMember,
|
||||
colorScheme: user.workspaceMember?.colorScheme as ColorScheme,
|
||||
};
|
||||
setCurrentWorkspaceMember(workspaceMember);
|
||||
}
|
||||
const workspace = user.defaultWorkspace ?? null;
|
||||
setCurrentWorkspace(workspace);
|
||||
return {
|
||||
user,
|
||||
|
||||
@ -143,16 +143,15 @@ export const useSignInUp = () => {
|
||||
billing?.isBillingEnabled &&
|
||||
currentWorkspace.subscriptionStatus !== 'active'
|
||||
) {
|
||||
navigate('/plan-required');
|
||||
navigate(AppPath.PlanRequired);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentWorkspace.displayName) {
|
||||
navigate('/');
|
||||
navigate(AppPath.Index);
|
||||
return;
|
||||
}
|
||||
|
||||
navigate('/create/workspace');
|
||||
navigate(AppPath.CreateWorkspace);
|
||||
} catch (err: any) {
|
||||
enqueueSnackBar(err?.message, {
|
||||
variant: 'error',
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
import { selector } from 'recoil';
|
||||
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
|
||||
export const isCurrentWorkspaceActiveSelector = selector({
|
||||
key: 'isCurrentWorkspaceActiveSelector',
|
||||
get: ({ get }) => {
|
||||
const currentWorkspaceMember = get(currentWorkspaceMemberState);
|
||||
return !!currentWorkspaceMember;
|
||||
},
|
||||
});
|
||||
@ -11,27 +11,24 @@ describe('getOnboardingStatus', () => {
|
||||
currentWorkspace: null,
|
||||
});
|
||||
|
||||
const unknownStatus = getOnboardingStatus({
|
||||
const ongoingWorkspaceActivation = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: null,
|
||||
currentWorkspace: null,
|
||||
});
|
||||
|
||||
const ongoingWorkspaceCreation = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
id: '1',
|
||||
name: {
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
},
|
||||
} as WorkspaceMember,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
displayName: null,
|
||||
} as CurrentWorkspace,
|
||||
});
|
||||
|
||||
const ongoingWorkspaceActivationPreviouslyActive = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: null,
|
||||
currentWorkspace: {
|
||||
id: '1',
|
||||
displayName: 'My Workspace',
|
||||
} as CurrentWorkspace,
|
||||
});
|
||||
|
||||
const ongoingProfileCreation = getOnboardingStatus({
|
||||
isLoggedIn: true,
|
||||
currentWorkspaceMember: {
|
||||
@ -110,8 +107,10 @@ describe('getOnboardingStatus', () => {
|
||||
});
|
||||
|
||||
expect(ongoingUserCreation).toBe('ongoing_user_creation');
|
||||
expect(unknownStatus).toBe(undefined);
|
||||
expect(ongoingWorkspaceCreation).toBe('ongoing_workspace_creation');
|
||||
expect(ongoingWorkspaceActivation).toBe('ongoing_workspace_activation');
|
||||
expect(ongoingWorkspaceActivationPreviouslyActive).toBe(
|
||||
'ongoing_workspace_activation',
|
||||
);
|
||||
expect(ongoingProfileCreation).toBe('ongoing_profile_creation');
|
||||
expect(completed).toBe('completed');
|
||||
expect(incomplete).toBe('incomplete');
|
||||
|
||||
@ -5,7 +5,7 @@ export enum OnboardingStatus {
|
||||
Incomplete = 'incomplete',
|
||||
Canceled = 'canceled',
|
||||
OngoingUserCreation = 'ongoing_user_creation',
|
||||
OngoingWorkspaceCreation = 'ongoing_workspace_creation',
|
||||
OngoingWorkspaceActivation = 'ongoing_workspace_activation',
|
||||
OngoingProfileCreation = 'ongoing_profile_creation',
|
||||
Completed = 'completed',
|
||||
}
|
||||
@ -28,11 +28,6 @@ export const getOnboardingStatus = ({
|
||||
return OnboardingStatus.OngoingUserCreation;
|
||||
}
|
||||
|
||||
// if the user has not been fetched yet, we can't know the onboarding status
|
||||
if (!currentWorkspaceMember) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (
|
||||
isBillingEnabled &&
|
||||
currentWorkspace?.subscriptionStatus === 'incomplete'
|
||||
@ -44,9 +39,10 @@ export const getOnboardingStatus = ({
|
||||
return OnboardingStatus.Canceled;
|
||||
}
|
||||
|
||||
if (!currentWorkspace?.displayName) {
|
||||
return OnboardingStatus.OngoingWorkspaceCreation;
|
||||
if (!currentWorkspaceMember) {
|
||||
return OnboardingStatus.OngoingWorkspaceActivation;
|
||||
}
|
||||
|
||||
if (
|
||||
!currentWorkspaceMember.name.firstName ||
|
||||
!currentWorkspaceMember.name.lastName
|
||||
|
||||
Reference in New Issue
Block a user