Files
lincodex/frontend/src/features/assessment-signals/ui/signal-notice.tsx
T

150 lines
5.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useEffect, useRef } from "react";
import { Button } from "../../../shared/ui";
import {
browserSignals,
notCollected,
serverSignals,
type DisclosedSignal,
} from "../model/notice-content";
import styles from "./signal-notice.module.css";
type ContentProps = { headingLevel: "h3" | "h4" };
function SignalList({ signals }: { signals: readonly DisclosedSignal[] }) {
return (
<ul>
{signals.map((signal) => (
<li key={signal.code}>
<strong>{signal.title}.</strong> {signal.detail}
</li>
))}
</ul>
);
}
/**
* The disclosed list, shared by the page summary and the confirmation dialog.
* The heading level follows the heading that precedes it in each place.
*/
export function SignalNoticeContent({ headingLevel }: ContentProps) {
const Heading = headingLevel;
return (
<div className={styles.content}>
<p>
Во время полной проверки собираются технические сигналы. Они помогают назначить ручную
перепроверку и сами по себе не меняют результат, категорию и квоты.
</p>
<Heading>Что фиксирует браузер</Heading>
<p>События сохраняются, только пока действует согласие C3.</p>
<SignalList signals={browserSignals} />
<Heading>Что измеряет сервер</Heading>
<SignalList signals={serverSignals} />
<Heading>Что не собирается</Heading>
<ul>
{notCollected.map((item) => (
<li key={item}>{item}</li>
))}
</ul>
<p>
Адреса и токены сессий не хранятся: для них есть только односторонние отпечатки. Во время
теста сбор ничего не показывает и не блокирует: ввод, вставка и отправка ответов работают
как обычно. Браузерные сигналы легко исказить, а ложные срабатывания возможны, например при
случайном переключении окна, поэтому это только подсказка. Экспресс-тест сигналы не
собирает.
</p>
<p>
Подтверждение хранится на сервере. Оно не заменяет согласие C3, которое управляется отдельно
на странице приватности.
</p>
</div>
);
}
/** Always visible description on the screen where the attempt is started. */
export function SignalNoticeSummary() {
return (
<aside className={styles.summary} aria-labelledby="assessment-signals-title">
<h3 id="assessment-signals-title">Какие данные фиксируются во время проверки</h3>
<SignalNoticeContent headingLevel="h4" />
</aside>
);
}
export type SignalNoticeDialogProps = {
open: boolean;
busy: boolean;
errorMessage: string | null;
onConfirm: () => void;
onClose: () => void;
};
/**
* Modal notice shown before a real attempt starts. It is a native dialog, so
* the browser traps focus inside, closes it with Escape, and returns focus to
* the control that opened it. Closing never confirms anything.
*/
export function SignalNoticeDialog({
open,
busy,
errorMessage,
onConfirm,
onClose,
}: SignalNoticeDialogProps) {
const dialogRef = useRef<HTMLDialogElement>(null);
useEffect(() => {
const dialog = dialogRef.current;
if (!dialog) return;
if (open && !dialog.open) {
dialog.showModal();
// Start at the heading so a screen reader reads the notice before any action.
dialog.querySelector<HTMLElement>("#signal-notice-title")?.focus();
}
if (!open && dialog.open) dialog.close();
}, [open]);
return (
<dialog
ref={dialogRef}
className={styles.dialog}
aria-labelledby="signal-notice-title"
onCancel={(event) => {
// A request in flight finishes first, so a closed notice never hides a stored confirmation.
if (busy) event.preventDefault();
}}
onClose={() => {
// A second Escape can close the dialog even though the first was refused.
// While the confirmation is being saved the dialog stays modal.
const dialog = dialogRef.current;
if (busy && dialog && !dialog.open) {
dialog.showModal();
return;
}
onClose();
}}
>
{open ? (
<>
<h2 id="signal-notice-title" tabIndex={-1} className={styles.title}>
Перед началом: какие сигналы собираются
</h2>
<SignalNoticeContent headingLevel="h3" />
{errorMessage ? (
<p className={styles.error} role="alert">
{errorMessage}
</p>
) : null}
<div className={styles.actions}>
<Button isBusy={busy} onClick={onConfirm}>
{busy ? "Сохраняем подтверждение..." : "Подтверждаю ознакомление и начинаю"}
</Button>
<Button variant="secondary" disabled={busy} onClick={onClose}>
Закрыть без подтверждения
</Button>
</div>
</>
) : null}
</dialog>
);
}