feat(auth): add registration and verification browser flow
This commit is contained in:
1 parent
391af7a1ef
commit
b2322bc178
41 files changed
+2144
-81
No files matched your search
@@ -0,0 +1,68 @@
|
||||
import { useState } from "react";
|
||||
import { RegisterForm, type RegistrationDraft } from "../../../features/register-account";
|
||||
import { ResendVerificationForm } from "../../../features/resend-email-verification";
|
||||
import { Button, Page, Section, TextLink } from "../../../shared/ui";
|
||||
import { paths } from "../../../shared/config";
|
||||
import {
|
||||
clearRegistrationContext,
|
||||
readRegistrationContext,
|
||||
writeRegistrationContext,
|
||||
type RegistrationContext,
|
||||
} from "../model/registration-context";
|
||||
|
||||
function scenarioLabel(scenario: RegistrationDraft["scenario"]): string {
|
||||
return scenario === "employer" ? "работодатель" : "кандидат";
|
||||
}
|
||||
|
||||
export function RegisterPage() {
|
||||
const [context, setContext] = useState<RegistrationContext>(readRegistrationContext);
|
||||
|
||||
function saveDraft(draft: RegistrationDraft) {
|
||||
const next = { ...draft, accepted: false };
|
||||
setContext(next);
|
||||
writeRegistrationContext(next);
|
||||
}
|
||||
|
||||
function markAccepted(draft: RegistrationDraft) {
|
||||
const next = { ...draft, accepted: true };
|
||||
setContext(next);
|
||||
writeRegistrationContext(next);
|
||||
}
|
||||
|
||||
function startAgain() {
|
||||
clearRegistrationContext();
|
||||
setContext({ email: "", scenario: "", accepted: false });
|
||||
}
|
||||
|
||||
return (
|
||||
<Page
|
||||
title="Регистрация"
|
||||
lead="Создайте аккаунт и выберите, как вы будете пользоваться платформой."
|
||||
>
|
||||
{context.accepted ? (
|
||||
<div>
|
||||
<Section title="Запрос принят">
|
||||
<p role="status" aria-live="polite">
|
||||
Если для этого адреса требуется подтверждение, письмо будет отправлено. Выбранный
|
||||
сценарий: {scenarioLabel(context.scenario)}.
|
||||
</p>
|
||||
<ResendVerificationForm initialEmail={context.email} />
|
||||
<TextLink to={paths.login}>Перейти ко входу</TextLink>
|
||||
<Button type="button" variant="quiet" onClick={startAgain}>
|
||||
Начать другую регистрацию
|
||||
</Button>
|
||||
</Section>
|
||||
</div>
|
||||
) : (
|
||||
<Section title="Данные аккаунта">
|
||||
<RegisterForm
|
||||
initialEmail={context.email}
|
||||
initialScenario={context.scenario}
|
||||
onDraftChange={saveDraft}
|
||||
onAccepted={markAccepted}
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user