229 lines
8.5 KiB
TypeScript
229 lines
8.5 KiB
TypeScript
import { useId } from "react";
|
||
import {
|
||
cardFieldLabels,
|
||
publishableCardFields,
|
||
type C2State,
|
||
type PublicationDraft,
|
||
} from "../../../entities/candidate-view";
|
||
import type { PrivacySettings, SearchStatusUpdate } from "../../../shared/api/schemas";
|
||
import { Button, SavingStatus, Section } from "../../../shared/ui";
|
||
import styles from "./visibility-controls.module.css";
|
||
|
||
type PublicationControlsProps = {
|
||
settings: PrivacySettings;
|
||
c2State: C2State;
|
||
draft: PublicationDraft;
|
||
isDirty: boolean;
|
||
isStale: boolean;
|
||
hasUnsupportedFields: boolean;
|
||
canSave: boolean;
|
||
isSaving: boolean;
|
||
message: string | null;
|
||
error: string | null;
|
||
onDraftChange: (draft: PublicationDraft) => void;
|
||
onSave: () => void;
|
||
onReload: () => void;
|
||
};
|
||
|
||
export function PublicationControls({
|
||
settings,
|
||
c2State,
|
||
draft,
|
||
isDirty,
|
||
isStale,
|
||
hasUnsupportedFields,
|
||
canSave,
|
||
isSaving,
|
||
message,
|
||
error,
|
||
onDraftChange,
|
||
onSave,
|
||
onReload,
|
||
}: PublicationControlsProps) {
|
||
const stateId = useId();
|
||
const fieldsId = useId();
|
||
const c2Id = useId();
|
||
|
||
function toggleField(field: PublicationDraft["fields"][number], checked: boolean) {
|
||
const next = checked
|
||
? publishableCardFields.filter(
|
||
(candidate) => candidate === field || draft.fields.includes(candidate),
|
||
)
|
||
: draft.fields.filter((candidate) => candidate !== field);
|
||
onDraftChange({ ...draft, fields: [...next] });
|
||
}
|
||
|
||
return (
|
||
<Section
|
||
title="Публикация карточки"
|
||
description="C2, набор публикуемых полей и статус поиска управляются отдельно. Изменение статуса поиска не публикует карточку."
|
||
>
|
||
<div className={styles.root}>
|
||
<p className={styles["current-state"]} role="status">
|
||
Текущее состояние:{" "}
|
||
{settings.publication.state === "published" ? "опубликована" : "закрыта"}.
|
||
</p>
|
||
<fieldset className={styles.group} aria-describedby={stateId}>
|
||
<legend>Состояние карточки</legend>
|
||
<p id={stateId} className={styles.help}>
|
||
Закрытая карточка не доступна компаниям. Повторная публикация требует отдельного
|
||
действия.
|
||
</p>
|
||
<label className={styles.choice}>
|
||
<input
|
||
type="radio"
|
||
name="publication-state"
|
||
value="closed"
|
||
checked={draft.state === "closed"}
|
||
disabled={isSaving}
|
||
onChange={() => onDraftChange({ ...draft, state: "closed" })}
|
||
/>
|
||
<span>Оставить карточку закрытой</span>
|
||
</label>
|
||
<label className={styles.choice}>
|
||
<input
|
||
type="radio"
|
||
name="publication-state"
|
||
value="published"
|
||
checked={draft.state === "published"}
|
||
disabled={isSaving}
|
||
onChange={() => onDraftChange({ ...draft, state: "published" })}
|
||
/>
|
||
<span>Опубликовать выбранные поля</span>
|
||
</label>
|
||
</fieldset>
|
||
|
||
<fieldset className={styles.group} aria-describedby={fieldsId}>
|
||
<legend>Поля анонимной карточки</legend>
|
||
<p id={fieldsId} className={styles.help}>
|
||
Имя, контакты, работодатели и суммы зарплаты не публикуются. Подтвержденные категории и
|
||
самооценка показываются раздельно.
|
||
</p>
|
||
{publishableCardFields.map((field) => (
|
||
<label className={styles.choice} key={field}>
|
||
<input
|
||
type="checkbox"
|
||
checked={draft.fields.includes(field)}
|
||
disabled={isSaving}
|
||
onChange={(event) => toggleField(field, event.currentTarget.checked)}
|
||
/>
|
||
<span>{cardFieldLabels[field]}</span>
|
||
</label>
|
||
))}
|
||
</fieldset>
|
||
|
||
{hasUnsupportedFields ? (
|
||
<p className={styles.notice} role="status">
|
||
В сохраненных настройках есть поля прежнего формата. Они не показываются в карточке.
|
||
Выберите разрешенные поля или явно закройте публикацию.
|
||
</p>
|
||
) : null}
|
||
<p id={c2Id} className={styles.help}>
|
||
{c2State === "active"
|
||
? "Согласие C2 активно. Оно само по себе не включает публикацию."
|
||
: c2State === "checking"
|
||
? "Проверяем полную историю согласий C2. До завершения публикация недоступна."
|
||
: "Для публикации сначала отдельно примите согласие C2 ниже."}
|
||
</p>
|
||
{isStale ? (
|
||
<div className={styles.error} role="alert">
|
||
Настройки изменились на сервере. Ваш черновик сохранен на экране. Загрузите актуальные
|
||
настройки, чтобы начать заново.
|
||
</div>
|
||
) : null}
|
||
{error ? (
|
||
<div className={styles.error} role="alert">
|
||
{error}
|
||
</div>
|
||
) : null}
|
||
{message ? (
|
||
<p className={styles.message} role="status" aria-live="polite">
|
||
{message}
|
||
</p>
|
||
) : null}
|
||
<div className={styles.actions}>
|
||
<Button
|
||
aria-describedby={c2Id}
|
||
aria-disabled={!canSave || isSaving}
|
||
disabled={!canSave}
|
||
isBusy={isSaving}
|
||
onClick={onSave}
|
||
>
|
||
{draft.state === "closed" ? "Сохранить и закрыть карточку" : "Сохранить публикацию"}
|
||
</Button>
|
||
{isStale ? (
|
||
<Button variant="secondary" isBusy={isSaving} onClick={onReload}>
|
||
Загрузить актуальные настройки
|
||
</Button>
|
||
) : null}
|
||
<SavingStatus
|
||
state={isSaving ? "saving" : message ? "saved" : error ? "failed" : "idle"}
|
||
/>
|
||
</div>
|
||
{!isDirty && !isStale ? (
|
||
<p className={styles.help}>Нет несохраненных изменений публикации.</p>
|
||
) : null}
|
||
</div>
|
||
</Section>
|
||
);
|
||
}
|
||
|
||
type SearchStatusControlProps = {
|
||
settings: PrivacySettings;
|
||
isSaving: boolean;
|
||
message: string | null;
|
||
error: string | null;
|
||
onSetStatus: (value: SearchStatusUpdate["value"]) => void;
|
||
};
|
||
|
||
export function SearchStatusControl({
|
||
settings,
|
||
isSaving,
|
||
message,
|
||
error,
|
||
onSetStatus,
|
||
}: SearchStatusControlProps) {
|
||
const status = settings.search_status;
|
||
return (
|
||
<Section
|
||
title="Статус поиска"
|
||
description="Это заявление о поиске работы, а не согласие и не настройка публикации. Статус сам по себе не открывает карточку компаниям."
|
||
>
|
||
<div className={styles.root}>
|
||
<p className={styles["current-state"]} role="status">
|
||
{status.value === "looking"
|
||
? "Вы подтвердили, что ищете работу."
|
||
: "Вы не объявляете поиск работы."}
|
||
{status.lapsed ? " Срок подтверждения истек." : ""}
|
||
</p>
|
||
<div className={styles.actions}>
|
||
{status.value === "looking" ? (
|
||
<Button
|
||
variant="secondary"
|
||
isBusy={isSaving}
|
||
onClick={() => onSetStatus("not_looking")}
|
||
>
|
||
Скрыть статус поиска
|
||
</Button>
|
||
) : (
|
||
<Button isBusy={isSaving} onClick={() => onSetStatus("looking")}>
|
||
Подтвердить статус «Ищу»
|
||
</Button>
|
||
)}
|
||
</div>
|
||
{error ? (
|
||
<div className={styles.error} role="alert">
|
||
{error}
|
||
</div>
|
||
) : null}
|
||
{message ? (
|
||
<p className={styles.message} role="status" aria-live="polite">
|
||
{message}
|
||
</p>
|
||
) : null}
|
||
<SavingStatus state={isSaving ? "saving" : message ? "saved" : error ? "failed" : "idle"} />
|
||
</div>
|
||
</Section>
|
||
);
|
||
}
|