69 lines
2.4 KiB
TypeScript
69 lines
2.4 KiB
TypeScript
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>
|
|
);
|
|
}
|