[WEB-1565] fix: onboarding steps logic. (#4779)

This commit is contained in:
Prateek Shourya 2024-06-12 15:42:05 +05:30 committed by GitHub
parent eb34dcaaaa
commit 28fc8ccd0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,14 +37,14 @@ const OnboardingPage = observer(() => {
const router = useRouter();
// store hooks
const { captureEvent } = useEventTracker();
const { data: user, updateCurrentUser } = useUser();
const { isLoading: userLoader, data: user, updateCurrentUser } = useUser();
const { data: profile, updateUserOnBoard, updateUserProfile } = useUserProfile();
const { workspaces, fetchWorkspaces } = useWorkspace();
// computed values
const workspacesList = Object.values(workspaces ?? {});
// fetching workspaces list
useSWR(USER_WORKSPACES_LIST, () => fetchWorkspaces(), {
const { isLoading: workspaceListLoader } = useSWR(USER_WORKSPACES_LIST, () => fetchWorkspaces(), {
shouldRetryOnError: false,
});
// fetching user workspace invitations
@ -99,18 +99,21 @@ const OnboardingPage = observer(() => {
};
useEffect(() => {
// If user is already invited to a workspace, only show profile setup steps.
if (workspacesList && workspacesList?.length > 0) {
// If password is auto set then show two different steps for profile setup, else merge them.
if (user?.is_password_autoset) setTotalSteps(2);
else setTotalSteps(1);
} else {
// If password is auto set then total steps will increase to 4 due to extra step at profile setup stage.
if (user?.is_password_autoset) setTotalSteps(4);
else setTotalSteps(3);
// Never update the total steps if it's already set.
if (!totalSteps && userLoader === false && workspaceListLoader === false) {
// If user is already invited to a workspace, only show profile setup steps.
if (workspacesList && workspacesList?.length > 0) {
// If password is auto set then show two different steps for profile setup, else merge them.
if (user?.is_password_autoset) setTotalSteps(2);
else setTotalSteps(1);
} else {
// If password is auto set then total steps will increase to 4 due to extra step at profile setup stage.
if (user?.is_password_autoset) setTotalSteps(4);
else setTotalSteps(3);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [userLoader, workspaceListLoader]);
useEffect(() => {
const handleStepChange = async () => {