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

+7 -1
View File
@@ -90,6 +90,12 @@ export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'Q
const [camError, setCamError] = useState<string | null>(null);
const scannerRef = useRef<Html5Qrcode | null>(null);
const [camOn, setCamOn] = useState(false);
// The camera callback below is registered once on mount; without a ref it
// would keep calling the FIRST render's onResult, whose closures over
// parent state (welcome mode, selected session) are stale. Always invoke
// the latest handler through this ref.
const onResultRef = useRef(onResult);
onResultRef.current = onResult;
useEffect(() => {
let cancelled = false;
@@ -119,7 +125,7 @@ export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'Q
if (cancelled) return;
setCamOn(false);
scanner?.stop().catch(() => {});
onResult(text);
onResultRef.current(text);
},
() => {},
)