Files
lincodex/frontend/src/widgets/candidate-next-step/ui/candidate-journey-progress.tsx
T

94 lines
3.3 KiB
TypeScript

import { useGetCurrentSession } from "../../../shared/api/endpoints/identity/identity";
import { paths } from "../../../shared/config";
import {
buildSteps,
Card,
ErrorState,
ForbiddenState,
isAccessDenied,
LoadingState,
Stepper,
TextLink,
} from "../../../shared/ui";
import { useCandidateJourney } from "../../../entities/candidate";
import styles from "./candidate-journey-progress.module.css";
const journeySteps = [
{ id: "profile", label: "Профиль" },
{ id: "questionnaire", label: "Анкета" },
{ id: "assessment", label: "Тест" },
] as const;
export function CandidateJourneyProgress() {
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 (session.isPending) {
return <LoadingState label="Проверяем вход перед загрузкой прогресса..." />;
}
if (!session.data || session.data.account.scenario !== "candidate") {
return (
<ForbiddenState
title="Прогресс кандидата недоступен"
description="Откройте кабинет кандидата, чтобы продолжить заполнение профиля."
/>
);
}
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="Не удалось загрузить прогресс"
/>
);
}
const currentIndex =
state.journey.nextStep.kind === "profile"
? 0
: state.journey.nextStep.kind === "questionnaire"
? 1
: state.journey.nextStep.kind === "result"
? journeySteps.length
: 2;
return (
<Card as="section" tone="raised" labelledBy="candidate-journey-progress-title">
<h2 id="candidate-journey-progress-title" className={styles.title}>
Профиль, анкета и тест
</h2>
<Stepper
label="Прогресс заполнения профиля кандидата"
steps={buildSteps(journeySteps, currentIndex)}
/>
<p className={styles.note}>
{state.journey.questionnaireSaved
? "Самооценка сохранена. Подтвержденную категорию присваивает только тест."
: "Сначала сохраните профиль и анкету, затем проверьте уровень тестом."}
</p>
<div className={styles.links}>
<TextLink to={paths.candidate.profile}>Профиль</TextLink>
<TextLink to={paths.candidate.questionnaire}>Анкета</TextLink>
<TextLink to={paths.candidate.assessment}>Тест</TextLink>
</div>
</Card>
);
}