Registrations table felt buggy because both row actions did setBusy(true) -> write -> reloadRegistrations() -> setBusy(false): the list is sorted by points, so a reload made the row you just touched jump (or vanish under a Checked-in filter), and the single `busy` flag disabled every control in the table for the whole request. The fix is per-row in-flight state (busyIds + withRowBusy) and no reload at all: the toggle patches its own row's checked_in plus the points delta the RPC returns, the type change patches `type`; a rejected write rolls both back. Only the touched row is disabled, shows a "Saving…" pulse, and two rows can save at once. Toggle hit area is now 40x41 px with a focus-visible ring. Front-desk gate: checkin_attendee reads registrations.checked_in and raises "This attendee needs to be checked in at the front desk first." when it is not true, and no longer sets checked_in as a side effect. checkins has no INSERT policy, so the RPC is the only write path and the gate cannot be bypassed. The scanner shows a dedicated "Not checked in yet" sheet instead of a toast. Badge copies: events.badge_copies (1..4, default 1). welcome_checkin sends that many pgmq jobs in one transaction (the Pi prints one label per job, so N jobs = N labels; no worker change) and clamps the value again itself. preview_welcome_checkin gained a `copies` column (drop + recreate) so the popup states the real count. Manual reprint still prints exactly one. Set from Settings -> Badge printing (active event) and the Events form, always as a single-column update; the Settings badge section now renders even when the LLM settings call fails. Tests: badge_print 113 (+6), leaderboard 47 (+1), new registration-checkin-toggle (6), front-desk-gate (3), welcome-badge-copies (3); the stale registrations-PATCH mock in registration-ticket-merge now targets set_registration_checked_in, the ambiguous Save button is "Save copies", and the print-copy assertion tolerates the typographic apostrophe. Docs updated (rpcs, schema, printing, tests, admin-app, screens) with a release record; NOT deployed - see docs/releases/2026-10-19.md. Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
109 lines
3.8 KiB
TypeScript
109 lines
3.8 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { setBadgeCopies } from '../lib/api';
|
|
|
|
/** Number of labels a welcome check-in can print, per the DB check constraint. */
|
|
export const BADGE_COPIES_MIN = 1;
|
|
export const BADGE_COPIES_MAX = 4;
|
|
|
|
export function clampBadgeCopies(n: number): number {
|
|
return Number.isFinite(n) ? Math.max(BADGE_COPIES_MIN, Math.min(BADGE_COPIES_MAX, Math.round(n))) : BADGE_COPIES_MIN;
|
|
}
|
|
|
|
/**
|
|
* Presentational 1..4 picker. Two consumers on purpose:
|
|
* - the Events form holds this in its own state, so Cancel still cancels;
|
|
* - `BadgeCopiesSetting` wraps it for the Settings view, which saves at once.
|
|
*/
|
|
export function BadgeCopiesPicker({ value, onChange, disabled = false, labelId }: {
|
|
value: number;
|
|
onChange: (v: number) => void;
|
|
disabled?: boolean;
|
|
labelId?: string;
|
|
}) {
|
|
return (
|
|
<div className="seg seg-num" role="group" aria-labelledby={labelId} data-testid="badge-copies">
|
|
{[1, 2, 3, 4].map((n) => (
|
|
<button
|
|
key={n}
|
|
type="button"
|
|
className={value === n ? 'active' : ''}
|
|
aria-pressed={value === n}
|
|
disabled={disabled}
|
|
onClick={() => onChange(n)}
|
|
>
|
|
{n}
|
|
</button>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const HELP = 'How many labels print when an attendee is welcomed in at the front desk';
|
|
|
|
/**
|
|
* Badge copies on welcome check-in (1..4, default 1) for one event.
|
|
* `events.badge_copies` drives `welcome_checkin`, which enqueues that many
|
|
* labels; a manual reprint from Registrations always prints one.
|
|
*
|
|
* Saves immediately through `setBadgeCopies` — a scoped single-column update,
|
|
* so it can never overwrite another event field the rest of the UI holds stale.
|
|
*/
|
|
export function BadgeCopiesSetting({ eventId, initialCopies, eventName }: {
|
|
eventId: string;
|
|
initialCopies: number;
|
|
eventName?: string;
|
|
}) {
|
|
const [copies, setCopies] = useState(clampBadgeCopies(initialCopies));
|
|
const [saved, setSaved] = useState<number | null>(clampBadgeCopies(initialCopies));
|
|
const [committed, setCommitted] = useState(false);
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
// Follow the event when the caller switches to a different one.
|
|
useEffect(() => {
|
|
const next = clampBadgeCopies(initialCopies);
|
|
setCopies(next);
|
|
setSaved(next);
|
|
setCommitted(false);
|
|
setError(null);
|
|
}, [eventId, initialCopies]);
|
|
|
|
const dirty = copies !== saved;
|
|
|
|
async function save() {
|
|
if (busy || !dirty) return;
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
await setBadgeCopies(eventId, copies);
|
|
setSaved(copies);
|
|
setCommitted(true);
|
|
} catch (e) {
|
|
setError(e instanceof Error ? e.message : 'Could not save');
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="field">
|
|
<div className="row between" style={{ alignItems: 'center', gap: 16, flexWrap: 'wrap' }}>
|
|
<div>
|
|
<label id="badge-copies-label">Badge copies on welcome check-in</label>
|
|
<div className="muted small" style={{ marginTop: 2, maxWidth: 460 }}>
|
|
{HELP}{eventName ? <> for <b>{eventName}</b></> : null}. Manual reprints from the
|
|
Registrations view always print one.
|
|
</div>
|
|
</div>
|
|
<div className="row" style={{ gap: 10, alignItems: 'center' }}>
|
|
<BadgeCopiesPicker value={copies} onChange={setCopies} disabled={busy} labelId="badge-copies-label" />
|
|
<button className="btn" type="button" disabled={busy || !dirty} onClick={save} data-testid="badge-copies-save">
|
|
{busy ? 'Saving…' : dirty ? 'Save copies' : committed ? 'Copies saved' : 'Save copies'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
{error && <p className="feedback-error" role="alert" style={{ marginTop: 8 }}>{error}</p>}
|
|
</div>
|
|
);
|
|
}
|