feat(candidate): add the candidate home, results and result history screens

This commit is contained in:
shira committed 2026-10-09 01:24:45 +03:00
1 parent 8277133712
commit 4761508f13
52 files changed
+5334 -81

No files matched your search

@@ -0,0 +1 @@
export { CandidateNextStep } from "./ui/candidate-next-step";
@@ -0,0 +1,126 @@
.root {
display: grid;
gap: var(--space-6);
}
/* The next step is the one dominant block of the home screen. */
.card {
display: grid;
gap: var(--space-3);
padding: var(--space-5);
border: var(--line-strong) solid var(--color-border-strong);
border-radius: var(--radius-l);
background: var(--color-surface);
}
.card-eyebrow {
color: var(--color-accent);
font-size: var(--font-size-xs);
font-weight: var(--font-weight-bold);
letter-spacing: var(--letter-spacing-label);
text-transform: uppercase;
}
.card-title {
font-size: var(--font-size-xl);
font-weight: var(--font-weight-bold);
line-height: var(--line-height-snug);
}
.card-text {
max-width: 44rem;
font-size: var(--font-size-m);
line-height: var(--line-height-body);
}
.actions {
display: flex;
flex-wrap: wrap;
gap: var(--space-3);
padding-top: var(--space-2);
}
.note {
max-width: 44rem;
color: var(--color-text-secondary);
font-size: var(--font-size-s);
line-height: var(--line-height-body);
}
.columns {
display: grid;
gap: var(--space-6);
}
@media (width >= 64rem) {
.columns {
grid-template-columns: repeat(2, minmax(0, 1fr));
align-items: start;
}
}
.standings,
.links {
display: grid;
gap: var(--space-3);
margin: 0;
padding: 0;
list-style: none;
}
.standing,
.link {
min-width: 0;
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-m);
background: var(--color-surface);
}
.standing-title {
margin-bottom: var(--space-3);
font-size: var(--font-size-m);
font-weight: var(--font-weight-bold);
}
.facts {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: var(--space-1) var(--space-4);
margin: 0;
}
@media (width >= 48rem) {
.facts {
grid-template-columns: minmax(9rem, auto) minmax(0, 1fr);
align-items: center;
}
}
.facts dt {
color: var(--color-text-secondary);
font-size: var(--font-size-s);
}
.facts dd {
min-width: 0;
margin: 0 0 var(--space-2);
overflow-wrap: anywhere;
}
.link {
display: flex;
flex-wrap: wrap;
gap: var(--space-2) var(--space-4);
align-items: center;
justify-content: space-between;
}
.link-label {
font-weight: var(--font-weight-bold);
}
.link-status {
color: var(--color-text-secondary);
font-size: var(--font-size-s);
}
@@ -0,0 +1,300 @@
import type { ReactNode } from "react";
import {
onboardingStepLabels,
useCandidateJourney,
type CandidateJourney,
type CandidateNextStep as NextStep,
type SpecializationStanding,
} from "../../../entities/candidate";
import { gradeLabels, specializationLabels } from "../../../entities/assessment";
import { useGetCurrentSession } from "../../../shared/api/endpoints/identity/identity";
import { paths } from "../../../shared/config";
import {
ButtonLink,
EmptyState,
ErrorState,
ForbiddenState,
isAccessDenied,
LoadingState,
Section,
TextLink,
TrustLevel,
} from "../../../shared/ui";
import styles from "./candidate-next-step.module.css";
type StepView = {
title: string;
description: ReactNode;
action: { label: string; to: string };
secondary?: { label: string; to: string };
/** True while the optional FSP link is worth mentioning. */
mentionsOptionalFsp: boolean;
};
function standingLabel(standing: SpecializationStanding): string {
return `${specializationLabels[standing.specialization]}, ${
standing.declaredGrade ? gradeLabels[standing.declaredGrade] : "уровень не указан"
}`;
}
function describeNextStep(journey: CandidateJourney, step: NextStep): StepView {
switch (step.kind) {
case "profile":
return {
title: "Заполните профиль",
description:
"Профиль еще не сохранен. Его можно заполнить вручную, без резюме и без привязки аккаунта ФСП.",
action: { label: "Заполнить профиль", to: paths.candidate.profile },
mentionsOptionalFsp: true,
};
case "questionnaire":
return {
title: "Заполните анкету",
description:
"Укажите специализацию и уровень, на который вы претендуете. Это самооценка: подтвержденную категорию присваивает только тест.",
action: { label: "Заполнить анкету", to: paths.candidate.questionnaire },
mentionsOptionalFsp: true,
};
case "assessment": {
const declared = journey.standings.map(standingLabel).join("; ");
const canStart = journey.standings.some((standing) => standing.canStartAttempt);
return {
title: "Подтвердите уровень тестом",
description: (
<>
Заявлено: {declared}. Заявленный уровень не считается категорией, пока его не подтвердит
тест.{" "}
{canStart
? "Тест можно начать сейчас."
: "Сейчас ни один уровень не открыт для начала; на странице теста указано, что мешает и когда это изменится."}
</>
),
action: { label: "Перейти к тесту", to: paths.candidate.assessment },
mentionsOptionalFsp: true,
};
}
case "resume_attempt":
return {
title: "Продолжите тест",
description: `Есть незавершенная попытка: ${specializationLabels[step.specialization]}. Ответы хранятся на сервере.`,
action: {
label: "Продолжить попытку",
to: paths.candidate.assessmentAttempt(step.attemptId),
},
mentionsOptionalFsp: true,
};
case "result":
return {
title: "Категория получена",
description: `Подтверждено тестом: ${journey.confirmed
.flatMap((standing) =>
standing.confirmedGrade
? [
`${specializationLabels[standing.specialization]}, ${gradeLabels[standing.confirmedGrade]}`,
]
: [],
)
.join("; ")}. Посмотрите результат и решите, кому видна ваша карточка.`,
action: { label: "Открыть результат", to: paths.candidate.results },
secondary: { label: "Настроить видимость", to: paths.candidate.privacy },
mentionsOptionalFsp: false,
};
}
}
function NextStepCard({ journey }: { journey: CandidateJourney }) {
const view = describeNextStep(journey, journey.nextStep);
return (
<section className={styles.card} aria-labelledby="next-step-title">
<p className={styles["card-eyebrow"]}>Следующий шаг</p>
<h2 id="next-step-title" className={styles["card-title"]}>
{view.title}
</h2>
<p className={styles["card-text"]}>{view.description}</p>
<div className={styles.actions}>
<ButtonLink to={view.action.to}>{view.action.label}</ButtonLink>
{view.secondary ? (
<ButtonLink to={view.secondary.to} variant="secondary">
{view.secondary.label}
</ButtonLink>
) : null}
</div>
<p className={styles.note}>
Сохраненный шаг аккаунта: <strong>{onboardingStepLabels[journey.savedStep]}</strong>.
{view.mentionsOptionalFsp
? " Привязка ФСП ID необязательна: путь до категории проходит через анкету и тест."
: null}
</p>
</section>
);
}
function Standings({ journey }: { journey: CandidateJourney }) {
return (
<Section
title="Заявлено и подтверждено"
headingLevel={2}
description="Заявленный уровень - это ваша самооценка из анкеты. Подтвержденной бывает только категория, которую присвоил тест."
>
{journey.standings.length === 0 ? (
<EmptyState
title="Анкета еще не сохранена"
description="Заявленный уровень появится после анкеты."
action={<ButtonLink to={paths.candidate.questionnaire}>Заполнить анкету</ButtonLink>}
/>
) : (
<ul className={styles.standings}>
{journey.standings.map((standing) => (
<li key={standing.specialization} className={styles.standing}>
<h3 className={styles["standing-title"]}>
{specializationLabels[standing.specialization]}
</h3>
<dl className={styles.facts}>
<dt>Заявлено (самооценка)</dt>
<dd>
<TrustLevel
level="claimed"
label={
standing.declaredGrade
? `Заявлено: ${gradeLabels[standing.declaredGrade]}`
: "Уровень не указан"
}
/>
</dd>
<dt>Подтвержденная категория</dt>
<dd>
{standing.confirmedGrade ? (
<TrustLevel
level="confirmed"
label={`Подтверждено тестом: ${gradeLabels[standing.confirmedGrade]}`}
/>
) : (
<TrustLevel level="none" label="Пока не подтверждена" />
)}
</dd>
</dl>
</li>
))}
</ul>
)}
</Section>
);
}
type SectionLink = { label: string; status: string; to: string | null; linkLabel: string };
function sectionLinks(journey: CandidateJourney): SectionLink[] {
const hasConfirmed = journey.confirmed.length > 0;
const hasActiveAttempt = journey.standings.some((standing) => standing.activeAttemptId !== null);
const testStatus = !journey.questionnaireSaved
? "Откроется после анкеты"
: hasConfirmed
? "Есть подтвержденная категория"
: hasActiveAttempt
? "Есть незавершенная попытка"
: "Еще не пройден";
return [
{
label: "Профиль",
status: journey.profileSaved ? "Сохранен" : "Не заполнен",
to: paths.candidate.profile,
linkLabel: journey.profileSaved ? "Открыть профиль" : "Заполнить профиль",
},
{
label: "Анкета",
status: journey.questionnaireSaved ? "Сохранена" : "Не заполнена",
to: paths.candidate.questionnaire,
linkLabel: journey.questionnaireSaved ? "Открыть анкету" : "Заполнить анкету",
},
{
label: "Тест",
status: testStatus,
to: journey.questionnaireSaved ? paths.candidate.assessment : null,
linkLabel: "Перейти к тесту",
},
{
label: "Результаты",
status: hasConfirmed ? "Есть категория" : "Появятся после теста",
to: paths.candidate.results,
linkLabel: "Результаты и история",
},
{
label: "Приватность",
status: "Согласия, видимость карточки, статус поиска",
to: paths.candidate.privacy,
linkLabel: "Открыть настройки",
},
{
label: "Поддержка",
status: "Обращения и запрос ручной оценки",
to: paths.candidate.supportCases,
linkLabel: "Открыть обращения",
},
];
}
function AvailableActions({ journey }: { journey: CandidateJourney }) {
return (
<Section title="Доступные действия" headingLevel={2}>
<ul className={styles.links}>
{sectionLinks(journey).map((item) => (
<li key={item.label} className={styles.link}>
<div>
<p className={styles["link-label"]}>{item.label}</p>
<p className={styles["link-status"]}>{item.status}</p>
</div>
{item.to ? <TextLink to={item.to}>{item.linkLabel}</TextLink> : null}
</li>
))}
</ul>
</Section>
);
}
/**
* The main block of the candidate home: the next step, the declared and the
* confirmed level side by side, and links to the available actions. Everything
* comes from one read of the profile, the questionnaire, and the assessment
* availability; a failed read shows an error instead of a guessed step.
*/
export function CandidateNextStep() {
const session = useGetCurrentSession();
const state = useCandidateJourney(session.data);
if (session.isError) {
if (isAccessDenied(session.error)) return <ForbiddenState error={session.error} />;
return (
<ErrorState
error={session.error}
isRetrying={session.isRefetching}
onRetry={() => void session.refetch()}
title="Не удалось проверить вход"
/>
);
}
if (state.status === "pending") {
return <LoadingState label="Определяем следующий шаг..." />;
}
if (state.status === "error") {
if (isAccessDenied(state.error)) return <ForbiddenState error={state.error} />;
return (
<ErrorState
error={state.error}
isRetrying={state.isRetrying}
onRetry={state.retry}
title="Не удалось определить следующий шаг"
/>
);
}
return (
<div className={styles.root}>
<NextStepCard journey={state.journey} />
<div className={styles.columns}>
<Standings journey={state.journey} />
<AvailableActions journey={state.journey} />
</div>
</div>
);
}