[WEB-1929] chore: improve finishOnboarding logic to handle case where user profile setup is done and user already has a workspace. (#5105)

This commit is contained in:
Prateek Shourya
2024-07-12 17:17:58 +05:30
committed by GitHub
parent f06095f120
commit ce89c7dcff
2 changed files with 22 additions and 9 deletions

View File

@@ -47,9 +47,12 @@ const OnboardingPage = observer(() => {
user?.id && fetchWorkspaces();
});
// fetching user workspace invitations
const { isLoading: invitationsLoader, data: invitations } = useSWR("USER_WORKSPACE_INVITATIONS_LIST", () => {
if (user?.id) return workspaceService.userWorkspaceInvitations();
});
const { isLoading: invitationsLoader, data: invitations } = useSWR(
`USER_WORKSPACE_INVITATIONS_LIST_${user?.id}`,
() => {
if (user?.id) return workspaceService.userWorkspaceInvitations();
}
);
// handle step change
const stepChange = async (steps: Partial<TOnboardingSteps>) => {
if (!user) return;
@@ -103,6 +106,16 @@ const OnboardingPage = observer(() => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userLoader, workspaceListLoader]);
// If the user completes the profile setup and has workspaces (through invitations), then finish the onboarding.
useEffect(() => {
if (userLoader === false && profile && workspaceListLoader === false) {
const onboardingStep = profile.onboarding_step;
if (onboardingStep.profile_complete && !onboardingStep.workspace_create && workspacesList.length > 0)
finishOnboarding();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [userLoader, profile, workspaceListLoader]);
useEffect(() => {
const handleStepChange = async () => {
if (!user) return;
@@ -111,10 +124,10 @@ const OnboardingPage = observer(() => {
if (!onboardingStep.profile_complete) setStep(EOnboardingSteps.PROFILE_SETUP);
// For Invited Users, they will skip all other steps.
if (totalSteps && totalSteps <= 2) return;
if (onboardingStep.profile_complete && !(onboardingStep.workspace_join || onboardingStep.workspace_create)) {
if (
onboardingStep.profile_complete &&
!(onboardingStep.workspace_join || onboardingStep.workspace_create || workspacesList?.length > 0)
) {
setStep(EOnboardingSteps.WORKSPACE_CREATE_OR_JOIN);
}

View File

@@ -35,7 +35,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
const { isLoading: isUserLoading, data: currentUser, fetchCurrentUser } = useUser();
const { data: currentUserProfile } = useUserProfile();
const { data: currentUserSettings } = useUserSettings();
const { workspaces } = useWorkspace();
const { loader: workspacesLoader, workspaces } = useWorkspace();
const { isLoading: isUserSWRLoading } = useSWR("USER_INFORMATION", async () => await fetchCurrentUser(), {
revalidateOnFocus: false,
@@ -73,7 +73,7 @@ export const AuthenticationWrapper: FC<TAuthenticationWrapper> = observer((props
return redirectionRoute;
};
if ((isUserSWRLoading || isUserLoading) && !currentUser?.id)
if ((isUserSWRLoading || isUserLoading || workspacesLoader) && !currentUser?.id)
return (
<div className="relative flex h-screen w-full items-center justify-center">
<LogoSpinner />