forked from github/plane
promote: develop to stage release
promote: develop to stage release
This commit is contained in:
commit
8c9f4b9665
@ -7,7 +7,7 @@ import { ICurrentUserResponse, IUser } from "types";
|
|||||||
import { MultiInput, PrimaryButton, SecondaryButton } from "components/ui";
|
import { MultiInput, PrimaryButton, SecondaryButton } from "components/ui";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
setStep: React.Dispatch<React.SetStateAction<number | null>>;
|
||||||
workspace: any;
|
workspace: any;
|
||||||
user: ICurrentUserResponse | undefined;
|
user: ICurrentUserResponse | undefined;
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ const defaultValues: Partial<IUser> = {
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user?: IUser;
|
user?: IUser;
|
||||||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
setStep: React.Dispatch<React.SetStateAction<number | null>>;
|
||||||
setUserRole: React.Dispatch<React.SetStateAction<string | null>>;
|
setUserRole: React.Dispatch<React.SetStateAction<string | null>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import { PrimaryButton } from "components/ui";
|
|||||||
import { getFirstCharacters, truncateText } from "helpers/string.helper";
|
import { getFirstCharacters, truncateText } from "helpers/string.helper";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
setStep: React.Dispatch<React.SetStateAction<number>>;
|
setStep: React.Dispatch<React.SetStateAction<number | null>>;
|
||||||
setWorkspace: React.Dispatch<React.SetStateAction<any>>;
|
setWorkspace: React.Dispatch<React.SetStateAction<any>>;
|
||||||
user: ICurrentUserResponse | undefined;
|
user: ICurrentUserResponse | undefined;
|
||||||
};
|
};
|
||||||
|
@ -6,6 +6,7 @@ import { mutate } from "swr";
|
|||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
// services
|
// services
|
||||||
import workspaceService from "services/workspace.service";
|
import workspaceService from "services/workspace.service";
|
||||||
|
import userService from "services/user.service";
|
||||||
// hooks
|
// hooks
|
||||||
import useToast from "hooks/use-toast";
|
import useToast from "hooks/use-toast";
|
||||||
// ui
|
// ui
|
||||||
@ -77,7 +78,7 @@ export const CreateWorkspaceForm: React.FC<Props> = ({
|
|||||||
message: "Workspace created successfully.",
|
message: "Workspace created successfully.",
|
||||||
});
|
});
|
||||||
mutate<IWorkspace[]>(USER_WORKSPACES, (prevData) => [res, ...(prevData ?? [])]);
|
mutate<IWorkspace[]>(USER_WORKSPACES, (prevData) => [res, ...(prevData ?? [])]);
|
||||||
onSubmit(res);
|
updateLastWorkspaceIdUnderUSer(res);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -93,6 +94,18 @@ export const CreateWorkspaceForm: React.FC<Props> = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// update last_workspace_id
|
||||||
|
const updateLastWorkspaceIdUnderUSer = (workspace: any) => {
|
||||||
|
userService
|
||||||
|
.updateUser({ last_workspace_id: workspace.id })
|
||||||
|
.then((res) => {
|
||||||
|
onSubmit(workspace);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() => () => {
|
() => () => {
|
||||||
// when the component unmounts set the default values to whatever user typed in
|
// when the component unmounts set the default values to whatever user typed in
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
// next imports
|
// next imports
|
||||||
import Router from "next/router";
|
import Router from "next/router";
|
||||||
// services
|
// services
|
||||||
@ -24,7 +24,7 @@ import { ONBOARDING_CARDS } from "constants/workspace";
|
|||||||
import type { NextPage } from "next";
|
import type { NextPage } from "next";
|
||||||
|
|
||||||
const Onboarding: NextPage = () => {
|
const Onboarding: NextPage = () => {
|
||||||
const [step, setStep] = useState(1);
|
const [step, setStep] = useState<null | number>(null);
|
||||||
const [userRole, setUserRole] = useState<string | null>(null);
|
const [userRole, setUserRole] = useState<string | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
@ -32,15 +32,18 @@ const Onboarding: NextPage = () => {
|
|||||||
|
|
||||||
const { user, isLoading: userLoading, mutateUser } = useUserAuth("onboarding");
|
const { user, isLoading: userLoading, mutateUser } = useUserAuth("onboarding");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (user && step === null) {
|
||||||
|
let currentStep: number = 1;
|
||||||
|
if (user?.role) currentStep = 2;
|
||||||
|
if (user?.last_workspace_id) currentStep = 4;
|
||||||
|
setStep(() => currentStep);
|
||||||
|
}
|
||||||
|
}, [step, user]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DefaultLayout>
|
<DefaultLayout>
|
||||||
{userLoading ? (
|
{userLoading || isLoading || step === null ? (
|
||||||
<div className="grid h-screen place-items-center">
|
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{isLoading ? (
|
|
||||||
<div className="grid h-screen place-items-center">
|
<div className="grid h-screen place-items-center">
|
||||||
<Spinner />
|
<Spinner />
|
||||||
</div>
|
</div>
|
||||||
@ -56,9 +59,7 @@ const Onboarding: NextPage = () => {
|
|||||||
) : step === 2 ? (
|
) : step === 2 ? (
|
||||||
<Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} />
|
<Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} />
|
||||||
) : (
|
) : (
|
||||||
step === 3 && (
|
step === 3 && <InviteMembers setStep={setStep} workspace={workspace} user={user} />
|
||||||
<InviteMembers setStep={setStep} workspace={workspace} user={user} />
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@ -95,21 +96,11 @@ const Onboarding: NextPage = () => {
|
|||||||
) ?? userWorkspaces[0];
|
) ?? userWorkspaces[0];
|
||||||
|
|
||||||
if (lastActiveWorkspace) {
|
if (lastActiveWorkspace) {
|
||||||
userService
|
|
||||||
.updateUser({
|
|
||||||
last_workspace_id: lastActiveWorkspace.id,
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
mutateUser();
|
mutateUser();
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
Router.push(`/${lastActiveWorkspace.slug}`);
|
Router.push(`/${lastActiveWorkspace.slug}`);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const invitations =
|
const invitations = await workspaceService.userWorkspaceInvitations();
|
||||||
await workspaceService.userWorkspaceInvitations();
|
|
||||||
if (invitations.length > 0) {
|
if (invitations.length > 0) {
|
||||||
Router.push(`/invitations`);
|
Router.push(`/invitations`);
|
||||||
return;
|
return;
|
||||||
@ -123,7 +114,7 @@ const Onboarding: NextPage = () => {
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
} else setStep((prevData) => prevData + 1);
|
} else setStep((prevData) => (prevData != null ? prevData + 1 : prevData));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{step === 4 || step === 8 ? "Get Started" : "Next"}
|
{step === 4 || step === 8 ? "Get Started" : "Next"}
|
||||||
@ -138,8 +129,6 @@ const Onboarding: NextPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</DefaultLayout>
|
</DefaultLayout>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user