feat(frontend): redesign the candidate cabinet with step-by-step profile and questionnaire forms

This commit is contained in:
shira committed 2026-10-10 09:50:27 +03:00
1 parent 15590d127c
commit c836d02ea3
77 files changed
+5409 -1618

No files matched your search

@@ -1,61 +1,90 @@
.root {
/* Phone first: one column; from 1024px the form and a side note. */
.layout {
display: grid;
gap: var(--space-5);
align-items: start;
min-width: 0;
}
.root > section {
min-width: 0;
@media (width >= 64rem) {
.layout {
grid-template-columns: minmax(0, 1fr) 18rem;
}
.aside {
position: sticky;
top: calc(var(--header-height) + var(--chrome-inset) * 2 + var(--space-4));
}
}
.server-step,
.form-error,
.conflict,
.continuation {
min-width: 0;
margin: 0 0 var(--space-4);
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-m);
background: var(--color-surface);
overflow-wrap: anywhere;
.panel {
gap: var(--space-5);
}
.panel-header {
display: flex;
flex-wrap: wrap;
gap: var(--space-2) var(--space-4);
align-items: baseline;
justify-content: space-between;
}
.panel-title {
color: var(--color-text-strong);
font-size: var(--font-size-l);
}
.server-step {
color: var(--color-text-secondary);
font-size: var(--font-size-s);
}
.form-error,
.conflict {
border-width: var(--line-strong);
border-color: var(--color-danger);
}
.form-error {
.server-step strong {
color: var(--color-text);
font-family: var(--font-mono);
font-weight: var(--font-weight-medium);
}
.conflict h2 {
margin: 0 0 var(--space-2);
font-size: var(--font-size-l);
.notice-title {
margin-bottom: var(--space-1);
color: var(--color-danger);
font-size: var(--font-size-m);
}
.conflict p,
.continuation p {
margin: 0 0 var(--space-3);
.notice-text {
color: var(--color-text);
}
.aside {
min-width: 0;
}
.aside-title {
color: var(--color-text-strong);
font-size: var(--font-size-m);
}
.aside-text,
.aside-note {
color: var(--color-text-secondary);
font-size: var(--font-size-s);
line-height: var(--line-height-body);
}
.continuation {
display: flex;
flex-wrap: wrap;
gap: var(--space-3);
align-items: center;
justify-content: space-between;
margin: var(--space-5) 0 0;
.aside-note {
padding-top: var(--space-3);
border-top: var(--line-thin) solid var(--color-divider);
}
.continuation p {
flex: 1 1 16rem;
.legend {
display: grid;
gap: var(--space-2);
margin: 0;
padding: 0;
list-style: none;
}
.loading {
display: grid;
gap: var(--space-4);
}
@@ -25,10 +25,13 @@ import { paths } from "../../../shared/config";
import {
Button,
ButtonLink,
Card,
ErrorState,
ForbiddenState,
LoadingState,
Section,
Notice,
Skeleton,
TrustLevel,
} from "../../../shared/ui";
import { ProfileForm } from "./profile-form";
import styles from "./edit-profile.module.css";
@@ -62,6 +65,15 @@ function ProfileAccessDenied({ error }: { error: unknown }) {
);
}
function EditorLoading({ label }: { label: string }) {
return (
<div className={styles.loading}>
<LoadingState label={label} />
<Skeleton shape="card" lines={4} />
</div>
);
}
export function EditProfile() {
const queryClient = useQueryClient();
const profile = useGetMyProfile({
@@ -92,7 +104,7 @@ export function EditProfile() {
}, [profileAccessError, queryClient, sessionAccessError]);
if (profile.isPending && !profile.data) {
return <LoadingState label="Загружаем профиль кандидата..." />;
return <EditorLoading label="Загружаем профиль кандидата..." />;
}
if (profileAccessError) {
return <ProfileAccessDenied error={profileAccessError} />;
@@ -130,7 +142,7 @@ export function EditProfile() {
/>
);
}
return <LoadingState label="Проверяем текущий вход..." />;
return <EditorLoading label="Проверяем текущий вход..." />;
}
if (session.data.account.scenario !== "candidate") {
return (
@@ -294,46 +306,62 @@ function ProfileEditor({ profile, profileQuery }: ProfileEditorProps) {
const continuationLabel = savedStep ? stepLabel(savedStep) : null;
return (
<div className={styles.root}>
<Section
title="Личные сведения"
description="Заполните только то, что готовы указать. Профиль сохраняется на сервере и не требует резюме или внешнего аккаунта."
>
{currentStep ? (
<p className={styles["server-step"]}>
Сохраненный шаг аккаунта: <strong>{stepLabel(currentStep)}</strong>.
</p>
) : null}
{conflict ? (
<div className={styles.conflict} role="alert" aria-labelledby="profile-conflict-title">
<h2 id="profile-conflict-title">Профиль обновлен в другом окне</h2>
<p>
Введенные здесь изменения не отправлены. Сравнение и автоматическое объединение не
выполняются. При замене черновика данные из этой формы будут удалены.
<div className={styles.layout}>
<Card as="section" tone="panel" labelledBy="profile-title" className={styles.panel}>
<header className={styles["panel-header"]}>
<h2 id="profile-title" className={styles["panel-title"]}>
Личные сведения
</h2>
{currentStep ? (
<p className={styles["server-step"]}>
Сохраненный шаг аккаунта: <strong>{stepLabel(currentStep)}</strong>.
</p>
{latestLoadError ? (
<p>Не удалось получить текущую версию. Черновик сохранен в памяти формы.</p>
) : null}
<Button
variant="secondary"
isBusy={profileQuery.isRefetching}
aria-describedby="profile-conflict-title"
onClick={() => void loadCurrentVersion()}
) : null}
</header>
{conflict ? (
<div role="alert" aria-labelledby="profile-conflict-title">
<Notice
tone="danger"
action={
<Button
variant="secondary"
isBusy={profileQuery.isRefetching}
aria-describedby="profile-conflict-title"
onClick={() => void loadCurrentVersion()}
>
{profileQuery.isRefetching
? "Загружаем текущую версию..."
: "Заменить черновик актуальной версией"}
</Button>
}
>
{profileQuery.isRefetching
? "Загружаем текущую версию..."
: "Заменить черновик актуальной версией"}
</Button>
<h3 id="profile-conflict-title" className={styles["notice-title"]}>
Профиль обновлен в другом окне
</h3>
<p>
Введенные здесь изменения не отправлены. Сравнение и автоматическое объединение не
выполняются. При замене черновика данные из этой формы будут удалены.
</p>
{latestLoadError ? (
<p>Не удалось получить текущую версию. Черновик сохранен в памяти формы.</p>
) : null}
</Notice>
</div>
) : null}
{forbidden ? (
<div className={styles["form-error"]} role="alert">
Профиль больше недоступен. Данные формы останутся до ухода со страницы.
<div role="alert">
<Notice tone="danger">
<p className={styles["notice-text"]}>
Профиль больше недоступен. Данные формы останутся до ухода со страницы.
</p>
</Notice>
</div>
) : null}
{formError ? (
<div className={styles["form-error"]} role="alert">
{formError}
<div role="alert">
<Notice tone="danger">
<p className={styles["notice-text"]}>{formError}</p>
</Notice>
</div>
) : null}
<ProfileForm
@@ -345,18 +373,50 @@ function ProfileEditor({ profile, profileQuery }: ProfileEditorProps) {
onSubmit={() => void handleSubmit()}
/>
{savedStep && continuation ? (
<div className={styles.continuation} role="status">
<p>Профиль сохранен. Сервер подтвердил шаг аккаунта: {continuationLabel}.</p>
{continuation !== paths.candidate.profile ? (
<ButtonLink to={continuation} variant="secondary">
Открыть сохраненный шаг
</ButtonLink>
) : (
<p>Серверный шаг остается «Профиль».</p>
)}
<div role="status">
<Notice
tone="success"
action={
continuation !== paths.candidate.profile ? (
<ButtonLink to={continuation} variant="secondary">
Открыть сохраненный шаг
</ButtonLink>
) : null
}
>
<p className={styles["notice-text"]}>
Профиль сохранен. Сервер подтвердил шаг аккаунта: {continuationLabel}.
</p>
{continuation === paths.candidate.profile ? (
<p>Серверный шаг остается «Профиль».</p>
) : null}
</Notice>
</div>
) : null}
</Section>
</Card>
<aside className={styles.aside} aria-labelledby="profile-aside-title">
<Card tone="raised">
<h2 id="profile-aside-title" className={styles["aside-title"]}>
Кто что видит
</h2>
<p className={styles["aside-text"]}>
Профиль сохраняется на сервере и не требует резюме или внешнего аккаунта. Имя и контакты
компании получают только после вашего согласия на конкретное приглашение.
</p>
<ul className={styles.legend}>
<li>
<TrustLevel level="claimed" label="Заявлено вами" />
</li>
<li>
<TrustLevel level="confirmed" label="Подтверждено тестом" />
</li>
</ul>
<p className={styles["aside-note"]}>
Черновик живет только на этой странице: он не записывается в браузерное хранилище и
отправляется целиком на последнем шаге.
</p>
</Card>
</aside>
</div>
);
}
@@ -0,0 +1,140 @@
/* Phone first. The same rules live in the questionnaire feature. */
.progress {
min-width: 0;
}
/* Below 700px the step labels are read by assistive technology but not
* drawn: four or six labels do not fit in a row at 360px, and the current
* label is the heading of the visible step anyway. */
@media (width < 43.75rem) {
.progress ol > li > span:last-child {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
}
.step {
display: grid;
gap: var(--space-5);
min-width: 0;
}
.step[hidden] {
display: none;
}
.header {
display: grid;
gap: var(--space-2);
min-width: 0;
}
.title {
color: var(--color-text-strong);
font-size: var(--font-size-xl);
line-height: var(--line-height-snug);
scroll-margin-block-start: calc(var(--header-height) + var(--space-6));
overflow-wrap: anywhere;
}
.title:focus {
outline: none;
}
.title:focus-visible {
outline: var(--focus-ring-width) solid var(--color-focus-ring);
outline-offset: var(--focus-ring-offset);
}
.description {
max-width: 44rem;
color: var(--color-text-secondary);
font-size: var(--font-size-s);
line-height: var(--line-height-body);
}
.body {
display: grid;
gap: var(--space-5);
min-width: 0;
}
.footer {
display: flex;
flex-wrap: wrap-reverse;
gap: var(--space-3);
align-items: center;
justify-content: space-between;
padding-top: var(--space-5);
border-top: var(--line-thin) solid var(--color-divider);
}
.footer-back,
.footer-forward {
display: flex;
flex-wrap: wrap;
gap: var(--space-3);
align-items: center;
min-width: 0;
}
.footer-forward {
justify-content: flex-end;
margin-inline-start: auto;
}
/* On a phone the forward action spans the width, within thumb reach. */
@media (width < 43.75rem) {
.footer-forward {
flex: 1 1 100%;
flex-direction: column-reverse;
align-items: stretch;
}
}
.review {
display: grid;
gap: var(--space-3);
min-width: 0;
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-s);
background: var(--color-canvas);
}
.review-header {
display: flex;
flex-wrap: wrap;
gap: var(--space-2) var(--space-4);
align-items: baseline;
justify-content: space-between;
}
.review-title {
color: var(--color-text-strong);
font-size: var(--font-size-m);
}
/* A text action with a capsule focus ring, as small as a link. */
.edit {
min-height: 2rem;
padding: 0 var(--space-3);
border: 0;
border-radius: var(--radius-pill);
color: var(--color-link);
font-family: var(--font-mono);
font-size: var(--font-size-s);
background: none;
text-decoration: underline;
text-decoration-thickness: var(--line-thin);
text-underline-offset: 0.25em;
cursor: pointer;
}
.edit:hover {
color: var(--color-link-hover);
}
@@ -0,0 +1,111 @@
import { useId, type ReactNode } from "react";
import { buildSteps, Stepper, VisuallyHidden } from "../../../shared/ui";
import styles from "./form-steps.module.css";
import type { FormStep } from "./use-form-steps";
/*
* Steps of a long form. The same small module lives in the questionnaire feature;
* it belongs in shared/ui once both forms settle (see the frontend README).
*/
export type { FormStep };
type FormProgressProps<TId extends string> = {
label: string;
steps: readonly FormStep<TId>[];
index: number;
};
/** The Stepper of the form; on a phone only the markers and the count stay. */
export function FormProgress<TId extends string>({ label, steps, index }: FormProgressProps<TId>) {
return (
<div className={styles.progress}>
<Stepper label={label} steps={buildSteps(steps, index)} />
</div>
);
}
type FormStepPanelProps = {
step: { label: string };
position: number;
total: number;
active: boolean;
headingRef: (element: HTMLHeadingElement | null) => void;
description?: ReactNode;
children: ReactNode;
};
/**
* One step. Inactive steps stay mounted with the hidden attribute, so field
* ids, descriptions, and server errors keep pointing at real elements.
*/
export function FormStepPanel({
step,
position,
total,
active,
headingRef,
description,
children,
}: FormStepPanelProps) {
const headingId = useId();
return (
<section className={styles.step} hidden={!active} aria-labelledby={headingId}>
<header className={styles.header}>
<h3 id={headingId} ref={headingRef} tabIndex={-1} className={styles.title}>
<VisuallyHidden>{`Шаг ${position} из ${total}. `}</VisuallyHidden>
{step.label}
</h3>
{description ? <div className={styles.description}>{description}</div> : null}
</header>
<div className={styles.body}>{children}</div>
</section>
);
}
type FormStepFooterProps = {
back?: ReactNode;
children: ReactNode;
};
/** Navigation under the steps: back on the left, the forward actions on the right. */
export function FormStepFooter({ back, children }: FormStepFooterProps) {
return (
<div className={styles.footer}>
<div className={styles["footer-back"]}>{back}</div>
<div className={styles["footer-forward"]}>{children}</div>
</div>
);
}
type ReviewBlockProps = {
title: string;
editLabel: string;
onEdit: () => void;
disabled?: boolean;
children: ReactNode;
};
/** A block of the review step with a way back to the step that owns it. */
export function ReviewBlock({ title, editLabel, onEdit, disabled, children }: ReviewBlockProps) {
const headingId = useId();
return (
<section className={styles.review} aria-labelledby={headingId}>
<div className={styles["review-header"]}>
<h4 id={headingId} className={styles["review-title"]}>
{title}
</h4>
<button
type="button"
className={styles.edit}
disabled={disabled}
aria-label={`Изменить: ${editLabel}`}
onClick={onEdit}
>
Изменить
</button>
</div>
{children}
</section>
);
}
@@ -1,12 +1,12 @@
.form {
display: grid;
gap: var(--space-6);
gap: var(--space-5);
min-width: 0;
}
.editor-fields {
display: grid;
gap: var(--space-6);
gap: var(--space-5);
min-width: 0;
margin: 0;
padding: 0;
@@ -24,53 +24,25 @@
.issue-summary {
min-width: 0;
padding: var(--space-4);
border: var(--line-strong) solid var(--color-danger);
border-radius: var(--radius-m);
background: var(--color-surface);
border-radius: var(--radius-s);
}
.issue-summary h2,
.categories h2 {
.issue-list {
display: grid;
gap: var(--space-1);
margin: 0;
font-size: var(--font-size-l);
}
.issue-summary ul,
.categories ul {
margin: var(--space-3) 0 0;
padding-left: var(--space-5);
}
.group {
display: grid;
gap: var(--space-4);
min-width: 0;
margin: 0;
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-m);
}
.group legend {
max-width: 100%;
padding-inline: var(--space-2);
font-size: var(--font-size-l);
font-weight: var(--font-weight-bold);
overflow-wrap: anywhere;
}
.group-description,
.hint,
.categories p {
margin: 0;
color: var(--color-text-secondary);
line-height: var(--line-height-body);
.issue-step {
color: var(--color-text);
font-weight: var(--font-weight-medium);
}
.field {
display: grid;
gap: var(--space-2);
align-content: start;
min-width: 0;
}
@@ -81,17 +53,17 @@
.field input,
.field select,
.field textarea {
box-sizing: border-box;
width: 100%;
min-width: 0;
max-width: 100%;
min-height: 2.75rem;
padding: 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);
font: inherit;
}
.field input[type="number"],
.field input[type="month"],
.field input[type="tel"] {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
}
.field textarea {
@@ -101,28 +73,9 @@
.field input[aria-invalid="true"],
.field select[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
border-width: var(--line-strong);
border-color: var(--color-danger);
}
.overlap input {
width: 1.25rem;
height: 1.25rem;
margin: 0.125rem 0 0;
}
.overlap input:focus-visible {
outline: var(--line-strong) solid var(--color-focus-ring);
outline-offset: 2px;
}
.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
outline: var(--line-strong) solid var(--color-focus-ring);
outline-offset: 2px;
}
.hint,
.error,
.claim-status {
@@ -130,26 +83,37 @@
line-height: var(--line-height-body);
}
.hint {
color: var(--color-text-secondary);
}
.error {
margin: 0;
color: var(--color-text);
color: var(--color-danger);
font-weight: var(--font-weight-bold);
}
.claim-status {
justify-self: start;
padding: 0 var(--space-2);
border-radius: var(--radius-pill);
color: var(--color-text-secondary);
font-family: var(--font-mono);
font-size: var(--font-size-xs);
background: var(--color-surface-tint);
}
/* A suggestion from a document: a quiet nested note under the field. */
.suggestion {
min-width: 0;
padding: var(--space-2) var(--space-3);
border-inline-start: var(--line-strong) solid var(--color-accent);
background: var(--color-canvas);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-s);
background: var(--color-surface-tint);
overflow-wrap: anywhere;
}
.suggestion summary {
cursor: pointer;
font-size: var(--font-size-s);
font-weight: var(--font-weight-medium);
}
@@ -161,22 +125,24 @@
overflow-wrap: anywhere;
}
/* A repeated row (a role, a workplace): a nested surface inside the panel. */
.item {
display: grid;
gap: var(--space-4);
min-width: 0;
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-m);
border-radius: var(--radius-s);
background: var(--color-canvas);
}
.item-header,
.item-actions,
.list-row,
.actions {
.add-row {
display: flex;
flex-wrap: wrap;
gap: var(--space-3);
gap: var(--space-2) var(--space-3);
align-items: center;
min-width: 0;
}
@@ -185,16 +151,17 @@
justify-content: space-between;
}
.item-header h3,
.list h3,
.overlap-list h3 {
margin: 0;
.item-header h4,
.list h4,
.overlap-list h4,
.categories h4 {
color: var(--color-text-strong);
font-size: var(--font-size-m);
}
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
grid-template-columns: minmax(0, 1fr);
gap: var(--space-4);
min-width: 0;
}
@@ -206,6 +173,11 @@
min-width: 0;
}
.list + .list {
padding-top: var(--space-4);
border-top: var(--line-thin) solid var(--color-divider);
}
.list-row {
align-items: flex-end;
}
@@ -220,11 +192,20 @@
gap: var(--space-3);
align-items: start;
min-width: 0;
padding: var(--space-3);
padding: var(--space-3) var(--space-4);
border: var(--line-thin) solid var(--color-border-strong);
border-radius: var(--radius-s);
}
.overlap:has(input:checked) {
border-color: var(--color-accent);
background: var(--color-accent-tint);
}
.overlap input {
margin-top: 0.2em;
}
.overlap label,
.overlap p {
margin: 0;
@@ -237,40 +218,107 @@
gap: var(--space-2);
min-width: 0;
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-m);
border: var(--line-thin) dashed var(--color-border-hover);
border-radius: var(--radius-s);
}
.actions {
justify-content: space-between;
padding-top: var(--space-2);
.categories p {
color: var(--color-text-secondary);
font-size: var(--font-size-s);
}
.actions > :first-child {
flex: 1 1 12rem;
.category-list,
.review-tags {
display: flex;
flex-wrap: wrap;
gap: var(--space-2) var(--space-3);
align-items: center;
margin: 0;
padding: 0;
list-style: none;
}
@media (width < 48rem) {
.category-list li {
display: flex;
flex-wrap: wrap;
gap: var(--space-2) var(--space-3);
align-items: center;
}
.review {
display: grid;
gap: var(--space-3);
min-width: 0;
}
.review-facts {
display: grid;
gap: var(--space-2);
margin: 0;
}
.review-facts > div {
display: grid;
gap: var(--space-1);
min-width: 0;
}
.review-facts dt,
.review-meta {
color: var(--color-text-secondary);
font-size: var(--font-size-s);
}
.review-facts dd {
min-width: 0;
overflow-wrap: anywhere;
}
.review-list {
display: grid;
gap: var(--space-2);
margin: 0;
padding: 0;
list-style: none;
}
.review-list li {
display: grid;
gap: 0.125rem;
min-width: 0;
}
.review-strong {
color: var(--color-text-strong);
font-weight: var(--font-weight-medium);
overflow-wrap: anywhere;
}
.review-empty {
color: var(--color-text-muted);
font-size: var(--font-size-s);
}
.salary {
color: var(--color-text-strong);
font-family: var(--font-mono);
font-size: 1.125rem;
font-weight: var(--font-weight-bold);
font-variant-numeric: tabular-nums;
}
.salary .review-meta {
font-family: var(--font-text);
font-weight: var(--font-weight-regular);
}
@media (width >= 48rem) {
.grid {
grid-template-columns: minmax(0, 1fr);
}
}
@media (width < 30rem) {
.group {
padding: var(--space-3);
}
.item {
padding: var(--space-3);
}
.actions {
align-items: stretch;
flex-direction: column;
}
.item-actions {
width: 100%;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.review-facts > div {
grid-template-columns: 9rem minmax(0, 1fr);
align-items: baseline;
}
}
@@ -113,4 +113,27 @@ describe("ProfileForm", () => {
);
expect(unconfirmedText).not.toContain("подтверждена ранее");
});
it("walks six steps and keeps the save action on the last one", () => {
const html = renderToString(
<ProfileForm
draft={toCandidateProfileDraft(emptyProfile)}
issues={[]}
isSaving={false}
savingState="idle"
onDraftChange={vi.fn()}
onSubmit={vi.fn()}
/>,
);
expect(html).toContain("Шаг 1 из 6");
for (const step of ["Контакты", "Роли", "Опыт", "Навыки", "Условия", "Проверка"]) {
expect(html).toContain(step);
}
expect(html.match(/<section[^>]*hidden=""/g)).toHaveLength(5);
expect(html).toContain(">Далее<");
expect(html).not.toContain("Сохранить профиль");
// An unsaved profile has no shortcut to the review step.
expect(html).not.toContain("К проверке и сохранению");
});
});
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,66 @@
import { useCallback, useEffect, useRef, useState } from "react";
/* The same hook lives in the questionnaire feature; see form-steps.tsx. */
export type FormStep<TId extends string> = { id: TId; label: string };
/**
* Index of the visible step. Moving to another step moves the focus to its
* heading, so a screen reader starts reading at the new step; the first
* render keeps the focus where it is.
*/
export function useFormSteps<TId extends string>(steps: readonly FormStep<TId>[]) {
const [index, setIndex] = useState(0);
const headings = useRef(new Map<TId, HTMLHeadingElement | null>());
const pendingFocus = useRef(false);
const current = steps[Math.min(index, steps.length - 1)] ?? steps[0];
useEffect(() => {
if (!pendingFocus.current || !current) return;
pendingFocus.current = false;
headings.current.get(current.id)?.focus();
}, [current]);
const goTo = useCallback(
(id: TId) => {
const next = steps.findIndex((step) => step.id === id);
if (next === -1) return;
if (next === index) {
headings.current.get(id)?.focus();
return;
}
pendingFocus.current = true;
setIndex(next);
},
[index, steps],
);
/** Shows a step without moving the focus; safe to call while rendering. */
const show = useCallback(
(id: TId) => {
const next = steps.findIndex((step) => step.id === id);
if (next !== -1) setIndex(next);
},
[steps],
);
return {
index,
current: current as FormStep<TId>,
isFirst: index === 0,
isLast: index === steps.length - 1,
goTo,
show,
next: () => {
const step = steps[index + 1];
if (step) goTo(step.id);
},
back: () => {
const step = steps[index - 1];
if (step) goTo(step.id);
},
headingRef: (id: TId) => (element: HTMLHeadingElement | null) => {
headings.current.set(id, element);
},
};
}