446919bc72
## Remove onboarding flashes Tested: - sign in with credentials - sign in with social oAuth - sign up with credentials - multidomain - single domain - reset password No more flashes, and code logic simplified! ## Close all dropdowns on CommandMenu close Before: https://github.com/user-attachments/assets/244ff935-3d40-47d5-a097-12d4cc3810dd After: https://github.com/user-attachments/assets/1de692f8-5032-404a-be74-025ebca67138 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { useRecoilCallback, useRecoilValue } from 'recoil';
|
|
|
|
import { CurrentUser, currentUserState } from '@/auth/states/currentUserState';
|
|
import {
|
|
CurrentWorkspace,
|
|
currentWorkspaceState,
|
|
} from '@/auth/states/currentWorkspaceState';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { OnboardingStatus } from '~/generated/graphql';
|
|
|
|
const getNextOnboardingStatus = (
|
|
currentUser: CurrentUser | null,
|
|
currentWorkspace: CurrentWorkspace | null,
|
|
) => {
|
|
if (currentUser?.onboardingStatus === OnboardingStatus.WORKSPACE_ACTIVATION) {
|
|
return OnboardingStatus.PROFILE_CREATION;
|
|
}
|
|
|
|
if (currentUser?.onboardingStatus === OnboardingStatus.PROFILE_CREATION) {
|
|
return OnboardingStatus.SYNC_EMAIL;
|
|
}
|
|
if (
|
|
currentUser?.onboardingStatus === OnboardingStatus.SYNC_EMAIL &&
|
|
currentWorkspace?.workspaceMembersCount === 1
|
|
) {
|
|
return OnboardingStatus.INVITE_TEAM;
|
|
}
|
|
return OnboardingStatus.COMPLETED;
|
|
};
|
|
|
|
export const useSetNextOnboardingStatus = () => {
|
|
const currentUser = useRecoilValue(currentUserState);
|
|
const currentWorkspace = useRecoilValue(currentWorkspaceState);
|
|
|
|
return useRecoilCallback(
|
|
({ set }) =>
|
|
() => {
|
|
const nextOnboardingStatus = getNextOnboardingStatus(
|
|
currentUser,
|
|
currentWorkspace,
|
|
);
|
|
set(currentUserState, (current) => {
|
|
if (isDefined(current)) {
|
|
return {
|
|
...current,
|
|
onboardingStatus: nextOnboardingStatus,
|
|
};
|
|
}
|
|
return current;
|
|
});
|
|
},
|
|
[currentWorkspace, currentUser],
|
|
);
|
|
};
|