2023-11-29 13:37:33 +00:00
|
|
|
import React, { useState } from "react";
|
2023-12-06 08:52:59 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
// mobx store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
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
|
2023-12-06 08:52:59 +00:00
|
|
|
import { LatestFeatureBlock } from "components/common";
|
2023-11-29 13:37:33 +00:00
|
|
|
import {
|
|
|
|
EmailForm,
|
|
|
|
UniqueCodeForm,
|
|
|
|
PasswordForm,
|
|
|
|
SetPasswordLink,
|
|
|
|
OAuthOptions,
|
|
|
|
OptionalSetPasswordForm,
|
|
|
|
CreatePasswordForm,
|
2023-12-06 08:52:59 +00:00
|
|
|
SelfHostedSignInForm,
|
2023-11-29 13:37:33 +00:00
|
|
|
} 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-06 08:52:59 +00:00
|
|
|
USE_UNIQUE_CODE_FROM_PASSWORD = "USE_UNIQUE_CODE_FROM_PASSWORD",
|
2023-11-29 13:37:33 +00:00
|
|
|
}
|
|
|
|
|
2023-12-01 10:20:01 +00:00
|
|
|
const OAUTH_HIDDEN_STEPS = [ESignInSteps.OPTIONAL_SET_PASSWORD, ESignInSteps.CREATE_PASSWORD];
|
|
|
|
|
2023-12-06 08:52:59 +00:00
|
|
|
export const SignInRoot = observer(() => {
|
2023-11-29 13:37:33 +00:00
|
|
|
// states
|
|
|
|
const [signInStep, setSignInStep] = useState<ESignInSteps>(ESignInSteps.EMAIL);
|
|
|
|
const [email, setEmail] = useState("");
|
2023-12-06 08:52:59 +00:00
|
|
|
const [isOnboarded, setIsOnboarded] = useState(false);
|
2023-12-04 09:34:04 +00:00
|
|
|
// sign in redirection hook
|
|
|
|
const { handleRedirection } = useSignInRedirection();
|
2023-12-06 08:52:59 +00:00
|
|
|
// mobx store
|
|
|
|
const {
|
|
|
|
appConfig: { envConfig },
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
const isOAuthEnabled = envConfig && (envConfig.google_client_id || envConfig.github_client_id);
|
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-12-06 08:52:59 +00:00
|
|
|
{envConfig?.is_self_managed ? (
|
|
|
|
<SelfHostedSignInForm
|
2023-11-29 13:37:33 +00:00
|
|
|
email={email}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
2023-12-04 09:34:04 +00:00
|
|
|
handleSignInRedirection={handleRedirection}
|
2023-11-29 13:37:33 +00:00
|
|
|
/>
|
2023-12-06 08:52:59 +00:00
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{signInStep === ESignInSteps.EMAIL && (
|
|
|
|
<EmailForm
|
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.PASSWORD && (
|
|
|
|
<PasswordForm
|
|
|
|
email={email}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.SET_PASSWORD_LINK && (
|
|
|
|
<SetPasswordLink email={email} updateEmail={(newEmail) => setEmail(newEmail)} />
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.USE_UNIQUE_CODE_FROM_PASSWORD && (
|
|
|
|
<UniqueCodeForm
|
|
|
|
email={email}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
|
|
|
submitButtonLabel="Go to workspace"
|
|
|
|
showTermsAndConditions
|
|
|
|
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.UNIQUE_CODE && (
|
|
|
|
<UniqueCodeForm
|
|
|
|
email={email}
|
|
|
|
updateEmail={(newEmail) => setEmail(newEmail)}
|
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
|
|
|
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.OPTIONAL_SET_PASSWORD && (
|
|
|
|
<OptionalSetPasswordForm
|
|
|
|
email={email}
|
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
|
|
|
isOnboarded={isOnboarded}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{signInStep === ESignInSteps.CREATE_PASSWORD && (
|
|
|
|
<CreatePasswordForm
|
|
|
|
email={email}
|
|
|
|
handleStepChange={(step) => setSignInStep(step)}
|
|
|
|
handleSignInRedirection={handleRedirection}
|
|
|
|
isOnboarded={isOnboarded}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
2023-11-29 13:37:33 +00:00
|
|
|
)}
|
|
|
|
</div>
|
2023-12-06 08:52:59 +00:00
|
|
|
{isOAuthEnabled && !OAUTH_HIDDEN_STEPS.includes(signInStep) && (
|
|
|
|
<OAuthOptions handleSignInRedirection={handleRedirection} />
|
2023-11-29 13:37:33 +00:00
|
|
|
)}
|
2023-12-06 08:52:59 +00:00
|
|
|
<LatestFeatureBlock />
|
2023-11-29 13:37:33 +00:00
|
|
|
</>
|
|
|
|
);
|
2023-12-06 08:52:59 +00:00
|
|
|
});
|