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:
1 parent
c857204cfe
commit
c49a94fe80
27 files changed
+1378
-73
No files matched your search
@@ -159,3 +159,166 @@ Badge queued correctly; test data cleaned afterwards.
|
||||
|
||||
**Deployed to production 2026-10-19**: attendee app only (`convivo-app`
|
||||
rebuilt; no migration, admin/sidecar untouched).
|
||||
|
||||
---
|
||||
|
||||
# Follow-up: Registrations toggle feels buggy; front-desk gate; badge copies (2026-10-19)
|
||||
|
||||
## Symptoms (reported from production)
|
||||
|
||||
1. The admin **Registrations** table "feels buggy", especially when checking
|
||||
someone in or out.
|
||||
2. Request: nobody should be scannable into a **session** before the front desk
|
||||
has checked them in — and the app should say so.
|
||||
3. Request: an admin setting for **how many badge copies** a welcome check-in
|
||||
prints (default 1, up to 4).
|
||||
|
||||
## Root cause of (1)
|
||||
|
||||
Not a render bug — a regression the previous change introduced, **and it was
|
||||
never deployed**, which is why "it doesn't work" at all.
|
||||
|
||||
Commit `316f131` (un-check-in removes points) made both row actions do:
|
||||
|
||||
```
|
||||
setBusy(true) → write → await reloadRegistrations(event_id) → setBusy(false)
|
||||
```
|
||||
|
||||
Two things went wrong from there:
|
||||
|
||||
- The list is **sorted by points**. Reloading after a toggle re-sorts it, so the
|
||||
row you just clicked *moves*, and with a **Checked in** filter applied it
|
||||
disappears entirely. Clicking the same place again hits a different person.
|
||||
- `busy` was **one flag for the whole table**, so during every request the event
|
||||
selector, every type dropdown, every checkbox and the Merge buttons all went
|
||||
dead at once, with no indication of which row was working. A second click in
|
||||
that window either did nothing or fired a second write for the same row.
|
||||
|
||||
**Fix** (`apps/admin/src/views/Registrations.tsx`):
|
||||
|
||||
- `busyIds: Set<string>` + a `withRowBusy(id, run)` helper — **per-row** in
|
||||
flight state. Only the touched row's control is disabled; it gets a
|
||||
`.row-busy` background and a "Saving…" pulse (`data-testid="saving-<id>"`,
|
||||
motion-respecting). Other rows stay live, and two rows can be saved at the
|
||||
same time. A double click on the same row is ignored while its write runs.
|
||||
- **No reload.** The toggle patches its own row — `checked_in` plus the points
|
||||
delta the RPC itself returns (`points_removed`) — and the type change patches
|
||||
`type` (`set_registration_type` only mutates that column, and the sponsor
|
||||
lookup modal's `onSaved` now patches to `sponsor` instead of reloading). Rows
|
||||
therefore keep their place; the leaderboard and totals are untouched because
|
||||
the server is the source of truth either way.
|
||||
- Rollback on failure restores **both** `checked_in` and `points` from the row
|
||||
that was clicked, so the checkbox never lies.
|
||||
|
||||
Accessibility/ergonomics in the same pass (`apps/admin/src/styles.css`): the
|
||||
toggle's hit area is now 40×41 px (`padding: 9px 0; margin: -9px 0`) instead of
|
||||
the bare track, the hidden checkbox gets a `:focus-visible` ring on the track,
|
||||
and a disabled track reads as disabled.
|
||||
|
||||
## Design of (2) — the front-desk gate
|
||||
|
||||
`checkin_attendee` now reads the attendee's `registrations.checked_in` and
|
||||
raises **`This attendee needs to be checked in at the front desk first.`** when
|
||||
it is not `true`. It also **stopped setting `checked_in = true` as a side
|
||||
effect**, which is what let a session scan make someone "checked in to the
|
||||
event" without anyone welcoming them. The welcome check-in (and the admin
|
||||
Registrations toggle, i.e. the front desk acting from the console) are now the
|
||||
only ways to earn that flag.
|
||||
|
||||
Enforced in the database on purpose: `checkins` has **no INSERT policy**, so the
|
||||
RPC is the only write path and the gate cannot be bypassed from the API.
|
||||
|
||||
The scanner (`apps/convivo/src/screens/Scan.tsx`) treats this as a *state*, not
|
||||
a transient error: instead of a toast it opens its own sheet — **🛑 "Not checked
|
||||
in yet" / "This attendee needs to be checked in at the front desk before they
|
||||
can be scanned into a session."** with **OK** (`data-testid="front-desk-required"`
|
||||
/ `front-desk-ok`). The camera stays paused behind it and re-arms on **OK**.
|
||||
|
||||
## Design of (3) — badge copies
|
||||
|
||||
- New column `events.badge_copies` `integer not null default 1
|
||||
check (badge_copies between 1 and 4)`. Per-event is the right data model; the
|
||||
setting is surfaced in **Settings → Badge printing** for the active event
|
||||
because that is where admins expect one global knob, and also on the Events
|
||||
form.
|
||||
- `welcome_checkin` builds the payload once and calls `pgmq.send` **N times** in
|
||||
the same transaction. The Pi worker prints exactly one label per job, so
|
||||
**N jobs = N labels** and nothing in `apps/printer` changed. The value is
|
||||
clamped again inside the function (`greatest(1, least(4, …))`) so a
|
||||
hand-edited row cannot flood the queue.
|
||||
- `preview_welcome_checkin` gained a **`copies`** column (drop + recreate — the
|
||||
return type changed, and Postgres refuses `create or replace` across that), so
|
||||
the confirmation popup tells the truth: *"you will print their badge 3 times"*
|
||||
instead of a fixed *"this person's label"*. `copies` is `0` when nothing would
|
||||
print.
|
||||
- **Manual reprint (`enqueue_badge_print`) still prints exactly one label** —
|
||||
reprinting a lost badge must not produce a stack.
|
||||
- Saving uses `setBadgeCopies(eventId, copies)`, a **single-column** update, so
|
||||
it can never clobber the rest of the event row. The picker is
|
||||
`components/BadgeCopiesSetting.tsx` (shared segmented 1–4 control + the
|
||||
self-saving card with a "Copies saved" confirmation). The Settings view loads
|
||||
the active event **independently of** `getLlmSettings()`, so the badge section
|
||||
still renders when the LLM/sidecar call fails.
|
||||
|
||||
## Tests
|
||||
|
||||
- `supabase/tests/badge_print_tests.sql`: **+6 assertions → 113** — gate refuses
|
||||
an un-welcomed session scan; `badge_copies = 3` queues three more labels; the
|
||||
savepoint restores the queue to one; `preview.copies` = `1` / `0` / `3`. The
|
||||
pre-existing session-check-in case now sets `checked_in` first, since the gate
|
||||
made it a precondition.
|
||||
- `supabase/tests/leaderboard_tests.sql`: **+1 assertion → 47**, fixtures
|
||||
checked-in (plus a fresh, un-checked-in attendee to drive the gate).
|
||||
- `supabase/tests/rpc_tests.sql`: fixtures checked-in so the session path is
|
||||
reachable.
|
||||
- New `e2e/tests/registration-checkin-toggle.spec.ts` — **6** mocked-admin tests:
|
||||
toggle fires exactly one request and **zero refetches**, row order unchanged,
|
||||
the busy row shows "Saving…" with its checkbox disabled while other rows stay
|
||||
enabled, a second row saves concurrently, un-check reports `−30`, a rejected
|
||||
write rolls back, type change without refetch, and the Settings picker
|
||||
persisting 1–4.
|
||||
- New `e2e/tests/front-desk-gate.spec.ts` — **3** real-browser tests
|
||||
(CONV-GATE-001..003): the refusal sheet with **no check-in recorded**, the same
|
||||
scan succeeding after the welcome, and a session check-in not setting the
|
||||
event flag by itself.
|
||||
- New `e2e/tests/welcome-badge-copies.spec.ts` — **3** real-browser tests
|
||||
(CONV-COPIES-001..003): `badge_copies = 3` → exactly 3 queue messages for that
|
||||
attendee, `1` → 1 with the singular wording, re-welcome → **+0**.
|
||||
- `e2e/tests/registration-ticket-merge.spec.ts` (pre-existing, **broken by
|
||||
`316f131`**): its rollback test mocked a `registrations` PATCH the toggle
|
||||
stopped using when it moved to `set_registration_checked_in`; the mock now
|
||||
targets the RPC, so the test exercises what the UI actually calls.
|
||||
- Also fixed by this work: `feedback-ai-summary.spec.ts` was picking up an
|
||||
ambiguous `Save` button once the badge card added one — the card's button is
|
||||
labelled **"Save copies" / "Copies saved"**, which resolves the collision for
|
||||
both screen-reader users and the test. `checkin-attendee.spec.ts`'s print-copy
|
||||
assertion now tolerates the typographic apostrophe in the popup text.
|
||||
- Pre-existing, **not** caused by this change set: `session-checkin.spec.ts`,
|
||||
`checkin-attendee.spec.ts` and `rpc_tests.sql` still fail locally because the
|
||||
seeded demo identities (`CVV-ATT-1000`…`CVV-ATT-1005`, the `37ab7060-…`
|
||||
session) no longer exist — pretix-imported data replaced them. The identical 8
|
||||
`rpc_tests` failures occur at HEAD, and the same specs failed with everything
|
||||
stashed. The new specs deliberately provision their own fixtures so they do
|
||||
not depend on that drift; the fixtures should be re-seeded separately.
|
||||
- Both apps typecheck clean and build (`admin` `index-DSNhW0mZ.js`,
|
||||
`convivo` `index-CXd2kxEv.js`, print `print-CaBuVVFf.js`).
|
||||
|
||||
## Deployment
|
||||
|
||||
**Not deployed.** Production is still missing everything from this change set:
|
||||
`events.badge_copies` does not exist, `checkin_attendee` has no gate,
|
||||
`welcome_checkin` prints one label, and `admin.appe.at` serves the pre-fix
|
||||
bundle `index-Czkxg0C-.js` (which is exactly the reload-everything behaviour
|
||||
described above). `set_registration_checked_in` already exists there with the
|
||||
same signature, so the migration will not conflict.
|
||||
|
||||
**One data consequence to decide on before shipping:** in production 2 people
|
||||
already have session check-ins without `checked_in = true`, so the gate would
|
||||
lock 1 of them out of further session scans until the front desk welcomes them.
|
||||
Either backfill `checked_in = true` for anyone with an existing check-in as part
|
||||
of the rollout, or accept that the front desk re-welcomes them (they print a
|
||||
badge on the way back through).
|
||||
|
||||
To ship: apply `20261019110000_front_desk_gate_and_badge_copies.sql` (records
|
||||
41 → 42), rebuild `convivo-app` **and** `convivo-admin`, then re-run the suites
|
||||
above against prod.
|
||||
Reference in new issue
Block a user