forked from github/plane
fix: assignee dropdown, sign in button, and onboarding flicker fix (#1242)
This commit is contained in:
parent
3d5fcbd4ce
commit
78c1a64690
@ -21,6 +21,7 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
|
||||
const [codeResent, setCodeResent] = useState(false);
|
||||
const [isCodeResending, setIsCodeResending] = useState(false);
|
||||
const [errorResendingCode, setErrorResendingCode] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const { setToastAlert } = useToast();
|
||||
const { timer: resendCodeTimer, setTimer: setResendCodeTimer } = useTimer();
|
||||
@ -64,26 +65,19 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
|
||||
};
|
||||
|
||||
const handleSignin = async (formData: EmailCodeFormValues) => {
|
||||
await authenticationService
|
||||
.magicSignIn(formData)
|
||||
.then(() => {
|
||||
setToastAlert({
|
||||
title: "Success",
|
||||
type: "success",
|
||||
message: "Successfully logged in!",
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
setToastAlert({
|
||||
title: "Oops!",
|
||||
type: "error",
|
||||
message: error?.response?.data?.error ?? "Enter the correct code to sign in",
|
||||
});
|
||||
setError("token" as keyof EmailCodeFormValues, {
|
||||
type: "manual",
|
||||
message: error.error,
|
||||
});
|
||||
setIsLoading(true);
|
||||
await authenticationService.magicSignIn(formData).catch((error) => {
|
||||
setIsLoading(false);
|
||||
setToastAlert({
|
||||
title: "Oops!",
|
||||
type: "error",
|
||||
message: error?.response?.data?.error ?? "Enter the correct code to sign in",
|
||||
});
|
||||
setError("token" as keyof EmailCodeFormValues, {
|
||||
type: "manual",
|
||||
message: error.error,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const emailOld = getValues("email");
|
||||
@ -200,9 +194,9 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
|
||||
size="md"
|
||||
onClick={handleSubmit(handleSignin)}
|
||||
disabled={!isValid && isDirty}
|
||||
loading={isSubmitting}
|
||||
loading={isLoading}
|
||||
>
|
||||
{isSubmitting ? "Signing in..." : "Sign in"}
|
||||
{isLoading ? "Signing in..." : "Sign in"}
|
||||
</PrimaryButton>
|
||||
) : (
|
||||
<PrimaryButton
|
||||
|
@ -126,7 +126,7 @@ export const ViewAssigneeSelect: React.FC<Props> = ({
|
||||
position={position}
|
||||
disabled={isNotAllowed}
|
||||
selfPositioned={selfPositioned}
|
||||
dropdownWidth="w-full min-w-[8rem]"
|
||||
dropdownWidth="w-full min-w-[12rem]"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ import {
|
||||
Workspace,
|
||||
} from "components/onboarding";
|
||||
// ui
|
||||
import { PrimaryButton } from "components/ui";
|
||||
import { PrimaryButton, Spinner } from "components/ui";
|
||||
// constant
|
||||
import { ONBOARDING_CARDS } from "constants/workspace";
|
||||
// types
|
||||
@ -34,6 +34,7 @@ import { CURRENT_USER } from "constants/fetch-keys";
|
||||
const Onboarding: NextPage = () => {
|
||||
const [step, setStep] = useState(1);
|
||||
const [userRole, setUserRole] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [workspace, setWorkspace] = useState();
|
||||
|
||||
@ -44,107 +45,116 @@ const Onboarding: NextPage = () => {
|
||||
return (
|
||||
<UserAuthorizationLayout>
|
||||
<DefaultLayout>
|
||||
<div className="relative grid h-full place-items-center p-5">
|
||||
{step <= 3 ? (
|
||||
<div className="h-full flex flex-col justify-center w-full py-4">
|
||||
<div className="mb-7 flex items-center justify-center text-center">
|
||||
<OnboardingLogo className="h-12 w-48 fill-current text-brand-base" />
|
||||
</div>
|
||||
{step === 1 ? (
|
||||
<UserDetails user={user} setStep={setStep} setUserRole={setUserRole} />
|
||||
) : step === 2 ? (
|
||||
<Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} />
|
||||
) : (
|
||||
<InviteMembers setStep={setStep} workspace={workspace} user={user} />
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full max-w-2xl flex-col gap-12">
|
||||
<div className="flex flex-col items-center justify-center gap-7 rounded-[10px] bg-brand-base pb-7 text-center shadow-md">
|
||||
{step === 4 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.welcome} />
|
||||
) : step === 5 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.issue} gradient />
|
||||
) : step === 6 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.cycle} gradient />
|
||||
) : step === 7 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.module} gradient />
|
||||
{isLoading ? (
|
||||
<div className="grid h-screen place-items-center">
|
||||
<Spinner />
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative grid h-full place-items-center p-5">
|
||||
{step <= 3 ? (
|
||||
<div className="h-full flex flex-col justify-center w-full py-4">
|
||||
<div className="mb-7 flex items-center justify-center text-center">
|
||||
<OnboardingLogo className="h-12 w-48 fill-current text-brand-base" />
|
||||
</div>
|
||||
{step === 1 ? (
|
||||
<UserDetails user={user} setStep={setStep} setUserRole={setUserRole} />
|
||||
) : step === 2 ? (
|
||||
<Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} />
|
||||
) : (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.commandMenu} />
|
||||
<InviteMembers setStep={setStep} workspace={workspace} user={user} />
|
||||
)}
|
||||
<div className="mx-auto flex h-1/4 items-end lg:w-1/2">
|
||||
<PrimaryButton
|
||||
type="button"
|
||||
className="flex w-full items-center justify-center text-center "
|
||||
size="md"
|
||||
onClick={() => {
|
||||
if (step === 8) {
|
||||
userService
|
||||
.updateUserOnBoard({ userRole }, user)
|
||||
.then(async () => {
|
||||
mutate<ICurrentUserResponse>(
|
||||
CURRENT_USER,
|
||||
(prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex w-full max-w-2xl flex-col gap-12">
|
||||
<div className="flex flex-col items-center justify-center gap-7 rounded-[10px] bg-brand-base pb-7 text-center shadow-md">
|
||||
{step === 4 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.welcome} />
|
||||
) : step === 5 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.issue} gradient />
|
||||
) : step === 6 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.cycle} gradient />
|
||||
) : step === 7 ? (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.module} gradient />
|
||||
) : (
|
||||
<OnboardingCard data={ONBOARDING_CARDS.commandMenu} />
|
||||
)}
|
||||
<div className="mx-auto flex h-1/4 items-end lg:w-1/2">
|
||||
<PrimaryButton
|
||||
type="button"
|
||||
className="flex w-full items-center justify-center text-center "
|
||||
size="md"
|
||||
onClick={() => {
|
||||
if (step === 8) {
|
||||
setIsLoading(true);
|
||||
userService
|
||||
.updateUserOnBoard({ userRole }, user)
|
||||
.then(async () => {
|
||||
mutate<ICurrentUserResponse>(
|
||||
CURRENT_USER,
|
||||
(prevData) => {
|
||||
if (!prevData) return prevData;
|
||||
|
||||
return {
|
||||
...prevData,
|
||||
user: {
|
||||
...prevData.user,
|
||||
is_onboarded: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
const userWorkspaces = await workspaceService.userWorkspaces();
|
||||
return {
|
||||
...prevData,
|
||||
user: {
|
||||
...prevData.user,
|
||||
is_onboarded: true,
|
||||
},
|
||||
};
|
||||
},
|
||||
false
|
||||
);
|
||||
const userWorkspaces = await workspaceService.userWorkspaces();
|
||||
|
||||
const lastActiveWorkspace =
|
||||
userWorkspaces.find(
|
||||
(workspace) => workspace.id === user?.last_workspace_id
|
||||
) ?? userWorkspaces[0];
|
||||
const lastActiveWorkspace =
|
||||
userWorkspaces.find(
|
||||
(workspace) => workspace.id === user?.last_workspace_id
|
||||
) ?? userWorkspaces[0];
|
||||
|
||||
if (lastActiveWorkspace) {
|
||||
userService
|
||||
.updateUser({
|
||||
last_workspace_id: lastActiveWorkspace.id,
|
||||
})
|
||||
.then((res) => {
|
||||
mutateUser();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
Router.push(`/${lastActiveWorkspace.slug}`);
|
||||
return;
|
||||
} else {
|
||||
const invitations = await workspaceService.userWorkspaceInvitations();
|
||||
if (invitations.length > 0) {
|
||||
Router.push(`/invitations`);
|
||||
if (lastActiveWorkspace) {
|
||||
userService
|
||||
.updateUser({
|
||||
last_workspace_id: lastActiveWorkspace.id,
|
||||
})
|
||||
.then((res) => {
|
||||
mutateUser();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
Router.push(`/${lastActiveWorkspace.slug}`);
|
||||
return;
|
||||
} else {
|
||||
Router.push(`/create-workspace`);
|
||||
return;
|
||||
const invitations =
|
||||
await workspaceService.userWorkspaceInvitations();
|
||||
if (invitations.length > 0) {
|
||||
Router.push(`/invitations`);
|
||||
return;
|
||||
} else {
|
||||
Router.push(`/create-workspace`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} else setStep((prevData) => prevData + 1);
|
||||
}}
|
||||
>
|
||||
{step === 4 || step === 8 ? "Get Started" : "Next"}
|
||||
</PrimaryButton>
|
||||
})
|
||||
.catch((err) => {
|
||||
setIsLoading(false);
|
||||
console.log(err);
|
||||
});
|
||||
} else setStep((prevData) => prevData + 1);
|
||||
}}
|
||||
>
|
||||
{step === 4 || step === 8 ? "Get Started" : "Next"}
|
||||
</PrimaryButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute flex flex-col gap-1 justify-center items-start left-5 top-5">
|
||||
<span className="text-xs text-brand-secondary">Logged in:</span>
|
||||
<span className="text-sm text-brand-base">{user?.email}</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="absolute flex flex-col gap-1 justify-center items-start left-5 top-5">
|
||||
<span className="text-xs text-brand-secondary">Logged in:</span>
|
||||
<span className="text-sm text-brand-base">{user?.email}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</DefaultLayout>
|
||||
</UserAuthorizationLayout>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user