feat(matches): add the candidate match screen with expandable explanations
This commit is contained in:
1 parent
0b11021b16
commit
28337d84cb
50 files changed
+4834
-37
No files matched your search
@@ -0,0 +1 @@
|
||||
export { MatchesPage } from "./ui/matches-page";
|
||||
@@ -0,0 +1,104 @@
|
||||
.content {
|
||||
display: grid;
|
||||
gap: var(--space-6);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.selector {
|
||||
display: grid;
|
||||
gap: var(--space-2);
|
||||
min-width: min(100%, 20rem);
|
||||
max-width: 28rem;
|
||||
}
|
||||
|
||||
.selector label,
|
||||
.basis legend {
|
||||
font-weight: var(--font-weight-bold);
|
||||
}
|
||||
|
||||
.selector select {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
min-height: 2.75rem;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border: var(--line-thin) solid var(--color-border-strong);
|
||||
border-radius: var(--radius-s);
|
||||
color: var(--color-text);
|
||||
background: var(--color-surface);
|
||||
}
|
||||
|
||||
.selector select:focus-visible {
|
||||
outline: var(--line-strong) solid var(--color-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.workspace {
|
||||
display: grid;
|
||||
gap: var(--space-6);
|
||||
align-items: start;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.basis {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.basis legend {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.choices {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-1) var(--space-4);
|
||||
}
|
||||
|
||||
.choice {
|
||||
display: inline-flex;
|
||||
gap: var(--space-2);
|
||||
align-items: center;
|
||||
min-height: 2.75rem;
|
||||
}
|
||||
|
||||
.choice input {
|
||||
width: 1.25rem;
|
||||
height: 1.25rem;
|
||||
margin: 0;
|
||||
accent-color: var(--color-accent);
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: 0;
|
||||
color: var(--color-text-secondary);
|
||||
font-size: var(--font-size-s);
|
||||
}
|
||||
|
||||
.results {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.idle {
|
||||
margin: 0;
|
||||
padding: var(--space-5);
|
||||
border: var(--line-thin) dashed var(--color-border-strong);
|
||||
border-radius: var(--radius-m);
|
||||
background: var(--color-surface);
|
||||
}
|
||||
|
||||
.load-more {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
@media (width >= 64rem) {
|
||||
.workspace {
|
||||
grid-template-columns: minmax(19rem, 24rem) minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { ApiRequestError } from "../../../shared/api";
|
||||
import { useGetCurrentSession } from "../../../shared/api/endpoints/identity/identity";
|
||||
import {
|
||||
getOrganizationNeed,
|
||||
listOrganizationNeeds,
|
||||
} from "../../../shared/api/endpoints/need/need";
|
||||
import type { MatchSearchRequest, Session } from "../../../shared/api/schemas";
|
||||
import {
|
||||
Button,
|
||||
EmptyState,
|
||||
ErrorState,
|
||||
ForbiddenState,
|
||||
isAccessDenied,
|
||||
LoadingState,
|
||||
Page,
|
||||
StatusView,
|
||||
} from "../../../shared/ui";
|
||||
import { formatRetryAfter, searchMatches } from "../../../entities/match";
|
||||
import {
|
||||
activeNeedOrganizations,
|
||||
isNeedSessionCurrent,
|
||||
needQueryKeys,
|
||||
useNeedOrganizationDirectory,
|
||||
type NeedOrganization,
|
||||
} from "../../../entities/need";
|
||||
import {
|
||||
buildMatchRequest,
|
||||
emptyFilterDraft,
|
||||
filtersFromDraft,
|
||||
MatchFilterForm,
|
||||
type MatchBasis,
|
||||
type MatchFilterDraft,
|
||||
} from "../../../features/filter-matches";
|
||||
import { MatchList } from "../../../widgets/match-list";
|
||||
import styles from "./matches-page.module.css";
|
||||
|
||||
const needPickerLimit = 100;
|
||||
type BasisMode = "need" | "bank";
|
||||
|
||||
type SearchVariables = {
|
||||
request: MatchSearchRequest;
|
||||
sentFilters: ReturnType<typeof filtersFromDraft>;
|
||||
needTitle: string | null;
|
||||
};
|
||||
|
||||
function sessionChanged(): Error {
|
||||
return new Error("The session changed during the search.");
|
||||
}
|
||||
|
||||
function SearchFailure({
|
||||
error,
|
||||
onRetry,
|
||||
isRetrying,
|
||||
}: {
|
||||
error: unknown;
|
||||
onRetry: () => void;
|
||||
isRetrying: boolean;
|
||||
}) {
|
||||
if (isAccessDenied(error)) return <ForbiddenState error={error} />;
|
||||
if (error instanceof ApiRequestError && error.status === 429) {
|
||||
const wait = formatRetryAfter(error.retryAfterSeconds);
|
||||
return (
|
||||
<StatusView
|
||||
kind="error"
|
||||
title="Слишком много запросов"
|
||||
description={
|
||||
wait
|
||||
? `Повторить поиск можно ${wait}.`
|
||||
: "Сервер не назвал время повтора. Подождите и повторите поиск."
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<ErrorState
|
||||
error={error}
|
||||
title={
|
||||
error instanceof ApiRequestError && error.status === 404
|
||||
? "Потребность или компания не найдены"
|
||||
: "Не удалось выполнить поиск"
|
||||
}
|
||||
isRetrying={isRetrying}
|
||||
onRetry={onRetry}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
type WorkspaceProps = {
|
||||
session: Session;
|
||||
organization: NeedOrganization;
|
||||
initialNeedId: string | null;
|
||||
};
|
||||
|
||||
/** The search form and the result for one organization; remounted when the organization changes. */
|
||||
function MatchWorkspace({ session, organization, initialNeedId }: WorkspaceProps) {
|
||||
const queryClient = useQueryClient();
|
||||
const accountId = session.account.id;
|
||||
const organizationId = organization.organization.id;
|
||||
const sessionCurrent = isNeedSessionCurrent(queryClient, session);
|
||||
const resultRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const needs = useQuery({
|
||||
queryKey: [...needQueryKeys.list(accountId, organizationId), "match-picker"],
|
||||
queryFn: ({ signal }) =>
|
||||
listOrganizationNeeds(organizationId, { limit: needPickerLimit }, { signal }),
|
||||
enabled: sessionCurrent,
|
||||
gcTime: 0,
|
||||
staleTime: 0,
|
||||
retry: false,
|
||||
});
|
||||
const needItems = needs.data?.items ?? [];
|
||||
|
||||
const [basisChoice, setBasisChoice] = useState<BasisMode | null>(initialNeedId ? "need" : null);
|
||||
const [needId, setNeedId] = useState(initialNeedId ?? "");
|
||||
const [draft, setDraft] = useState<MatchFilterDraft>(emptyFilterDraft);
|
||||
|
||||
const mode: BasisMode = basisChoice ?? (needItems.length > 0 ? "need" : "bank");
|
||||
const selectedNeed = needItems.find((item) => item.id === needId);
|
||||
|
||||
const needDetail = useQuery({
|
||||
queryKey: [...needQueryKeys.detail(accountId, organizationId, needId), "match-basis"],
|
||||
queryFn: ({ signal }) => getOrganizationNeed(organizationId, needId, { signal }),
|
||||
enabled: sessionCurrent && mode === "need" && selectedNeed !== undefined,
|
||||
gcTime: 0,
|
||||
staleTime: 0,
|
||||
retry: false,
|
||||
});
|
||||
|
||||
const basis: MatchBasis | null =
|
||||
mode === "bank"
|
||||
? { mode: "bank" }
|
||||
: needDetail.data
|
||||
? { mode: "need", needId, requirementsVersion: needDetail.data.requirements_version }
|
||||
: null;
|
||||
|
||||
let blockedReason: string | null = null;
|
||||
if (mode === "need") {
|
||||
if (needs.isPending) blockedReason = "Загружаем потребности...";
|
||||
else if (needItems.length === 0) {
|
||||
blockedReason = "Потребностей нет. Создайте потребность или ищите по всем профилям.";
|
||||
} else if (!selectedNeed) blockedReason = "Выберите потребность.";
|
||||
else if (needDetail.isError) blockedReason = "Не удалось загрузить потребность. Повторите.";
|
||||
else if (!needDetail.data) blockedReason = "Загружаем версию требований...";
|
||||
}
|
||||
|
||||
const search = useMutation({
|
||||
mutationFn: async (variables: SearchVariables) => {
|
||||
if (!isNeedSessionCurrent(queryClient, session)) throw sessionChanged();
|
||||
const result = await searchMatches(organizationId, variables.request, session.csrf_token);
|
||||
if (!isNeedSessionCurrent(queryClient, session)) throw sessionChanged();
|
||||
return result;
|
||||
},
|
||||
});
|
||||
|
||||
function runSearch() {
|
||||
if (!basis) return;
|
||||
search.mutate({
|
||||
request: buildMatchRequest(basis, draft),
|
||||
sentFilters: filtersFromDraft(draft),
|
||||
needTitle: basis.mode === "need" ? (needDetail.data?.title ?? null) : null,
|
||||
});
|
||||
}
|
||||
|
||||
const currentRequest = basis ? JSON.stringify(buildMatchRequest(basis, draft)) : null;
|
||||
const stale =
|
||||
search.isSuccess &&
|
||||
search.variables !== undefined &&
|
||||
currentRequest !== JSON.stringify(search.variables.request);
|
||||
|
||||
// After a search finishes, the result region is the reading position.
|
||||
useEffect(() => {
|
||||
if (search.isError) resultRef.current?.focus();
|
||||
}, [search.isError]);
|
||||
|
||||
return (
|
||||
<div className={styles.workspace}>
|
||||
<MatchFilterForm
|
||||
value={draft}
|
||||
onChange={setDraft}
|
||||
onSubmit={runSearch}
|
||||
isSearching={search.isPending}
|
||||
blockedReason={blockedReason}
|
||||
basis={
|
||||
<fieldset className={styles.basis}>
|
||||
<legend>Основание поиска</legend>
|
||||
<div className={styles.choices}>
|
||||
<label className={styles.choice}>
|
||||
<input
|
||||
type="radio"
|
||||
name="match-basis"
|
||||
checked={mode === "need"}
|
||||
onChange={() => setBasisChoice("need")}
|
||||
/>
|
||||
По потребности
|
||||
</label>
|
||||
<label className={styles.choice}>
|
||||
<input
|
||||
type="radio"
|
||||
name="match-basis"
|
||||
checked={mode === "bank"}
|
||||
onChange={() => setBasisChoice("bank")}
|
||||
/>
|
||||
По всем профилям
|
||||
</label>
|
||||
</div>
|
||||
{mode === "need" ? (
|
||||
<div className={styles.selector}>
|
||||
<label htmlFor="match-need">Потребность</label>
|
||||
<select
|
||||
id="match-need"
|
||||
value={selectedNeed ? needId : ""}
|
||||
onChange={(event) => setNeedId(event.currentTarget.value)}
|
||||
>
|
||||
<option value="">Выберите потребность</option>
|
||||
{needItems.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.title}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{needs.isError ? (
|
||||
<p className={styles.hint}>
|
||||
Не удалось загрузить потребности. Можно искать по всем профилям.
|
||||
</p>
|
||||
) : null}
|
||||
{needs.data?.page.has_more ? (
|
||||
<p className={styles.hint}>Показаны первые {needPickerLimit} потребностей.</p>
|
||||
) : null}
|
||||
{needDetail.data ? (
|
||||
<p className={styles.hint}>
|
||||
Версия требований: {needDetail.data.requirements_version}. Грейд потребности
|
||||
фильтром не служит.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<p className={styles.hint}>
|
||||
Ищем среди всех профилей, доступных компании. Каждая специализация кандидата
|
||||
показывается отдельной записью.
|
||||
</p>
|
||||
)}
|
||||
</fieldset>
|
||||
}
|
||||
/>
|
||||
<div className={styles.results} ref={resultRef} tabIndex={-1}>
|
||||
{search.isPending ? <LoadingState label="Ищем кандидатов..." /> : null}
|
||||
{search.isError ? (
|
||||
<SearchFailure error={search.error} isRetrying={search.isPending} onRetry={runSearch} />
|
||||
) : null}
|
||||
{search.isSuccess && search.variables ? (
|
||||
<MatchList
|
||||
accountId={accountId}
|
||||
organizationId={organizationId}
|
||||
result={search.data}
|
||||
sentFilters={search.variables.sentFilters}
|
||||
needTitle={search.variables.needTitle}
|
||||
stale={stale}
|
||||
/>
|
||||
) : null}
|
||||
{search.isIdle ? (
|
||||
<p className={styles.idle}>
|
||||
Поиск еще не запускался. Задайте условия и нажмите «Найти кандидатов»: выдача появится
|
||||
здесь, а перезагрузка страницы не повторяет поиск сама.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function isAccessLoss(error: unknown): error is ApiRequestError {
|
||||
return (
|
||||
error instanceof ApiRequestError &&
|
||||
(error.status === 401 || error.status === 403 || error.status === 404)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The candidate search of an organization owner. The page picks the
|
||||
* organization from the address, loads the owner's organizations, and hands
|
||||
* the search itself to the workspace. A search starts only on the employer's
|
||||
* action, because it spends card view quota.
|
||||
*/
|
||||
export function MatchesPage() {
|
||||
const queryClient = useQueryClient();
|
||||
const sessionQuery = useGetCurrentSession({ query: { retry: false } });
|
||||
const session = sessionQuery.data;
|
||||
const sessionReady =
|
||||
Boolean(session && session.account.scenario === "employer") &&
|
||||
isNeedSessionCurrent(queryClient, session);
|
||||
const directory = useNeedOrganizationDirectory(session, sessionReady);
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const requestedOrganizationId = searchParams.get("organization_id");
|
||||
const requestedNeedId = searchParams.get("need_id");
|
||||
|
||||
const pages = directory.data?.pages;
|
||||
const organizations = useMemo(() => activeNeedOrganizations(pages ?? []), [pages]);
|
||||
const selected =
|
||||
organizations.find((item) => item.organization.id === requestedOrganizationId) ??
|
||||
(requestedOrganizationId ? undefined : organizations[0]);
|
||||
const hasMore = directory.hasNextPage;
|
||||
const fetchNext = directory.fetchNextPage;
|
||||
const fetching = directory.isFetchingNextPage;
|
||||
|
||||
// A requested organization may sit on a later page of the directory.
|
||||
useEffect(() => {
|
||||
if (!directory.data || directory.isError || fetching) return;
|
||||
if (hasMore && (!selected || organizations.length === 0)) void fetchNext();
|
||||
}, [directory.data, directory.isError, fetchNext, fetching, hasMore, organizations, selected]);
|
||||
|
||||
const loading =
|
||||
!sessionQuery.isError &&
|
||||
(!sessionReady || directory.isPending || (hasMore && !selected && !directory.isError));
|
||||
|
||||
return (
|
||||
<Page
|
||||
title="Кандидаты"
|
||||
eyebrow="Кабинет работодателя"
|
||||
lead="Ищите анонимные карточки по потребности или среди всех профилей. Объяснение строит сервер: подтвержденные источники и пробелы показаны отдельно, неизвестное не выдается за ноль."
|
||||
width="wide"
|
||||
>
|
||||
{sessionQuery.isError ? (
|
||||
isAccessLoss(sessionQuery.error) ? (
|
||||
<ForbiddenState error={sessionQuery.error} title="Текущий вход не подтвержден" />
|
||||
) : (
|
||||
<ErrorState
|
||||
error={sessionQuery.error}
|
||||
isRetrying={sessionQuery.isFetching}
|
||||
onRetry={() => void sessionQuery.refetch()}
|
||||
/>
|
||||
)
|
||||
) : null}
|
||||
{directory.isError ? (
|
||||
isAccessLoss(directory.error) ? (
|
||||
<ForbiddenState error={directory.error} />
|
||||
) : (
|
||||
<ErrorState
|
||||
error={directory.error}
|
||||
isRetrying={directory.isFetching}
|
||||
onRetry={() => void directory.refetch()}
|
||||
/>
|
||||
)
|
||||
) : null}
|
||||
{loading ? <LoadingState label="Проверяем компанию..." /> : null}
|
||||
{session && sessionReady && directory.data && !directory.isError && !loading ? (
|
||||
<div className={styles.content}>
|
||||
{organizations.length === 0 ? (
|
||||
<ForbiddenState
|
||||
title="Нужны права владельца компании"
|
||||
description="Искать кандидатов в этой версии может только владелец компании."
|
||||
/>
|
||||
) : !selected ? (
|
||||
<EmptyState
|
||||
title="Компания не найдена среди ваших"
|
||||
description="Выберите компанию, где вы владелец."
|
||||
action={
|
||||
<Button variant="secondary" onClick={() => setSearchParams({}, { replace: true })}>
|
||||
Выбрать другую компанию
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
{organizations.length > 1 ? (
|
||||
<div className={styles.selector}>
|
||||
<label htmlFor="match-organization">Компания</label>
|
||||
<select
|
||||
id="match-organization"
|
||||
value={selected.organization.id}
|
||||
onChange={(event) =>
|
||||
setSearchParams({ organization_id: event.currentTarget.value })
|
||||
}
|
||||
>
|
||||
{organizations.map((item) => (
|
||||
<option key={item.organization.id} value={item.organization.id}>
|
||||
{item.organization.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
) : null}
|
||||
<MatchWorkspace
|
||||
key={selected.organization.id}
|
||||
session={session}
|
||||
organization={selected}
|
||||
initialNeedId={requestedOrganizationId ? requestedNeedId : null}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
@@ -109,6 +109,13 @@
|
||||
padding-inline-start: var(--space-5);
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2) var(--space-3);
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.load-more {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
|
||||
@@ -95,9 +95,14 @@ function NeedCard({ item, organizationId }: { item: NeedSummary; organizationId:
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
<ButtonLink to={paths.employer.need(item.id, organizationId)} variant="secondary">
|
||||
Открыть потребность
|
||||
</ButtonLink>
|
||||
<div className={styles.actions}>
|
||||
<ButtonLink to={paths.employer.need(item.id, organizationId)} variant="secondary">
|
||||
Открыть потребность
|
||||
</ButtonLink>
|
||||
<ButtonLink to={paths.employer.candidatesForNeed(item.id, organizationId)} variant="quiet">
|
||||
Подобрать кандидатов
|
||||
</ButtonLink>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -119,15 +119,6 @@ export const screens = {
|
||||
"Фильтры поиска кандидатов",
|
||||
],
|
||||
},
|
||||
employerCandidates: {
|
||||
area: "employer",
|
||||
title: "Кандидаты",
|
||||
planned: [
|
||||
"Объяснимая выдача по потребности",
|
||||
"Шортлист",
|
||||
"Псевдонимы вместо контактов до принятия приглашения",
|
||||
],
|
||||
},
|
||||
employerInvitations: {
|
||||
area: "employer",
|
||||
title: "Приглашения",
|
||||
|
||||
Reference in new issue
Block a user