fix(scanner): camera scans used stale first-render handler (welcome mode ignored); feat(admin): un-check-in removes check-in points

- Scanner: invoke onResult through a ref refreshed each render; the camera
  callback captured the mount-time closure, so scans kept running session
  check-in even with the Welcome toggle on (manual entry was unaffected)
- new RPC set_registration_checked_in(id, bool): admin-only; on un-check,
  deletes the event's 'checkin' points_log rows and applies the negative
  delta via _award_points('admin') so leaderboard + audit stay consistent;
  re-check awards nothing; returns points_removed
- admin Registrations toggle now calls the RPC, refreshes rows and toasts
  the removed points
- supabase/tests/set_registration_checked_in_tests.sql: 15 assertions

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:
committed 2026-10-19 10:35:10 +02:00
1 parent 65dcf64c4e
commit 383a80f5ec
6 files changed
+307 -6

No files matched your search

+57
View File
@@ -61,3 +61,60 @@ and still never prints, per the product decision):
changed files — `api.ts`, `types.ts`, `Scan.tsx` — were byte-identical to the
deployed baseline, so whole-file copy was safe). Only `convivo-app` recreated;
admin, sidecar and every unrelated container ID preserved.
---
# Follow-up: camera scans ignored Welcome mode + un-check-in removes points (2026-10-19)
## Symptoms (reported from production)
1. With the "Check-in type" toggle switched to **Welcome**, a camera scan still
produced the *session* result sheet ("Already checked in / No extra points")
and no confirmation popup.
2. Feature request: when an admin flips the **checked-in** toggle OFF in the
admin Registrations view, the points that person earned from check-ins
should be removed too.
## Root cause of (1)
`Scanner` (`apps/convivo/src/components/ui.tsx`) registers the html5-qrcode
success callback once in a `useEffect(…, [])`. That callback captured the
`onResult` prop **from the first render**, so it kept calling a `handleScan`
closure in which `welcomeMode` was still `false` (and the session selector
still empty). Toggling Welcome afterwards had no effect on camera scans — every
scan ran the session branch. The manual-entry field called the *current* prop,
which is why keyboard-driven tests and the earlier smoke test passed.
**Fix:** keep `onResult` in a ref refreshed on every render and invoke
`onResultRef.current(text)` from the camera callback.
## Design of (2)
New admin RPC `set_registration_checked_in(p_registration_id, p_checked_in)`
(`20261019100000_set_registration_checked_in.sql`), the single admin path for
the toggle:
- admin-only (`is_admin()`), locks the registration row;
- sets `checked_in` to the requested value;
- when turning it **off**, sums the attendee's `points_log` rows of category
`checkin` for that event, deletes them, and applies the negative delta
through `_award_points(…, 'admin')` — so the leaderboard mirror and the audit
trail stay consistent (the reversal itself is logged as an `admin` row);
- returns `points_removed`. Re-checking in does **not** re-award points (no
point farming by toggling); the admin `points` column refreshes after the
call and a toast reports the removal.
## Tests
- `supabase/tests/set_registration_checked_in_tests.sql`: **15 assertions** —
un-check removes exactly the checkin points (40 → 10, other categories
untouched), leaderboard syncs, reversal logged once as −30 `admin`,
no-checkin-points un-check is a no-op, re-check awards nothing, unknown id
rejected, non-admin and anon rejected.
- Existing suites re-run clean: leaderboard 46, badge_print 109, rpc_tests.
## Deployment
**Deployed to production 2026-10-19**: migration applied + ledger (40 → 41);
`convivo-app` and `convivo-admin` rebuilt from HEAD behind the drift guard (all
three changed files byte-identical to the deployed baseline).