fix: assignee dropdown, sign in button, and onboarding flicker fix (#1242)

This commit is contained in:
Anmol Singh Bhatia 2023-06-07 17:45:57 +05:30 committed by GitHub
parent 3d5fcbd4ce
commit 78c1a64690
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 112 deletions

View File

@ -21,6 +21,7 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
const [codeResent, setCodeResent] = useState(false); const [codeResent, setCodeResent] = useState(false);
const [isCodeResending, setIsCodeResending] = useState(false); const [isCodeResending, setIsCodeResending] = useState(false);
const [errorResendingCode, setErrorResendingCode] = useState(false); const [errorResendingCode, setErrorResendingCode] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const { setToastAlert } = useToast(); const { setToastAlert } = useToast();
const { timer: resendCodeTimer, setTimer: setResendCodeTimer } = useTimer(); const { timer: resendCodeTimer, setTimer: setResendCodeTimer } = useTimer();
@ -64,26 +65,19 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
}; };
const handleSignin = async (formData: EmailCodeFormValues) => { const handleSignin = async (formData: EmailCodeFormValues) => {
await authenticationService setIsLoading(true);
.magicSignIn(formData) await authenticationService.magicSignIn(formData).catch((error) => {
.then(() => { setIsLoading(false);
setToastAlert({ setToastAlert({
title: "Success", title: "Oops!",
type: "success", type: "error",
message: "Successfully logged in!", message: error?.response?.data?.error ?? "Enter the correct code to sign 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,
});
}); });
setError("token" as keyof EmailCodeFormValues, {
type: "manual",
message: error.error,
});
});
}; };
const emailOld = getValues("email"); const emailOld = getValues("email");
@ -200,9 +194,9 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
size="md" size="md"
onClick={handleSubmit(handleSignin)} onClick={handleSubmit(handleSignin)}
disabled={!isValid && isDirty} disabled={!isValid && isDirty}
loading={isSubmitting} loading={isLoading}
> >
{isSubmitting ? "Signing in..." : "Sign in"} {isLoading ? "Signing in..." : "Sign in"}
</PrimaryButton> </PrimaryButton>
) : ( ) : (
<PrimaryButton <PrimaryButton

View File

@ -126,7 +126,7 @@ export const ViewAssigneeSelect: React.FC<Props> = ({
position={position} position={position}
disabled={isNotAllowed} disabled={isNotAllowed}
selfPositioned={selfPositioned} selfPositioned={selfPositioned}
dropdownWidth="w-full min-w-[8rem]" dropdownWidth="w-full min-w-[12rem]"
/> />
); );
}; };

View File

@ -22,7 +22,7 @@ import {
Workspace, Workspace,
} from "components/onboarding"; } from "components/onboarding";
// ui // ui
import { PrimaryButton } from "components/ui"; import { PrimaryButton, Spinner } from "components/ui";
// constant // constant
import { ONBOARDING_CARDS } from "constants/workspace"; import { ONBOARDING_CARDS } from "constants/workspace";
// types // types
@ -34,6 +34,7 @@ import { CURRENT_USER } from "constants/fetch-keys";
const Onboarding: NextPage = () => { const Onboarding: NextPage = () => {
const [step, setStep] = useState(1); const [step, setStep] = useState(1);
const [userRole, setUserRole] = useState<string | null>(null); const [userRole, setUserRole] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [workspace, setWorkspace] = useState(); const [workspace, setWorkspace] = useState();
@ -44,107 +45,116 @@ const Onboarding: NextPage = () => {
return ( return (
<UserAuthorizationLayout> <UserAuthorizationLayout>
<DefaultLayout> <DefaultLayout>
<div className="relative grid h-full place-items-center p-5"> {isLoading ? (
{step <= 3 ? ( <div className="grid h-screen place-items-center">
<div className="h-full flex flex-col justify-center w-full py-4"> <Spinner />
<div className="mb-7 flex items-center justify-center text-center"> </div>
<OnboardingLogo className="h-12 w-48 fill-current text-brand-base" /> ) : (
</div> <div className="relative grid h-full place-items-center p-5">
{step === 1 ? ( {step <= 3 ? (
<UserDetails user={user} setStep={setStep} setUserRole={setUserRole} /> <div className="h-full flex flex-col justify-center w-full py-4">
) : step === 2 ? ( <div className="mb-7 flex items-center justify-center text-center">
<Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} /> <OnboardingLogo className="h-12 w-48 fill-current text-brand-base" />
) : ( </div>
<InviteMembers setStep={setStep} workspace={workspace} user={user} /> {step === 1 ? (
)} <UserDetails user={user} setStep={setStep} setUserRole={setUserRole} />
</div> ) : step === 2 ? (
) : ( <Workspace setStep={setStep} setWorkspace={setWorkspace} user={user} />
<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} /> <InviteMembers setStep={setStep} workspace={workspace} user={user} />
)} )}
<div className="mx-auto flex h-1/4 items-end lg:w-1/2"> </div>
<PrimaryButton ) : (
type="button" <div className="flex w-full max-w-2xl flex-col gap-12">
className="flex w-full items-center justify-center text-center " <div className="flex flex-col items-center justify-center gap-7 rounded-[10px] bg-brand-base pb-7 text-center shadow-md">
size="md" {step === 4 ? (
onClick={() => { <OnboardingCard data={ONBOARDING_CARDS.welcome} />
if (step === 8) { ) : step === 5 ? (
userService <OnboardingCard data={ONBOARDING_CARDS.issue} gradient />
.updateUserOnBoard({ userRole }, user) ) : step === 6 ? (
.then(async () => { <OnboardingCard data={ONBOARDING_CARDS.cycle} gradient />
mutate<ICurrentUserResponse>( ) : step === 7 ? (
CURRENT_USER, <OnboardingCard data={ONBOARDING_CARDS.module} gradient />
(prevData) => { ) : (
if (!prevData) return prevData; <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 { return {
...prevData, ...prevData,
user: { user: {
...prevData.user, ...prevData.user,
is_onboarded: true, is_onboarded: true,
}, },
}; };
}, },
false false
); );
const userWorkspaces = await workspaceService.userWorkspaces(); const userWorkspaces = await workspaceService.userWorkspaces();
const lastActiveWorkspace = const lastActiveWorkspace =
userWorkspaces.find( userWorkspaces.find(
(workspace) => workspace.id === user?.last_workspace_id (workspace) => workspace.id === user?.last_workspace_id
) ?? userWorkspaces[0]; ) ?? userWorkspaces[0];
if (lastActiveWorkspace) { if (lastActiveWorkspace) {
userService userService
.updateUser({ .updateUser({
last_workspace_id: lastActiveWorkspace.id, last_workspace_id: lastActiveWorkspace.id,
}) })
.then((res) => { .then((res) => {
mutateUser(); mutateUser();
}) })
.catch((err) => { .catch((err) => {
console.log(err); console.log(err);
}); });
Router.push(`/${lastActiveWorkspace.slug}`); Router.push(`/${lastActiveWorkspace.slug}`);
return;
} else {
const invitations = await workspaceService.userWorkspaceInvitations();
if (invitations.length > 0) {
Router.push(`/invitations`);
return; return;
} else { } else {
Router.push(`/create-workspace`); const invitations =
return; await workspaceService.userWorkspaceInvitations();
if (invitations.length > 0) {
Router.push(`/invitations`);
return;
} else {
Router.push(`/create-workspace`);
return;
}
} }
} })
}) .catch((err) => {
.catch((err) => { setIsLoading(false);
console.log(err); console.log(err);
}); });
} else setStep((prevData) => prevData + 1); } else setStep((prevData) => prevData + 1);
}} }}
> >
{step === 4 || step === 8 ? "Get Started" : "Next"} {step === 4 || step === 8 ? "Get Started" : "Next"}
</PrimaryButton> </PrimaryButton>
</div>
</div> </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>
)}
<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>
</div> )}
</DefaultLayout> </DefaultLayout>
</UserAuthorizationLayout> </UserAuthorizationLayout>
); );