fix(admin): per-row check-in toggle; feat(db): front-desk gate + badge copies
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]>
This commit is contained in:
1 parent
d3531e1fac
commit
17473916a6
27 files changed
+1378
-73
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
import type { Event, PretixOptions, PretixSyncResult, SyncResult } from '../lib/types';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { Empty, Modal, Spinner, Toggle } from '../components/ui';
|
||||
import { BadgeCopiesPicker, clampBadgeCopies } from '../components/BadgeCopiesSetting';
|
||||
import { normalizeSessionizeSource } from '../lib/sessionizeSource';
|
||||
|
||||
export function Events() {
|
||||
@@ -297,6 +298,7 @@ function EventModal({
|
||||
const [pretixError, setPretixError] = useState<string | null>(null);
|
||||
const [realtimeClock, setRealtimeClock] = useState(event?.use_realtime_clock ?? false);
|
||||
const [talkBonus, setTalkBonus] = useState(event?.talk_networking_bonus ?? 2);
|
||||
const [badgeCopies, setBadgeCopies] = useState(event?.badge_copies ?? 1);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const lastFetchedKey = useRef<string | null>(null);
|
||||
|
||||
@@ -353,6 +355,7 @@ function EventModal({
|
||||
pretix_api_key: pretixApiKey.trim() || null,
|
||||
use_realtime_clock: realtimeClock,
|
||||
talk_networking_bonus: Math.max(0, Math.min(10, Math.round(talkBonus) || 0)),
|
||||
badge_copies: clampBadgeCopies(badgeCopies),
|
||||
});
|
||||
onSaved(event ? 'Event updated' : 'Event created');
|
||||
} catch (e) {
|
||||
@@ -537,6 +540,24 @@ function EventModal({
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="field">
|
||||
<div className="row between" style={{ alignItems: 'center', gap: 16, flexWrap: 'wrap' }}>
|
||||
<div>
|
||||
<label id="event-badge-copies-label">Badge copies on welcome check-in</label>
|
||||
<div className="muted small" style={{ marginTop: 2, maxWidth: 420 }}>
|
||||
How many labels print when an attendee is welcomed in at the front desk.
|
||||
Manual reprints from the Registrations view always print one.
|
||||
The same control lives in Settings for the active event.
|
||||
</div>
|
||||
</div>
|
||||
<BadgeCopiesPicker
|
||||
value={clampBadgeCopies(badgeCopies)}
|
||||
onChange={setBadgeCopies}
|
||||
disabled={busy}
|
||||
labelId="event-badge-copies-label"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -41,12 +41,15 @@ export function Registrations() {
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [qrFor, setQrFor] = useState<Registration | null>(null);
|
||||
const [sponsorFor, setSponsorFor] = useState<Registration | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [deletingAll, setDeletingAll] = useState(false);
|
||||
const [mergeFor, setMergeFor] = useState<Registration | null>(null);
|
||||
const [badgeFor, setBadgeFor] = useState<Registration | null>(null);
|
||||
const [badgeLayouts, setBadgeLayouts] = useState<BadgeLayout[]>([]);
|
||||
const [printingIds, setPrintingIds] = useState<Set<string>>(new Set());
|
||||
// Rows with a write in flight (check-in toggle or pass-type change). Per-row
|
||||
// instead of one global flag: a slow request must never freeze the whole
|
||||
// table, and it must be obvious WHICH row is working.
|
||||
const [busyIds, setBusyIds] = useState<Set<string>>(new Set());
|
||||
const { overview: printOverview } = usePrintStatus();
|
||||
// Aggregated printer state, used only to phrase the enqueue toast honestly.
|
||||
const printerState = aggregateState(activeStations(printOverview));
|
||||
@@ -174,43 +177,66 @@ export function Registrations() {
|
||||
const ticketOptions = ynOptions(searched.filter((r) => passType(r) && passCheckedIn(r)), hasTicket);
|
||||
const checkedInOptions = ynOptions(searched.filter((r) => passType(r) && passTicket(r)), (r) => r.checked_in);
|
||||
|
||||
async function changeType(r: Registration, type: RegistrationType) {
|
||||
setBusy(true);
|
||||
// Run a per-row write: mark that row busy, and clear it when settled. Only
|
||||
// the touched row is disabled — the rest of the table stays usable.
|
||||
async function withRowBusy(id: string, run: () => Promise<void>) {
|
||||
if (busyIds.has(id)) return;
|
||||
setBusyIds((ids) => new Set(ids).add(id));
|
||||
try {
|
||||
await setRegistrationType(r.contact_email, type);
|
||||
await reloadRegistrations(r.event_id);
|
||||
push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email} → ${type}`);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Update failed';
|
||||
// A sponsor registration needs a sponsor lookup — open the in-place
|
||||
// sponsor popup instead of just failing.
|
||||
if (type === 'sponsor' && /sponsor lookup/i.test(msg)) {
|
||||
setSponsorFor(r);
|
||||
} else {
|
||||
push('error', msg);
|
||||
}
|
||||
await run();
|
||||
} finally {
|
||||
setBusy(false);
|
||||
setBusyIds((ids) => {
|
||||
const next = new Set(ids);
|
||||
next.delete(id);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleCheckedIn(r: Registration, v: boolean) {
|
||||
setBusy(true);
|
||||
setRegistrations((rows) => rows.map((row) => row.id === r.id ? { ...row, checked_in: v } : row));
|
||||
try {
|
||||
const removed = await setCheckedIn(r.id, v);
|
||||
if (removed > 0) {
|
||||
push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email}: un-checked in, −${removed} check-in pts removed`);
|
||||
async function changeType(r: Registration, type: RegistrationType) {
|
||||
await withRowBusy(r.id, async () => {
|
||||
try {
|
||||
await setRegistrationType(r.contact_email, type);
|
||||
// Update the row in place — a full reload would reorder the table and
|
||||
// make the row you just touched jump somewhere else.
|
||||
setRegistrations((rows) => rows.map((row) => (row.id === r.id ? { ...row, type } : row)));
|
||||
push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email} → ${type}`);
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : 'Update failed';
|
||||
// A sponsor registration needs a sponsor lookup — open the in-place
|
||||
// sponsor popup instead of just failing.
|
||||
if (type === 'sponsor' && /sponsor lookup/i.test(msg)) {
|
||||
setSponsorFor(r);
|
||||
} else {
|
||||
push('error', msg);
|
||||
}
|
||||
}
|
||||
// The RPC may have changed this attendee's points — refresh so the
|
||||
// points column and leaderboard stay truthful.
|
||||
await reloadRegistrations(r.event_id);
|
||||
} catch (e) {
|
||||
setRegistrations((rows) => rows.map((row) => row.id === r.id ? { ...row, checked_in: r.checked_in } : row));
|
||||
push('error', e instanceof Error ? e.message : 'Update failed');
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function toggleCheckedIn(r: Registration, v: boolean) {
|
||||
await withRowBusy(r.id, async () => {
|
||||
// Optimistically flip just this row's checkbox; the row keeps its place.
|
||||
setRegistrations((rows) => rows.map((row) => (row.id === r.id ? { ...row, checked_in: v } : row)));
|
||||
try {
|
||||
const removed = await setCheckedIn(r.id, v);
|
||||
// Patch this row's points from the RPC's own number. We deliberately do
|
||||
// NOT reload the list: it is sorted by points, so a reload moves the row
|
||||
// you just toggled somewhere else on every click.
|
||||
setRegistrations((rows) => rows.map((row) => (row.id === r.id
|
||||
? { ...row, checked_in: v, points: Math.max(0, row.points - removed) }
|
||||
: row)));
|
||||
const name = byEmail.get(r.contact_email)?.full_name ?? r.contact_email;
|
||||
if (removed > 0) push('success', `${name}: un-checked in, −${removed} check-in pts removed`);
|
||||
else push('success', `${name}: ${v ? 'checked in' : 'un-checked in'}`);
|
||||
} catch (e) {
|
||||
// Revert to the committed state — never leave the checkbox lying.
|
||||
setRegistrations((rows) => rows.map((row) => (row.id === r.id
|
||||
? { ...row, checked_in: r.checked_in, points: r.points }
|
||||
: row)));
|
||||
push('error', e instanceof Error ? e.message : 'Update failed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Queue this attendee's badge. Works while the printer is offline/error —
|
||||
@@ -272,7 +298,7 @@ export function Registrations() {
|
||||
className="input"
|
||||
style={{ maxWidth: 280 }}
|
||||
value={selectedId}
|
||||
disabled={busy || mergeFor !== null}
|
||||
disabled={mergeFor !== null}
|
||||
onChange={(e) => setSelectedId(e.target.value)}
|
||||
>
|
||||
{events.map((e) => (
|
||||
@@ -312,8 +338,9 @@ export function Registrations() {
|
||||
<tbody>
|
||||
{filtered.map((r) => {
|
||||
const c = byEmail.get(r.contact_email);
|
||||
const rowBusy = busyIds.has(r.id);
|
||||
return (
|
||||
<tr key={r.id}>
|
||||
<tr key={r.id} className={rowBusy ? 'row-busy' : undefined}>
|
||||
<td>
|
||||
<div className="cell-person">
|
||||
<Avatar name={c?.full_name ?? r.contact_email} id={r.contact_email} size={38} fs={13} />
|
||||
@@ -330,7 +357,7 @@ export function Registrations() {
|
||||
className="input"
|
||||
style={{ width: 130, padding: '6px 10px', fontSize: 12.5 }}
|
||||
value={r.type}
|
||||
disabled={busy}
|
||||
disabled={rowBusy}
|
||||
onChange={(e) => changeType(r, e.target.value as RegistrationType)}
|
||||
>
|
||||
{TYPES.map((t) => (
|
||||
@@ -370,14 +397,19 @@ export function Registrations() {
|
||||
</Tooltip>
|
||||
)}
|
||||
{!r.qr_token?.trim() && r.import_source === 'sessionize' && (
|
||||
<button className="btn small" disabled={busy} onClick={() => setMergeFor(r)}>
|
||||
<button className="btn small" onClick={() => setMergeFor(r)}>
|
||||
Merge tickets
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<Toggle checked={r.checked_in} disabled={busy} onChange={(v) => toggleCheckedIn(r, v)} />
|
||||
<div className="row" style={{ gap: 8 }}>
|
||||
<Toggle checked={r.checked_in} disabled={rowBusy} onChange={(v) => toggleCheckedIn(r, v)} />
|
||||
{/* Per-row in-flight affordance: the switch is optimistic,
|
||||
so show that the save is still travelling. */}
|
||||
{rowBusy && <span className="row-saving" data-testid={`saving-${r.id}`}>Saving…</span>}
|
||||
</div>
|
||||
</td>
|
||||
<td style={{ textAlign: 'right' }}>
|
||||
<span className="pts">{r.points}</span>
|
||||
@@ -456,9 +488,13 @@ export function Registrations() {
|
||||
contact={byEmail.get(sponsorFor.contact_email)}
|
||||
eventId={event.id}
|
||||
onClose={() => setSponsorFor(null)}
|
||||
onSaved={async (msg) => {
|
||||
onSaved={(msg) => {
|
||||
// The modal sets the registration type to sponsor; mirror it on the
|
||||
// row. (Reloading events here never refreshed the rows, which left
|
||||
// the type badge showing the old value.)
|
||||
const savedId = sponsorFor.id;
|
||||
setRegistrations((rows) => rows.map((row) => (row.id === savedId ? { ...row, type: 'sponsor' } : row)));
|
||||
setSponsorFor(null);
|
||||
await load();
|
||||
push('success', msg);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useEffect, useState, type FormEvent } from 'react';
|
||||
import { Save } from 'lucide-react';
|
||||
import { getLlmSettings, saveLlmSettings } from '../lib/api';
|
||||
import { getActiveEvent, getLlmSettings, saveLlmSettings } from '../lib/api';
|
||||
import type { Event } from '../lib/types';
|
||||
import { Spinner } from '../components/ui';
|
||||
import { BadgeCopiesSetting } from '../components/BadgeCopiesSetting';
|
||||
|
||||
export function Settings() {
|
||||
const [endpoint, setEndpoint] = useState('');
|
||||
@@ -13,6 +15,8 @@ export function Settings() {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
// Badge printing is per event, so it follows the active event.
|
||||
const [activeEvent, setActiveEvent] = useState<Event | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
@@ -23,6 +27,11 @@ export function Settings() {
|
||||
setHasKey(settings.has_api_key);
|
||||
setLoaded(true);
|
||||
}).catch(cause => { if (active) setError(cause instanceof Error ? cause.message : 'Failed to load settings'); });
|
||||
// Best-effort: a failure here just hides the badge section, it must not
|
||||
// break the Feedback AI settings below.
|
||||
getActiveEvent()
|
||||
.then(event => { if (active) setActiveEvent(event); })
|
||||
.catch(() => { if (active) setActiveEvent(null); });
|
||||
return () => { active = false; };
|
||||
}, []);
|
||||
|
||||
@@ -47,6 +56,12 @@ export function Settings() {
|
||||
<div className="page-head"><h1>Settings</h1></div>
|
||||
{error && <p className="feedback-error" role="alert">{error}</p>}
|
||||
{!loaded && !error && <Spinner />}
|
||||
{activeEvent && (
|
||||
<section className="settings-section" aria-labelledby="badge-printing-h" data-testid="settings-badge-printing">
|
||||
<h2 className="h2" id="badge-printing-h">Badge printing</h2>
|
||||
<BadgeCopiesSetting eventId={activeEvent.id} initialCopies={activeEvent.badge_copies ?? 1} eventName={activeEvent.name} />
|
||||
</section>
|
||||
)}
|
||||
{loaded && <form className="llm-settings" onSubmit={save} onChange={() => setSaved(false)}>
|
||||
<h2 className="h2">Feedback AI</h2>
|
||||
<div className="field">
|
||||
|
||||
Reference in new issue
Block a user