Files
lincodex/frontend/src/entities/match/ui/candidate-card-details.tsx
T

203 lines
8.2 KiB
TypeScript

import {
Button,
ErrorState,
ForbiddenState,
isAccessDenied,
LoadingState,
PublishedProjects,
StatusView,
TrustLevel,
} from "../../../shared/ui";
import { useMatchCandidateCard, useMatchCandidateEvidence } from "../api/card";
import { describeCardFailure } from "../model/card-failure";
import { presentCard, presentEvidence } from "../model/card-presentation";
import styles from "./candidate-card-details.module.css";
type CandidateCardDetailsProps = {
id: string;
accountId: string;
organizationId: string;
candidateHandle: string;
/** False keeps the panel mounted but out of the page, so closing does not read the card again. */
open: boolean;
};
function ReadFailure({
error,
isRetrying,
onRetry,
fallbackTitle,
}: {
error: unknown;
isRetrying: boolean;
onRetry: () => void;
fallbackTitle: string;
}) {
const failure = describeCardFailure(error);
if (failure) {
return (
<StatusView
kind={failure.kind}
title={failure.title}
description={failure.description}
action={
failure.kind === "error" ? (
<Button variant="secondary" isBusy={isRetrying} onClick={onRetry}>
{isRetrying ? "Повторяем..." : "Повторить"}
</Button>
) : null
}
/>
);
}
if (isAccessDenied(error)) return <ForbiddenState error={error} />;
return (
<ErrorState error={error} title={fallbackTitle} isRetrying={isRetrying} onRetry={onRetry} />
);
}
/**
* The full anonymous card of one result and its evidence section, read from
* the card endpoints when the employer opens it. The card belongs to the
* whole candidate, so it lists every specialization the candidate published,
* each with its own confirmation status.
*/
export function CandidateCardDetails({
id,
accountId,
organizationId,
candidateHandle,
open,
}: CandidateCardDetailsProps) {
const card = useMatchCandidateCard(accountId, organizationId, candidateHandle, true);
const hasCategories = Boolean(card.data?.categories && card.data.categories.length > 0);
const evidence = useMatchCandidateEvidence(
accountId,
organizationId,
candidateHandle,
card.isSuccess && hasCategories,
);
const details = card.data ? presentCard(card.data) : null;
const facts = evidence.data ? presentEvidence(evidence.data) : null;
return (
<section id={id} className={styles.panel} aria-label="Карточка кандидата" hidden={!open}>
<h5 className={styles.title}>Карточка кандидата</h5>
<p className={styles.note}>
Карточка относится к кандидату целиком и без контактов. Подтверждение задается для каждой
специализации отдельно. Открытие учитывается в просмотрах, кандидат, уже показанный в этом
окне, второй раз не списывается.
</p>
{card.isPending ? <LoadingState label="Открываем карточку..." /> : null}
{card.isError ? (
<ReadFailure
error={card.error}
isRetrying={card.isFetching}
onRetry={() => void card.refetch()}
fallbackTitle="Не удалось открыть карточку"
/>
) : null}
{details ? (
<>
<section aria-label="Подтвержденные категории">
<h6 className={styles.subtitle}>Подтвержденные категории</h6>
{details.categories === null ? (
<p className={styles.unknown}>Нет значения в карточке.</p>
) : details.categories.length === 0 ? (
<p className={styles.unknown}>Подтвержденных категорий нет.</p>
) : (
<ul className={styles.list}>
{details.categories.map((category) => (
<li key={category.specialization}>
{category.specialization}: {category.grade}. {category.strength}
</li>
))}
</ul>
)}
</section>
<section aria-label="Заявленные специализации">
<h6 className={styles.subtitle}>Заявленные специализации</h6>
{details.selfAssessments === null ? (
<p className={styles.unknown}>Нет значения в карточке.</p>
) : details.selfAssessments.length === 0 ? (
<p className={styles.unknown}>Специализации не названы.</p>
) : (
<ul className={styles.list}>
{details.selfAssessments.map((item) => (
<li key={item.specialization}>
<strong>{item.specialization}</strong>
<span>
{item.declaredGrade ? `Заявлено: ${item.declaredGrade}` : "Уровень не указан"}
</span>
<TrustLevel
level={item.confirmed ? "confirmed" : "none"}
label={item.confirmed ? "Грейд подтвержден" : "Грейд не подтвержден"}
/>
</li>
))}
</ul>
)}
</section>
<dl className={styles.facts}>
<dt>Технологии</dt>
<dd>
{details.stack === null
? "Нет значения в карточке"
: details.stack.join(", ") || "Не названы"}
</dd>
<dt>Общий опыт</dt>
<dd>{details.experience ?? "Нет значения в карточке"}</dd>
<dt>Форматы работы</dt>
<dd>
{details.workFormats === null
? "Нет значения в карточке"
: details.workFormats.join(", ") || "Не названы"}
</dd>
<dt>Зарплатные ожидания</dt>
<dd>{details.salaryCompatibility ?? "Нет значения в карточке"}</dd>
</dl>
{details.projects && details.projects.length > 0 ? (
<section aria-label="Проекты кандидата">
<h6 className={styles.subtitle}>Проекты</h6>
<PublishedProjects projects={details.projects} />
</section>
) : null}
{hasCategories ? (
<section aria-label="Подтверждающие факты оценки">
<h6 className={styles.subtitle}>Подтверждающие факты оценки</h6>
{evidence.isPending ? <LoadingState label="Загружаем факты оценки..." /> : null}
{evidence.isError ? (
<ReadFailure
error={evidence.error}
isRetrying={evidence.isFetching}
onRetry={() => void evidence.refetch()}
fallbackTitle="Не удалось загрузить факты оценки"
/>
) : null}
{facts && facts.length === 0 ? (
<p className={styles.unknown}>Для категорий карточки нет видимого факта оценки.</p>
) : null}
{facts && facts.length > 0 ? (
<ul className={styles.list}>
{facts.map((fact) => (
<li key={fact.title}>
<strong>{fact.title}</strong>
<TrustLevel level={fact.trust} label={fact.trustLabel} />
<dl className={styles["evidence-facts"]}>
<dt>Год оценки</dt>
<dd>{fact.observedYear}</dd>
<dt>Основа</dt>
<dd>{fact.basisLabel}</dd>
</dl>
</li>
))}
</ul>
) : null}
</section>
) : null}
</>
) : null}
</section>
);
}