Files
Convivo/docs/releases/2026-10-19.md
T
Lago 316f1316e6 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
2026-10-19 10:35:10 +02:00

121 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Welcome Check-In Confirmation (2026-10-19)
## Symptom
At the welcome desk, a staff member scanned an attendee's lanyard in the Convivo
app and the attendee was checked in — but **no badge printed**. Reported against
production.
## Root cause
Two things, one a genuine bug and one a UX gap:
1. **The scanner defaults to *session* check-in.** The staff Scan screen has a
"Check-in type" toggle. In the default **session** mode it calls
`checkin_attendee`, which records session attendance and points but — by
design — never enqueues a badge. Only **welcome** check-in (`welcome_checkin`)
enqueues a print. A scan left in session mode therefore checks the person in
without printing.
2. **Welcome check-in fired silently.** Even in welcome mode the scan checked the
person in and queued a print with no confirmation, so staff had no idea a
label was about to come out (or that the wrong mode was selected).
## Fix
A confirmation step on the **welcome** path only (session check-in is unchanged
and still never prints, per the product decision):
- New read-only RPC `preview_welcome_checkin(p_attendee_qr)`
(`20261019090000_welcome_checkin_preview.sql`) resolves the scanned token to
the attendee and reports `already` + `will_print`. `will_print` mirrors the
exact enqueue condition in `welcome_checkin` (a genuine first check-in **and**
the event has a badge layout), so the popup never promises a print that won't
happen. It checks nobody in and enqueues nothing. Staff/admin only.
- The attendee app (`apps/convivo/src/screens/Scan.tsx`) now previews first and
shows a sheet: **"You are checking in [Name]. By confirming, you will print
this person's label."** with **Yes / No**. Only **Yes** runs `welcome_checkin`.
When `will_print` is `false` (already checked in, or no layout) the copy drops
the print sentence.
## Tests
- `supabase/tests/badge_print_tests.sql`: **+8 assertions** (109 total) — preview
resolves the name, reports `will_print` for an unchecked attendee, enqueues
nothing, checks nobody in, reports no print for a checked-in attendee or a
layout-less event, and is staff/admin-only (non-staff + anon rejected).
- `e2e/src/pages/ScanPage.ts` + welcome specs drive the new confirm step; added
`CONV-CHECKIN-003` (popup shows the name + print copy; **No** leaves the
attendee unchecked; **Yes** checks in).
- Real-browser smoke against a local build: **No** → not checked in, queue empty;
**Yes** → checked in and one `badge_print` job queued with the right name.
## Deployment
**Deployed to production 2026-10-19** (attendee app + DB migration).
- Migration `20261019090000_welcome_checkin_preview.sql` applied to prod in one
transaction with `ON_ERROR_STOP=1` and recorded in the ledger (39 → 40).
Backup `/home/APPE/convivo-backups/wprev-…` (counts before/after). Counts and
the print queue unchanged; `preview_welcome_checkin` present.
- `convivo-app` rebuilt from HEAD behind a baseline drift guard (the three
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).