2023-11-29 13:37:33 +00:00
|
|
|
import React, { useState } from "react";
|
2023-12-04 09:34:04 +00:00
|
|
|
// hooks
|
|
|
|
import useSignInRedirection from "hooks/use-sign-in-redirection";
|
2023-11-29 13:37:33 +00:00
|
|
|
// components
|
|
|
|
import {
|
|
|
|
EmailForm,
|
|
|
|
UniqueCodeForm,
|
|
|
|
PasswordForm,
|
|
|
|
SetPasswordLink,
|
|
|
|
OAuthOptions,
|
|
|
|
OptionalSetPasswordForm,
|
|
|
|
CreatePasswordForm,
|
|
|
|
} from "components/account";
|
|
|
|
|
|
|
|
export enum ESignInSteps {
|
|
|
|
EMAIL = "EMAIL",
|
|
|
|
PASSWORD = "PASSWORD",
|
|
|
|
SET_PASSWORD_LINK = "SET_PASSWORD_LINK",
|
|
|
|
UNIQUE_CODE = "UNIQUE_CODE",
|
|
|
|
OPTIONAL_SET_PASSWORD = "OPTIONAL_SET_PASSWORD",
|
|
|
|
CREATE_PASSWORD = "CREATE_PASSWORD",
|
|
|
|
}
|
|
|
|
|
2023-12-01 10:20:01 +00:00
|
|
|
const OAUTH_HIDDEN_STEPS = [ESignInSteps.OPTIONAL_SET_PASSWORD, ESignInSteps.CREATE_PASSWORD];
|
|
|
|
|
2023-12-04 09:34:04 +00:00
|
|
|
export const SignInRoot = () => {
|
2023-11-29 13:37:33 +00:00
|
|
|
// states
|
|
|
|
const [signInStep, setSignInStep] = useState<ESignInSteps>(ESignInSteps.EMAIL);
|
|
|
|
const [email, setEmail] = useState("");
|
2023-12-04 09:34:04 +00:00
|
|
|
// sign in redirection hook
|
|
|
|
const { handleRedirection } = useSignInRedirection();
|
2023-11-29 13:37:33 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-11-29 15:03:08 +00:00
|
|
|
<div className="mx-auto flex flex-col">
|
2023-11-29 13:37:33 +00:00
|
|
|
{signInStep === ESignInSteps.EMAIL && (
|
2023-12-04 09:34:04 +00:00
|
|
|
<EmailForm handleStepChange={(step) => setSignInStep(step)} updateEmail={(newEmail) => setEmail(newEmail)} />
|
2023-11-29 13:37:33 +00:00
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.PASSWORD && (
|
|
|
|
<PasswordForm
|
|
|
|
email={email}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
2023-12-04 09:34:04 +00:00
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
2023-11-29 13:37:33 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.SET_PASSWORD_LINK && (
|
|
|
|
<SetPasswordLink email={email} updateEmail={(newEmail) => setEmail(newEmail)} />
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.UNIQUE_CODE && (
|
|
|
|
<UniqueCodeForm
|
|
|
|
email={email}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
2023-12-04 09:34:04 +00:00
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
2023-11-29 13:37:33 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.OPTIONAL_SET_PASSWORD && (
|
|
|
|
<OptionalSetPasswordForm
|
|
|
|
email={email}
|
2023-12-04 09:34:04 +00:00
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
2023-11-29 13:37:33 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.CREATE_PASSWORD && (
|
|
|
|
<CreatePasswordForm
|
|
|
|
email={email}
|
2023-12-04 09:34:04 +00:00
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
2023-11-29 13:37:33 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-12-01 10:20:01 +00:00
|
|
|
{!OAUTH_HIDDEN_STEPS.includes(signInStep) && (
|
2023-11-29 13:37:33 +00:00
|
|
|
<OAuthOptions
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
2023-12-04 09:34:04 +00:00
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
2023-11-29 13:37:33 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|