forked from github/plane
refactor: onboarding workflow (#1286)
* chore: onboarding steps workflow verification * chore: onboarding variable update
This commit is contained in:
parent
4b25b7244b
commit
6f7b563712
@ -7,7 +7,7 @@ import { ICurrentUserResponse, IUser } from "types";
|
||||
import { MultiInput, PrimaryButton, SecondaryButton } from "components/ui";
|
||||
|
||||
type Props = {
|
||||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
||||
setStep: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
workspace: any;
|
||||
user: ICurrentUserResponse | undefined;
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ const defaultValues: Partial<IUser> = {
|
||||
|
||||
type Props = {
|
||||
user?: IUser;
|
||||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
||||
setStep: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
setUserRole: React.Dispatch<React.SetStateAction<string | null>>;
|
||||
};
|
||||
|
||||
|
@ -17,7 +17,7 @@ import { PrimaryButton } from "components/ui";
|
||||
import { getFirstCharacters, truncateText } from "helpers/string.helper";
|
||||
|
||||
type Props = {
|
||||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
||||
setStep: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
setWorkspace: React.Dispatch<React.SetStateAction<any>>;
|
||||
user: ICurrentUserResponse | undefined;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
// next imports
|
||||
import Router from "next/router";
|
||||
// services
|
||||
@ -24,7 +24,7 @@ import { ONBOARDING_CARDS } from "constants/workspace";
|
||||
import type { NextPage } from "next";
|
||||
|
||||
const Onboarding: NextPage = () => {
|
||||
const [step, setStep] = useState(1);
|
||||
const [step, setStep] = useState<null | number>(null);
|
||||
const [userRole, setUserRole] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
@ -32,15 +32,18 @@ const Onboarding: NextPage = () => {
|
||||
|
||||
const { user, isLoading: userLoading, mutateUser } = useUserAuth("onboarding");
|
||||
|
||||
useEffect(() => {
|
||||
if (user && step === null) {
|
||||
let currentStep: null | number = null;
|
||||
if (user?.role) currentStep = 2;
|
||||
if (user?.last_workspace_id) currentStep = 4;
|
||||
if (currentStep != null) setStep(() => currentStep);
|
||||
}
|
||||
}, [step, user]);
|
||||
|
||||
return (
|
||||
<DefaultLayout>
|
||||
{userLoading ? (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{isLoading ? (
|
||||
{userLoading || isLoading || step === null ? (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
@ -56,9 +59,7 @@ const Onboarding: NextPage = () => {
|
||||
) : step === 2 ? (
|
||||
<Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} />
|
||||
) : (
|
||||
step === 3 && (
|
||||
<InviteMembers setStep={setStep} workspace={workspace} user={user} />
|
||||
)
|
||||
step === 3 && <InviteMembers setStep={setStep} workspace={workspace} user={user} />
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
@ -108,8 +109,7 @@ const Onboarding: NextPage = () => {
|
||||
Router.push(`/${lastActiveWorkspace.slug}`);
|
||||
return;
|
||||
} else {
|
||||
const invitations =
|
||||
await workspaceService.userWorkspaceInvitations();
|
||||
const invitations = await workspaceService.userWorkspaceInvitations();
|
||||
if (invitations.length > 0) {
|
||||
Router.push(`/invitations`);
|
||||
return;
|
||||
@ -123,7 +123,7 @@ const Onboarding: NextPage = () => {
|
||||
setIsLoading(false);
|
||||
console.log(err);
|
||||
});
|
||||
} else setStep((prevData) => prevData + 1);
|
||||
} else setStep((prevData) => (prevData != null ? prevData + 1 : prevData));
|
||||
}}
|
||||
>
|
||||
{step === 4 || step === 8 ? "Get Started" : "Next"}
|
||||
@ -138,8 +138,6 @@ const Onboarding: NextPage = () => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</DefaultLayout>
|
||||
);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user