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.
This commit is contained in:
Lago committed 2026-10-19 15:10:20 +02:00
1 parent c857204cfe
commit c49a94fe80
27 files changed
+1378 -73

No files matched your search

+11 -8
View File
@@ -7,7 +7,7 @@ const targetId = '22222222-2222-4222-8222-222222222222';
const otherId = '33333333-3333-4333-8333-333333333333';
const manualId = '44444444-4444-4444-8444-444444444444';
async function openRegistrations(page: Page, options: { patchFailure?: boolean; mergeFailure?: boolean } = {}) {
async function openRegistrations(page: Page, options: { checkinFailure?: boolean; mergeFailure?: boolean } = {}) {
const user = { id: '99999999-9999-4999-8999-999999999999', email: '[email protected]', aud: 'authenticated', role: 'authenticated', app_metadata: {}, user_metadata: {} };
const payload = Buffer.from(JSON.stringify({ sub: user.id, exp: Math.floor(Date.now() / 1000) + 3600 })).toString('base64url');
const session = { user, access_token: `eyJhbGciOiJIUzI1NiJ9.${payload}.test`, refresh_token: 'mock-refresh-token', expires_in: 3600, token_type: 'bearer' };
@@ -43,13 +43,16 @@ async function openRegistrations(page: Page, options: { patchFailure?: boolean;
}
if (table === 'contacts') return route.fulfill({ json: url.searchParams.has('email') ? contacts[0] : contacts });
if (table === 'events') return route.fulfill({ json: url.searchParams.has('is_active') ? event : [event] });
// The check-in toggle goes through the set_registration_checked_in RPC
// (the single admin path — it also reverses check-in points), not a PATCH.
if (table === 'set_registration_checked_in') {
const body = route.request().postDataJSON() as { p_registration_id: string; p_checked_in: boolean };
if (options.checkinFailure) return route.fulfill({ status: 500, json: { message: 'Check-in failed' } });
const row = registrations.find((r) => r.id === body.p_registration_id);
registrations = registrations.map(r => r.id === body.p_registration_id ? { ...r, checked_in: body.p_checked_in } : r);
return route.fulfill({ json: [{ registration_id: body.p_registration_id, checked_in: body.p_checked_in, points_removed: 0 }] });
}
if (table === 'registrations') {
if (route.request().method() === 'PATCH') {
if (options.patchFailure) return route.fulfill({ status: 500, json: { message: 'Check-in failed' } });
const id = url.searchParams.get('id')!.replace('eq.', '');
registrations = registrations.map(row => row.id === id ? { ...row, ...route.request().postDataJSON() } : row);
return route.fulfill({ json: { id } });
}
return route.fulfill({ json: registrations });
}
return route.fulfill({ json: [] });
@@ -71,7 +74,7 @@ test('counts only QR tickets and check-in slides without refresh', async ({ page
});
test('failed check-in rolls the toggle back', async ({ page }) => {
await openRegistrations(page, { patchFailure: true });
await openRegistrations(page, { checkinFailure: true });
const row = page.getByRole('row').filter({ hasText: '[email protected]' });
await row.locator('label.toggle').click();
await expect(page.getByText('Check-in failed', { exact: true })).toBeVisible();