"use client"; import * as React from "react"; import { HistoryIcon, Loader2Icon } from "lucide-react"; import type { NewerStatementResult, StatementAuditSnapshot, } from "@accessibit/types"; import { useSiteAdmin } from "../context"; import { fill, fillFor } from "../lib/fill"; import { Button } from "../ui/button"; import { Notice } from "../ui/notice"; const DAY: Intl.DateTimeFormatOptions = { year: "numeric", month: "short", day: "numeric", }; /** * "C'è un risultato più recente" (ACC-571, C1 boards): the site has an audit * or a Tracker check newer than the one the published statement declares. * Whether it does is the host server's (the dashboard's * `statementNewerResult.ts`; WordPress computes none); this only says * so, naming both runs the way the facts do: the one the published document * declares, and the one the next publication would. While it is up, the facts * call theirs "Prossima pubblicazione basata su", so the two never read as * the same run. A published run pruned since is "un risultato precedente". * * Informational, not a warning: the published statement is still a valid * declaration of the run it names. Publishing again is the customer's call — * the page never rewrites a legal document on its own — so the action is the * page's own save-and-publish, nothing new behind it, and it carries the same * label, progress included ("Salvataggio…", "Generazione…"). Once it lands * the server finds nothing newer and the notice goes; the page puts the focus * back (`StatementPage`). * * A `status` (the `Notice`'s own), drawn once the statement has been read and * gone once it is republished: read out once as it appears, not on every * render, and its title is a paragraph like every other notice on the page. */ export function StatementNewerResultNotice({ result, onPublish, label, busy = false, disabled = busy, }: { /** The newer run, and the one the published statement declares. */ result: NewerStatementResult; /** The page's save-and-publish. */ onPublish: () => void; /** * The main button's label, which follows the save's phase. Defaults to * "Salva e pubblica", the label of the same action on a published * statement, when nothing is running. */ label?: string; /** * The page is saving or generating the statement, from whichever button: * the spinner follows the page-wide save, as the main button's does. */ busy?: boolean; /** * The page cannot publish right now — busy, still reading, or publishing * the temporary statement — so the button waits. Apart from `busy` only so * the temporary statement's publication does not spin it (ACC-571). */ disabled?: boolean; }) { const { messages, locale: lang, format } = useSiteAdmin(); const t = messages.statement.notices; const facts = messages.statement.facts; // The page's own label for the same action: on a published statement the // main button reads "Salva e pubblica", and it publishes unsaved edits too. const actionLabel = label ?? messages.statement.form.actions.saveAndPublish; const name = ( basis: Pick< StatementAuditSnapshot["basedOn"], "kind" | "source" | "completedAt" >, ) => fillFor(lang, facts.basis[basis.source ?? basis.kind], { date: format.customerDate(basis.completedAt, DAY), }); return ( { if (disabled) return; onPublish(); }} > {busy && ); }