1257 lines
47 KiB
TypeScript
1257 lines
47 KiB
TypeScript
import { useEffect, useId, useRef, useState, type FormEvent, type ReactNode } from "react";
|
||
import {
|
||
addExperience,
|
||
addRole,
|
||
addSoftSkill,
|
||
addStack,
|
||
buildCandidateProfileUpdate,
|
||
moveExperience,
|
||
removeExperience,
|
||
removeItem,
|
||
reviewExperienceOverlaps,
|
||
setParallelAcknowledgement,
|
||
updateExperienceDraft,
|
||
updateFieldDraft,
|
||
updateRoleDraft,
|
||
updateSalaryDraft,
|
||
updateSoftSkillDraft,
|
||
updateStackDraft,
|
||
type CandidateProfileDraft,
|
||
type ProfileFormIssue,
|
||
} from "../../../entities/candidate";
|
||
import type { CandidateProfile } from "../../../shared/api/schemas";
|
||
import { Button, Mono, Notice, SavingStatus, Tag, TrustLevel } from "../../../shared/ui";
|
||
import { profileStepOfField, type ProfileStepId } from "../model/profile-steps";
|
||
import {
|
||
FormProgress,
|
||
FormStepFooter,
|
||
FormStepPanel,
|
||
ReviewBlock,
|
||
type FormStep,
|
||
} from "./form-steps";
|
||
import { useFormSteps } from "./use-form-steps";
|
||
import styles from "./profile-form.module.css";
|
||
|
||
const profileSteps: readonly FormStep<ProfileStepId>[] = [
|
||
{ id: "contacts", label: "Контакты" },
|
||
{ id: "roles", label: "Роли" },
|
||
{ id: "experience", label: "Опыт" },
|
||
{ id: "skills", label: "Навыки" },
|
||
{ id: "terms", label: "Условия" },
|
||
{ id: "review", label: "Проверка" },
|
||
];
|
||
|
||
type Specialization = CandidateProfile["roles"][number]["specialization"];
|
||
type Grade = NonNullable<CandidateProfile["roles"][number]["self_assessed_grade"]>;
|
||
|
||
const specializations: ReadonlyArray<{ value: Specialization; label: string }> = [
|
||
{ value: "backend", label: "Backend" },
|
||
{ value: "frontend", label: "Frontend" },
|
||
{ value: "mobile", label: "Mobile" },
|
||
{ value: "network_engineer", label: "Сетевой инженер" },
|
||
{ value: "devops_sre", label: "DevOps / SRE" },
|
||
{ value: "data_analyst", label: "Аналитик данных" },
|
||
{ value: "ds_ml", label: "DS / ML" },
|
||
{ value: "information_security", label: "Информационная безопасность" },
|
||
{ value: "qa", label: "QA" },
|
||
];
|
||
|
||
const grades: ReadonlyArray<{ value: Grade; label: string }> = [
|
||
{ value: "intern", label: "Стажер" },
|
||
{ value: "junior", label: "Junior" },
|
||
{ value: "middle", label: "Middle" },
|
||
{ value: "senior", label: "Senior" },
|
||
];
|
||
|
||
type ProfileFormProps = {
|
||
draft: CandidateProfileDraft;
|
||
issues: readonly ProfileFormIssue[];
|
||
isSaving: boolean;
|
||
savingState: "idle" | "saving" | "saved" | "failed";
|
||
onDraftChange: (draft: CandidateProfileDraft) => void;
|
||
onSubmit: () => void;
|
||
};
|
||
|
||
function errorFor(issues: readonly ProfileFormIssue[], field: string): string | undefined {
|
||
return issues.find((issue) => issue.field === field)?.message;
|
||
}
|
||
|
||
function ErrorText({ id, children }: { id: string; children?: string | undefined }) {
|
||
return children ? (
|
||
<p className={styles.error} id={id}>
|
||
{children}
|
||
</p>
|
||
) : null;
|
||
}
|
||
|
||
function Suggestion({ source }: { source: { quote: string | null; origin: string } | null }) {
|
||
if (!source || source.origin === "manual") return null;
|
||
const origin = source.origin === "imported" ? "Импортировано" : "Предложено из документа";
|
||
return (
|
||
<details className={styles.suggestion}>
|
||
<summary>{origin}. Значение пока не подтверждено.</summary>
|
||
{source.quote ? <blockquote>{source.quote}</blockquote> : <p>Цитата не сохранена.</p>}
|
||
</details>
|
||
);
|
||
}
|
||
|
||
type FieldProps = {
|
||
id: string;
|
||
label: string;
|
||
error?: string | undefined;
|
||
description?: ReactNode | undefined;
|
||
suggestion?: { quote: string | null; origin: string } | null | undefined;
|
||
children: ReactNode;
|
||
};
|
||
|
||
function Field({ id, label, error, description, suggestion, children }: FieldProps) {
|
||
return (
|
||
<div className={styles.field}>
|
||
<label htmlFor={id}>{label}</label>
|
||
{description ? (
|
||
<p className={styles.hint} id={`${id}-hint`}>
|
||
{description}
|
||
</p>
|
||
) : null}
|
||
{children}
|
||
{suggestion ? (
|
||
<div id={`${id}-suggestion`}>
|
||
<Suggestion source={suggestion} />
|
||
</div>
|
||
) : null}
|
||
<ErrorText id={`${id}-error`}>{error}</ErrorText>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function describedBy(
|
||
id: string,
|
||
error?: string,
|
||
suggestion?: boolean,
|
||
hint?: boolean,
|
||
): string | undefined {
|
||
const values = [
|
||
hint ? `${id}-hint` : "",
|
||
suggestion ? `${id}-suggestion` : "",
|
||
error ? `${id}-error` : "",
|
||
]
|
||
.filter(Boolean)
|
||
.join(" ");
|
||
return values || undefined;
|
||
}
|
||
|
||
const fieldLabels: Readonly<Record<string, string>> = {
|
||
fullName: "имя и фамилия",
|
||
"contacts.email": "контактный email",
|
||
"contacts.phone": "телефон",
|
||
"contacts.telegram": "Telegram",
|
||
"terms.location": "место работы",
|
||
"terms.relocation": "переезд",
|
||
"terms.salaryMinimum.amount": "минимальная зарплата",
|
||
"terms.salaryMinimum.tax_basis": "до или после налога",
|
||
};
|
||
|
||
/** The field named in an issue of the summary, when it has a short name. */
|
||
function fieldLabel(field: string): string | null {
|
||
if (fieldLabels[field]) return fieldLabels[field];
|
||
const row = /^(experience|roles|stack|softSkills)\.(\d+)/.exec(field);
|
||
if (!row) return null;
|
||
const position = Number(row[2]) + 1;
|
||
switch (row[1]) {
|
||
case "experience":
|
||
return `место работы ${position}`;
|
||
case "roles":
|
||
return `роль ${position}`;
|
||
case "stack":
|
||
return `навык ${position}`;
|
||
default:
|
||
return `гибкий навык ${position}`;
|
||
}
|
||
}
|
||
|
||
/** One line per field and message: a schema error can repeat for a field. */
|
||
function uniqueIssues(issues: readonly ProfileFormIssue[]): ProfileFormIssue[] {
|
||
const seen = new Set<string>();
|
||
return issues.filter((item) => {
|
||
const key = `${item.field}\u0000${item.message}`;
|
||
if (seen.has(key)) return false;
|
||
seen.add(key);
|
||
return true;
|
||
});
|
||
}
|
||
|
||
function SourceLabel({ status }: { status: "confirmed" | "extracted" | "unknown" }) {
|
||
if (status === "extracted")
|
||
return <span className={styles["claim-status"]}>Нужно проверить</span>;
|
||
if (status === "unknown") return <span className={styles["claim-status"]}>Не указано</span>;
|
||
return null;
|
||
}
|
||
|
||
export function ProfileForm({
|
||
draft,
|
||
issues,
|
||
isSaving,
|
||
savingState,
|
||
onDraftChange,
|
||
onSubmit,
|
||
}: ProfileFormProps) {
|
||
const prefix = `profile-${useId().replaceAll(":", "")}`;
|
||
const rowSequence = useRef(0);
|
||
const newRowId = (kind: string) => `${kind}-draft-${++rowSequence.current}`;
|
||
const fieldId = (field: string) => `${prefix}-${field.replaceAll(".", "-")}`;
|
||
const issueSummary = useRef<HTMLDivElement>(null);
|
||
const steps = useFormSteps(profileSteps);
|
||
const { goTo } = steps;
|
||
const [stepIssues, setStepIssues] = useState<ProfileFormIssue[]>([]);
|
||
const shownIssues = issues.length > 0 ? issues : stepIssues;
|
||
const listedIssues = uniqueIssues(shownIssues);
|
||
const issue = (field: string) => errorFor(shownIssues, field);
|
||
const setDraft = (next: CandidateProfileDraft) => {
|
||
setStepIssues([]);
|
||
onDraftChange(next);
|
||
};
|
||
|
||
// Issues from a save (client or server) open the first step that owns one.
|
||
const [seenIssues, setSeenIssues] = useState(issues);
|
||
if (seenIssues !== issues) {
|
||
setSeenIssues(issues);
|
||
const first = issues[0];
|
||
if (first) steps.show(profileStepOfField(first.field));
|
||
}
|
||
|
||
useEffect(() => {
|
||
if (shownIssues.length > 0) issueSummary.current?.focus();
|
||
}, [shownIssues]);
|
||
|
||
function goForward() {
|
||
const step = steps.current.id;
|
||
const found = buildCandidateProfileUpdate(draft).issues.filter(
|
||
(item) => profileStepOfField(item.field) === step,
|
||
);
|
||
if (found.length > 0) {
|
||
setStepIssues(found);
|
||
return;
|
||
}
|
||
setStepIssues([]);
|
||
steps.next();
|
||
}
|
||
|
||
function handleSubmit(event: FormEvent<HTMLFormElement>) {
|
||
event.preventDefault();
|
||
if (!steps.isLast) {
|
||
goForward();
|
||
return;
|
||
}
|
||
event.currentTarget.querySelector<HTMLButtonElement>('button[type="submit"]')?.focus();
|
||
onSubmit();
|
||
}
|
||
|
||
const stepLabel = (field: string) =>
|
||
profileSteps.find((step) => step.id === profileStepOfField(field))?.label ?? "";
|
||
const panel = (id: ProfileStepId) => {
|
||
const position = profileSteps.findIndex((step) => step.id === id);
|
||
return {
|
||
step: profileSteps[position] as FormStep<ProfileStepId>,
|
||
position: position + 1,
|
||
total: profileSteps.length,
|
||
active: steps.current.id === id,
|
||
headingRef: steps.headingRef(id),
|
||
};
|
||
};
|
||
|
||
const overlaps = reviewExperienceOverlaps(draft);
|
||
|
||
return (
|
||
<form className={styles.form} onSubmit={handleSubmit} noValidate>
|
||
<FormProgress label="Шаги профиля" steps={profileSteps} index={steps.index} />
|
||
|
||
{shownIssues.length > 0 ? (
|
||
<div
|
||
className={styles["issue-summary"]}
|
||
ref={issueSummary}
|
||
role="alert"
|
||
aria-labelledby={`${prefix}-issues-title`}
|
||
tabIndex={-1}
|
||
>
|
||
<Notice
|
||
tone="danger"
|
||
title={<span id={`${prefix}-issues-title`}>Проверьте профиль</span>}
|
||
>
|
||
<ul className={styles["issue-list"]}>
|
||
{listedIssues.map((item, index) => (
|
||
<li key={`${item.field}-${index}`}>
|
||
<span className={styles["issue-step"]}>
|
||
{stepLabel(item.field)}
|
||
{fieldLabel(item.field) ? `, ${fieldLabel(item.field)}` : ""}:
|
||
</span>{" "}
|
||
{item.message}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</Notice>
|
||
</div>
|
||
) : null}
|
||
|
||
<fieldset className={styles["editor-fields"]} disabled={isSaving}>
|
||
<legend className={styles["editor-legend"]}>Данные профиля</legend>
|
||
<FormStepPanel
|
||
{...panel("contacts")}
|
||
description="Заполните только то, что готовы указать. Компании увидят контакты только после вашего отдельного согласия."
|
||
>
|
||
<div className={styles.grid}>
|
||
<Field
|
||
id={fieldId("fullName")}
|
||
label="Имя и фамилия"
|
||
error={issue("fullName")}
|
||
suggestion={draft.fullName.source}
|
||
>
|
||
<input
|
||
id={fieldId("fullName")}
|
||
name="full_name"
|
||
autoComplete="name"
|
||
maxLength={200}
|
||
value={draft.fullName.value}
|
||
aria-invalid={Boolean(issue("fullName"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("fullName"),
|
||
issue("fullName"),
|
||
Boolean(draft.fullName.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft({
|
||
...draft,
|
||
fullName: updateFieldDraft(draft.fullName, event.currentTarget.value),
|
||
})
|
||
}
|
||
/>
|
||
<SourceLabel status={draft.fullName.status} />
|
||
</Field>
|
||
<Field
|
||
id={fieldId("contacts.email")}
|
||
label="Контактный email"
|
||
error={issue("contacts.email")}
|
||
suggestion={draft.contacts.email.source}
|
||
description="Это контакт профиля. Он может отличаться от адреса входа."
|
||
>
|
||
<input
|
||
id={fieldId("contacts.email")}
|
||
name="contact_email"
|
||
type="email"
|
||
autoComplete="email"
|
||
maxLength={254}
|
||
value={draft.contacts.email.value}
|
||
aria-invalid={Boolean(issue("contacts.email"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("contacts.email"),
|
||
issue("contacts.email"),
|
||
Boolean(draft.contacts.email.source),
|
||
true,
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft({
|
||
...draft,
|
||
contacts: {
|
||
...draft.contacts,
|
||
email: updateFieldDraft(draft.contacts.email, event.currentTarget.value),
|
||
},
|
||
})
|
||
}
|
||
/>
|
||
<SourceLabel status={draft.contacts.email.status} />
|
||
</Field>
|
||
<Field
|
||
id={fieldId("contacts.phone")}
|
||
label="Телефон"
|
||
error={issue("contacts.phone")}
|
||
suggestion={draft.contacts.phone.source}
|
||
description="Международный формат E.164, например +70000000000."
|
||
>
|
||
<input
|
||
id={fieldId("contacts.phone")}
|
||
name="contact_phone"
|
||
type="tel"
|
||
autoComplete="tel"
|
||
inputMode="tel"
|
||
maxLength={16}
|
||
value={draft.contacts.phone.value}
|
||
aria-invalid={Boolean(issue("contacts.phone"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("contacts.phone"),
|
||
issue("contacts.phone"),
|
||
Boolean(draft.contacts.phone.source),
|
||
true,
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft({
|
||
...draft,
|
||
contacts: {
|
||
...draft.contacts,
|
||
phone: updateFieldDraft(draft.contacts.phone, event.currentTarget.value),
|
||
},
|
||
})
|
||
}
|
||
/>
|
||
<SourceLabel status={draft.contacts.phone.status} />
|
||
</Field>
|
||
<Field
|
||
id={fieldId("contacts.telegram")}
|
||
label="Telegram"
|
||
error={issue("contacts.telegram")}
|
||
suggestion={draft.contacts.telegram.source}
|
||
description="Укажите имя пользователя с символом @."
|
||
>
|
||
<input
|
||
id={fieldId("contacts.telegram")}
|
||
name="contact_telegram"
|
||
autoComplete="off"
|
||
maxLength={33}
|
||
value={draft.contacts.telegram.value}
|
||
aria-invalid={Boolean(issue("contacts.telegram"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("contacts.telegram"),
|
||
issue("contacts.telegram"),
|
||
Boolean(draft.contacts.telegram.source),
|
||
true,
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft({
|
||
...draft,
|
||
contacts: {
|
||
...draft.contacts,
|
||
telegram: updateFieldDraft(
|
||
draft.contacts.telegram,
|
||
event.currentTarget.value,
|
||
),
|
||
},
|
||
})
|
||
}
|
||
/>
|
||
<SourceLabel status={draft.contacts.telegram.status} />
|
||
</Field>
|
||
</div>
|
||
</FormStepPanel>
|
||
|
||
<FormStepPanel
|
||
{...panel("roles")}
|
||
description="Самооценка остается заявлением кандидата. Подтвержденная категория появляется только после оценки."
|
||
>
|
||
{draft.roles.map((item, index) => {
|
||
const base = `roles.${index}`;
|
||
const specializationId = fieldId(`${base}.specialization`);
|
||
const gradeId = fieldId(`${base}.self_assessed_grade`);
|
||
return (
|
||
<div className={styles.item} key={item.id}>
|
||
<div className={styles["item-header"]}>
|
||
<h4>Роль {index + 1}</h4>
|
||
<Button
|
||
variant="quiet"
|
||
aria-label={`Удалить роль ${index + 1}`}
|
||
disabled={isSaving}
|
||
onClick={() => setDraft(removeItem(draft, "roles", item.id))}
|
||
>
|
||
Удалить
|
||
</Button>
|
||
</div>
|
||
<div className={styles.grid}>
|
||
<Field
|
||
id={specializationId}
|
||
label="Специализация"
|
||
error={issue(`${base}.specialization`)}
|
||
suggestion={item.source}
|
||
>
|
||
<select
|
||
id={specializationId}
|
||
value={item.specialization}
|
||
aria-invalid={Boolean(issue(`${base}.specialization`))}
|
||
aria-describedby={describedBy(
|
||
specializationId,
|
||
issue(`${base}.specialization`),
|
||
Boolean(item.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateRoleDraft(draft, item.id, {
|
||
specialization: event.currentTarget.value as Specialization | "",
|
||
}),
|
||
)
|
||
}
|
||
>
|
||
<option value="">Выберите специализацию</option>
|
||
{specializations.map((option) => (
|
||
<option key={option.value} value={option.value}>
|
||
{option.label}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</Field>
|
||
<Field
|
||
id={gradeId}
|
||
label="Моя оценка уровня"
|
||
error={issue(`${base}.self_assessed_grade`)}
|
||
suggestion={item.source}
|
||
>
|
||
<select
|
||
id={gradeId}
|
||
value={item.self_assessed_grade ?? ""}
|
||
aria-invalid={Boolean(issue(`${base}.self_assessed_grade`))}
|
||
aria-describedby={describedBy(
|
||
gradeId,
|
||
issue(`${base}.self_assessed_grade`),
|
||
Boolean(item.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateRoleDraft(draft, item.id, {
|
||
self_assessed_grade: (event.currentTarget.value ||
|
||
null) as Grade | null,
|
||
}),
|
||
)
|
||
}
|
||
>
|
||
<option value="">Не указывать</option>
|
||
{grades.map((option) => (
|
||
<option key={option.value} value={option.value}>
|
||
{option.label}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</Field>
|
||
</div>
|
||
</div>
|
||
);
|
||
})}
|
||
<div className={styles["add-row"]}>
|
||
<Button
|
||
variant="secondary"
|
||
disabled={draft.roles.length >= 9 || isSaving}
|
||
onClick={() => setDraft(addRole(draft, newRowId("role")))}
|
||
>
|
||
Добавить специализацию
|
||
</Button>
|
||
</div>
|
||
<section className={styles.categories} aria-labelledby={`${prefix}-categories-title`}>
|
||
<h4 id={`${prefix}-categories-title`}>Подтвержденные категории</h4>
|
||
<p>Эти результаты устанавливает оценка. Их нельзя изменить в профиле.</p>
|
||
{draft.confirmedCategories.length > 0 ? (
|
||
<ul className={styles["category-list"]}>
|
||
{draft.confirmedCategories.map((category) => (
|
||
<li key={`${category.specialization}-${category.grade}-${category.attempt_id}`}>
|
||
<Tag tone="grade">
|
||
{`${specializationLabel(category.specialization)} · ${gradeLabel(category.grade)}`}
|
||
</Tag>
|
||
<TrustLevel level="confirmed" label="Подтверждено тестом" />
|
||
</li>
|
||
))}
|
||
</ul>
|
||
) : (
|
||
<p>Подтвержденных категорий пока нет.</p>
|
||
)}
|
||
</section>
|
||
</FormStepPanel>
|
||
|
||
<FormStepPanel
|
||
{...panel("experience")}
|
||
description="Укажите специализацию и месяцы работы. Пустая дата окончания означает, что работа продолжается."
|
||
>
|
||
{draft.experience.map((item, index) => {
|
||
const base = `experience.${index}`;
|
||
const specialId = fieldId(`${base}.specialization`);
|
||
const startId = fieldId(`${base}.started_on`);
|
||
const endId = fieldId(`${base}.ended_on`);
|
||
const employerId = fieldId(`${base}.employer_name`);
|
||
const summaryId = fieldId(`${base}.summary`);
|
||
return (
|
||
<section
|
||
className={styles.item}
|
||
key={item.id}
|
||
aria-labelledby={`${prefix}-experience-${index}-title`}
|
||
>
|
||
<div className={styles["item-header"]}>
|
||
<h4 id={`${prefix}-experience-${index}-title`}>Место работы {index + 1}</h4>
|
||
<div className={styles["item-actions"]}>
|
||
<Button
|
||
variant="quiet"
|
||
aria-label={`Переместить место работы ${index + 1} выше`}
|
||
disabled={index === 0 || isSaving}
|
||
onClick={() => setDraft(moveExperience(draft, index, -1))}
|
||
>
|
||
Выше
|
||
</Button>
|
||
<Button
|
||
variant="quiet"
|
||
aria-label={`Переместить место работы ${index + 1} ниже`}
|
||
disabled={index === draft.experience.length - 1 || isSaving}
|
||
onClick={() => setDraft(moveExperience(draft, index, 1))}
|
||
>
|
||
Ниже
|
||
</Button>
|
||
<Button
|
||
variant="quiet"
|
||
aria-label={`Удалить место работы ${index + 1}`}
|
||
disabled={isSaving}
|
||
onClick={() => setDraft(removeExperience(draft, item.id))}
|
||
>
|
||
Удалить
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
<div className={styles.grid}>
|
||
<Field
|
||
id={employerId}
|
||
label="Компания"
|
||
error={issue(`${base}.employer_name`)}
|
||
suggestion={item.source}
|
||
>
|
||
<input
|
||
id={employerId}
|
||
value={item.employer_name ?? ""}
|
||
maxLength={200}
|
||
aria-invalid={Boolean(issue(`${base}.employer_name`))}
|
||
aria-describedby={describedBy(
|
||
employerId,
|
||
issue(`${base}.employer_name`),
|
||
Boolean(item.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateExperienceDraft(draft, item.id, {
|
||
employer_name: event.currentTarget.value || null,
|
||
}),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field
|
||
id={specialId}
|
||
label="Специализация"
|
||
error={issue(`${base}.specialization`)}
|
||
suggestion={item.source}
|
||
>
|
||
<select
|
||
id={specialId}
|
||
value={item.specialization}
|
||
aria-invalid={Boolean(issue(`${base}.specialization`))}
|
||
aria-describedby={describedBy(
|
||
specialId,
|
||
issue(`${base}.specialization`),
|
||
Boolean(item.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateExperienceDraft(draft, item.id, {
|
||
specialization: event.currentTarget.value as Specialization | "",
|
||
}),
|
||
)
|
||
}
|
||
>
|
||
<option value="">Выберите специализацию</option>
|
||
{specializations.map((option) => (
|
||
<option key={option.value} value={option.value}>
|
||
{option.label}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</Field>
|
||
<Field
|
||
id={startId}
|
||
label="Начало работы"
|
||
error={issue(`${base}.started_on`)}
|
||
description="Месяц и год."
|
||
suggestion={item.source}
|
||
>
|
||
<input
|
||
id={startId}
|
||
type="month"
|
||
value={item.started_on}
|
||
aria-invalid={Boolean(issue(`${base}.started_on`))}
|
||
aria-describedby={describedBy(
|
||
startId,
|
||
issue(`${base}.started_on`),
|
||
Boolean(item.source),
|
||
true,
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateExperienceDraft(draft, item.id, {
|
||
started_on: event.currentTarget.value,
|
||
}),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field
|
||
id={endId}
|
||
label="Окончание работы"
|
||
error={issue(`${base}.ended_on`)}
|
||
description="Оставьте пустым, если работаете здесь сейчас."
|
||
suggestion={item.source}
|
||
>
|
||
<input
|
||
id={endId}
|
||
type="month"
|
||
value={item.ended_on ?? ""}
|
||
aria-invalid={Boolean(issue(`${base}.ended_on`))}
|
||
aria-describedby={describedBy(
|
||
endId,
|
||
issue(`${base}.ended_on`),
|
||
Boolean(item.source),
|
||
true,
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateExperienceDraft(draft, item.id, {
|
||
ended_on: event.currentTarget.value || null,
|
||
}),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field id={summaryId} label="Чем занимались" error={issue(`${base}.summary`)}>
|
||
<textarea
|
||
id={summaryId}
|
||
rows={3}
|
||
maxLength={1000}
|
||
value={item.summary ?? ""}
|
||
aria-invalid={Boolean(issue(`${base}.summary`))}
|
||
aria-describedby={describedBy(summaryId, issue(`${base}.summary`))}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateExperienceDraft(draft, item.id, {
|
||
summary: event.currentTarget.value || null,
|
||
}),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
</div>
|
||
</section>
|
||
);
|
||
})}
|
||
<Button
|
||
variant="secondary"
|
||
disabled={draft.experience.length >= 20 || isSaving}
|
||
onClick={() => setDraft(addExperience(draft, newRowId("experience")))}
|
||
>
|
||
Добавить место работы
|
||
</Button>
|
||
{overlaps.length > 0 ? (
|
||
<div className={styles["overlap-list"]}>
|
||
<h4>Параллельные периоды</h4>
|
||
<p>Совпадающие месяцы нужно подтвердить отдельно для каждой пары мест работы.</p>
|
||
{overlaps.map((overlap) => {
|
||
const id = `${prefix}-overlap-${overlap.key.replace(":", "-")}`;
|
||
return (
|
||
<div className={styles.overlap} key={overlap.key}>
|
||
{overlap.requiresAcknowledgement ? (
|
||
<>
|
||
<input
|
||
id={id}
|
||
type="checkbox"
|
||
checked={overlap.acknowledged}
|
||
disabled={isSaving}
|
||
aria-describedby={
|
||
issue("experience.overlaps") ? `${id}-error` : undefined
|
||
}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
setParallelAcknowledgement(
|
||
draft,
|
||
overlap.key,
|
||
event.currentTarget.checked,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<label htmlFor={id}>
|
||
Подтверждаю, что места работы {overlap.firstIndex + 1} и{" "}
|
||
{overlap.secondIndex + 1} действительно шли параллельно:{" "}
|
||
{formatPeriod(overlap.firstPeriod)} и {formatPeriod(overlap.secondPeriod)}
|
||
.
|
||
</label>
|
||
</>
|
||
) : (
|
||
<p>
|
||
Параллельная работа в местах {overlap.firstIndex + 1} и{" "}
|
||
{overlap.secondIndex + 1} подтверждена ранее:{" "}
|
||
{formatPeriod(overlap.firstPeriod)} и {formatPeriod(overlap.secondPeriod)}.
|
||
</p>
|
||
)}
|
||
</div>
|
||
);
|
||
})}
|
||
<ErrorText id={`${prefix}-experience-overlaps-error`}>
|
||
{issue("experience.overlaps")}
|
||
</ErrorText>
|
||
</div>
|
||
) : null}
|
||
</FormStepPanel>
|
||
|
||
<FormStepPanel
|
||
{...panel("skills")}
|
||
description="Технологии и гибкие навыки по одному в строке. Пустые строки не сохраняются."
|
||
>
|
||
<div className={styles.list}>
|
||
<h4>Технологии и инструменты</h4>
|
||
{draft.stack.map((item, index) => {
|
||
const field = `stack.${index}.tag`;
|
||
const id = fieldId(field);
|
||
return (
|
||
<div className={styles["list-row"]} key={item.id}>
|
||
<Field
|
||
id={id}
|
||
label={`Навык ${index + 1}`}
|
||
error={issue(field)}
|
||
suggestion={item.source}
|
||
>
|
||
<input
|
||
id={id}
|
||
value={item.tag}
|
||
maxLength={50}
|
||
aria-invalid={Boolean(issue(field))}
|
||
aria-describedby={describedBy(id, issue(field), Boolean(item.source))}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateStackDraft(draft, item.id, { tag: event.currentTarget.value }),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Button
|
||
variant="quiet"
|
||
aria-label={`Удалить навык ${index + 1}`}
|
||
disabled={isSaving}
|
||
onClick={() => setDraft(removeItem(draft, "stack", item.id))}
|
||
>
|
||
Удалить
|
||
</Button>
|
||
</div>
|
||
);
|
||
})}
|
||
<Button
|
||
variant="secondary"
|
||
disabled={draft.stack.length >= 30 || isSaving}
|
||
onClick={() => setDraft(addStack(draft, newRowId("stack")))}
|
||
>
|
||
Добавить навык
|
||
</Button>
|
||
</div>
|
||
|
||
<div className={styles.list}>
|
||
<h4>Гибкие навыки</h4>
|
||
{draft.softSkills.map((item, index) => {
|
||
const field = `softSkills.${index}.skill`;
|
||
const id = fieldId(field);
|
||
return (
|
||
<div className={styles["list-row"]} key={item.id}>
|
||
<Field
|
||
id={id}
|
||
label={`Гибкий навык ${index + 1}`}
|
||
error={issue(field)}
|
||
suggestion={item.source}
|
||
>
|
||
<input
|
||
id={id}
|
||
value={item.skill}
|
||
maxLength={50}
|
||
aria-invalid={Boolean(issue(field))}
|
||
aria-describedby={describedBy(id, issue(field), Boolean(item.source))}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateSoftSkillDraft(draft, item.id, {
|
||
skill: event.currentTarget.value,
|
||
}),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Button
|
||
variant="quiet"
|
||
aria-label={`Удалить гибкий навык ${index + 1}`}
|
||
disabled={isSaving}
|
||
onClick={() => setDraft(removeItem(draft, "softSkills", item.id))}
|
||
>
|
||
Удалить
|
||
</Button>
|
||
</div>
|
||
);
|
||
})}
|
||
<Button
|
||
variant="secondary"
|
||
disabled={draft.softSkills.length >= 10 || isSaving}
|
||
onClick={() => setDraft(addSoftSkill(draft, newRowId("soft-skill")))}
|
||
>
|
||
Добавить гибкий навык
|
||
</Button>
|
||
</div>
|
||
</FormStepPanel>
|
||
|
||
<FormStepPanel
|
||
{...panel("terms")}
|
||
description="Все условия необязательны. Зарплата указывается в рублях в месяц."
|
||
>
|
||
<Field
|
||
id={fieldId("terms.location")}
|
||
label="Желаемое место работы"
|
||
error={issue("terms.location")}
|
||
suggestion={draft.terms.location.source}
|
||
>
|
||
<input
|
||
id={fieldId("terms.location")}
|
||
maxLength={100}
|
||
value={draft.terms.location.value}
|
||
aria-invalid={Boolean(issue("terms.location"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("terms.location"),
|
||
issue("terms.location"),
|
||
Boolean(draft.terms.location.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft({
|
||
...draft,
|
||
terms: {
|
||
...draft.terms,
|
||
location: updateFieldDraft(draft.terms.location, event.currentTarget.value),
|
||
},
|
||
})
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field
|
||
id={fieldId("terms.relocation")}
|
||
label="Готовность к переезду"
|
||
error={issue("terms.relocation")}
|
||
suggestion={draft.terms.relocation.source}
|
||
>
|
||
<select
|
||
id={fieldId("terms.relocation")}
|
||
value={
|
||
draft.terms.relocation.value === null ? "" : String(draft.terms.relocation.value)
|
||
}
|
||
aria-invalid={Boolean(issue("terms.relocation"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("terms.relocation"),
|
||
issue("terms.relocation"),
|
||
Boolean(draft.terms.relocation.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft({
|
||
...draft,
|
||
terms: {
|
||
...draft.terms,
|
||
relocation: updateFieldDraft(
|
||
draft.terms.relocation,
|
||
event.currentTarget.value === ""
|
||
? null
|
||
: event.currentTarget.value === "true",
|
||
),
|
||
},
|
||
})
|
||
}
|
||
>
|
||
<option value="">Не указывать</option>
|
||
<option value="true">Да</option>
|
||
<option value="false">Нет</option>
|
||
</select>
|
||
</Field>
|
||
<div className={styles.grid}>
|
||
<Field
|
||
id={fieldId("terms.salaryMinimum.amount")}
|
||
label="Минимальная зарплата, рублей в месяц"
|
||
error={issue("terms.salaryMinimum.amount")}
|
||
suggestion={draft.terms.salaryMinimum.source}
|
||
description="Сумма должна быть кратна 1000."
|
||
>
|
||
<input
|
||
id={fieldId("terms.salaryMinimum.amount")}
|
||
type="number"
|
||
inputMode="numeric"
|
||
min={1000}
|
||
max={100000000}
|
||
step={1000}
|
||
value={draft.terms.salaryMinimum.amount}
|
||
aria-invalid={Boolean(issue("terms.salaryMinimum.amount"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("terms.salaryMinimum.amount"),
|
||
issue("terms.salaryMinimum.amount"),
|
||
Boolean(draft.terms.salaryMinimum.source),
|
||
true,
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(updateSalaryDraft(draft, { amount: event.currentTarget.value }))
|
||
}
|
||
/>
|
||
<SourceLabel status={draft.terms.salaryMinimum.status} />
|
||
</Field>
|
||
<Field
|
||
id={fieldId("terms.salaryMinimum.tax_basis")}
|
||
label="Сумма до или после налога"
|
||
error={issue("terms.salaryMinimum.tax_basis")}
|
||
suggestion={draft.terms.salaryMinimum.source}
|
||
>
|
||
<select
|
||
id={fieldId("terms.salaryMinimum.tax_basis")}
|
||
value={draft.terms.salaryMinimum.tax_basis}
|
||
aria-invalid={Boolean(issue("terms.salaryMinimum.tax_basis"))}
|
||
aria-describedby={describedBy(
|
||
fieldId("terms.salaryMinimum.tax_basis"),
|
||
issue("terms.salaryMinimum.tax_basis"),
|
||
Boolean(draft.terms.salaryMinimum.source),
|
||
)}
|
||
onChange={(event) =>
|
||
setDraft(
|
||
updateSalaryDraft(draft, {
|
||
tax_basis: event.currentTarget.value as "net" | "gross" | "",
|
||
}),
|
||
)
|
||
}
|
||
>
|
||
<option value="">Выберите</option>
|
||
<option value="gross">До налога</option>
|
||
<option value="net">После налога</option>
|
||
</select>
|
||
</Field>
|
||
</div>
|
||
</FormStepPanel>
|
||
|
||
<FormStepPanel
|
||
{...panel("review")}
|
||
description="Проверьте сведения перед сохранением. Сервер получит профиль целиком."
|
||
>
|
||
<ProfileReview draft={draft} disabled={isSaving} onEdit={(id) => goTo(id)} />
|
||
</FormStepPanel>
|
||
</fieldset>
|
||
|
||
<FormStepFooter
|
||
back={
|
||
steps.isFirst ? null : (
|
||
<Button variant="secondary" disabled={isSaving} onClick={steps.back}>
|
||
Назад
|
||
</Button>
|
||
)
|
||
}
|
||
>
|
||
{steps.isLast ? (
|
||
<>
|
||
<SavingStatus state={savingState} />
|
||
<Button type="submit" isBusy={isSaving}>
|
||
{isSaving ? "Сохраняем профиль..." : "Сохранить профиль"}
|
||
</Button>
|
||
</>
|
||
) : (
|
||
<>
|
||
{draft.expectedVersion > 0 ? (
|
||
<Button variant="quiet" disabled={isSaving} onClick={() => goTo("review")}>
|
||
К проверке и сохранению
|
||
</Button>
|
||
) : null}
|
||
<Button type="submit" disabled={isSaving}>
|
||
Далее
|
||
</Button>
|
||
</>
|
||
)}
|
||
</FormStepFooter>
|
||
</form>
|
||
);
|
||
}
|
||
|
||
function specializationLabel(value: Specialization | ""): string {
|
||
return specializations.find((option) => option.value === value)?.label ?? (value || "Не выбрана");
|
||
}
|
||
|
||
function gradeLabel(value: Grade | null): string {
|
||
return grades.find((option) => option.value === value)?.label ?? "уровень не указан";
|
||
}
|
||
|
||
const moneyFormat = new Intl.NumberFormat("ru-RU");
|
||
|
||
function ReviewValue({ children }: { children: ReactNode }) {
|
||
return children === "" || children === null ? (
|
||
<span className={styles["review-empty"]}>не указано</span>
|
||
) : (
|
||
<>{children}</>
|
||
);
|
||
}
|
||
|
||
/** The last step: everything the save will send, grouped by the step that owns it. */
|
||
function ProfileReview({
|
||
draft,
|
||
disabled,
|
||
onEdit,
|
||
}: {
|
||
draft: CandidateProfileDraft;
|
||
disabled: boolean;
|
||
onEdit: (step: ProfileStepId) => void;
|
||
}) {
|
||
const stack = draft.stack.filter((item) => item.tag.trim());
|
||
const softSkills = draft.softSkills.filter((item) => item.skill.trim());
|
||
const salary = draft.terms.salaryMinimum;
|
||
const salaryAmount = Number(salary.amount);
|
||
const overlaps = reviewExperienceOverlaps(draft).length;
|
||
return (
|
||
<div className={styles.review}>
|
||
<ReviewBlock
|
||
title="Контакты"
|
||
editLabel="контакты"
|
||
disabled={disabled}
|
||
onEdit={() => onEdit("contacts")}
|
||
>
|
||
<dl className={styles["review-facts"]}>
|
||
<div>
|
||
<dt>Имя</dt>
|
||
<dd>
|
||
<ReviewValue>{draft.fullName.value.trim()}</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>Email</dt>
|
||
<dd>
|
||
<ReviewValue>{draft.contacts.email.value.trim()}</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>Телефон</dt>
|
||
<dd>
|
||
<ReviewValue>
|
||
{draft.contacts.phone.value.trim() ? (
|
||
<Mono>{draft.contacts.phone.value.trim()}</Mono>
|
||
) : (
|
||
""
|
||
)}
|
||
</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>Telegram</dt>
|
||
<dd>
|
||
<ReviewValue>{draft.contacts.telegram.value.trim()}</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
</dl>
|
||
</ReviewBlock>
|
||
<ReviewBlock title="Роли" editLabel="роли" disabled={disabled} onEdit={() => onEdit("roles")}>
|
||
{draft.roles.length > 0 ? (
|
||
<ul className={styles["review-tags"]}>
|
||
{draft.roles.map((role) => (
|
||
<li key={role.id}>
|
||
<Tag tone="grade">
|
||
{`${specializationLabel(role.specialization)} · ${gradeLabel(role.self_assessed_grade)}`}
|
||
</Tag>
|
||
</li>
|
||
))}
|
||
<li>
|
||
<TrustLevel level="claimed" label="Самооценка" />
|
||
</li>
|
||
</ul>
|
||
) : (
|
||
<p className={styles["review-empty"]}>Роли не добавлены.</p>
|
||
)}
|
||
</ReviewBlock>
|
||
<ReviewBlock
|
||
title="Опыт"
|
||
editLabel="опыт"
|
||
disabled={disabled}
|
||
onEdit={() => onEdit("experience")}
|
||
>
|
||
{draft.experience.length > 0 ? (
|
||
<ol className={styles["review-list"]}>
|
||
{draft.experience.map((item) => (
|
||
<li key={item.id}>
|
||
<span className={styles["review-strong"]}>
|
||
{item.employer_name?.trim() || "Компания не указана"}
|
||
</span>
|
||
<span className={styles["review-meta"]}>
|
||
{specializationLabel(item.specialization)},{" "}
|
||
<Mono>
|
||
{item.started_on || "?"} — {item.ended_on || "сейчас"}
|
||
</Mono>
|
||
</span>
|
||
</li>
|
||
))}
|
||
</ol>
|
||
) : (
|
||
<p className={styles["review-empty"]}>Места работы не добавлены.</p>
|
||
)}
|
||
{overlaps > 0 ? (
|
||
<p className={styles["review-meta"]}>
|
||
Пересекающихся пар периодов: <Mono>{overlaps}</Mono>.
|
||
</p>
|
||
) : null}
|
||
</ReviewBlock>
|
||
<ReviewBlock
|
||
title="Навыки"
|
||
editLabel="навыки"
|
||
disabled={disabled}
|
||
onEdit={() => onEdit("skills")}
|
||
>
|
||
{stack.length > 0 || softSkills.length > 0 ? (
|
||
<ul className={styles["review-tags"]}>
|
||
{stack.map((item) => (
|
||
<li key={item.id}>
|
||
<Tag tone="stack">{item.tag.trim()}</Tag>
|
||
</li>
|
||
))}
|
||
{softSkills.map((item) => (
|
||
<li key={item.id}>
|
||
<Tag tone="neutral">{item.skill.trim()}</Tag>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
) : (
|
||
<p className={styles["review-empty"]}>Навыки не добавлены.</p>
|
||
)}
|
||
</ReviewBlock>
|
||
<ReviewBlock
|
||
title="Условия"
|
||
editLabel="условия"
|
||
disabled={disabled}
|
||
onEdit={() => onEdit("terms")}
|
||
>
|
||
<dl className={styles["review-facts"]}>
|
||
<div>
|
||
<dt>Место работы</dt>
|
||
<dd>
|
||
<ReviewValue>{draft.terms.location.value.trim()}</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>Переезд</dt>
|
||
<dd>
|
||
<ReviewValue>
|
||
{draft.terms.relocation.value === null
|
||
? ""
|
||
: draft.terms.relocation.value
|
||
? "готов(а)"
|
||
: "не готов(а)"}
|
||
</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
<div>
|
||
<dt>Зарплата</dt>
|
||
<dd>
|
||
<ReviewValue>
|
||
{salary.amount.trim() && Number.isFinite(salaryAmount) ? (
|
||
<span className={styles.salary}>
|
||
от {moneyFormat.format(salaryAmount)} ₽
|
||
{salary.tax_basis ? (
|
||
<span className={styles["review-meta"]}>
|
||
{" "}
|
||
{salary.tax_basis === "gross" ? "до налога" : "на руки"}
|
||
</span>
|
||
) : null}
|
||
</span>
|
||
) : (
|
||
""
|
||
)}
|
||
</ReviewValue>
|
||
</dd>
|
||
</div>
|
||
</dl>
|
||
</ReviewBlock>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function formatPeriod(period: { started_on: string; ended_on: string | null }): string {
|
||
return `${period.started_on} - ${period.ended_on ?? "сейчас"}`;
|
||
}
|