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

+12 -4
View File
@@ -171,10 +171,18 @@ export async function setRegistrationType(contactEmail: string, type: Registrati
await rpc('set_registration_type', { p_contact_email: contactEmail, p_type: type });
}
export async function setCheckedIn(registrationId: string, checkedIn: boolean): Promise<void> {
const { data, error } = await supabase.from('registrations').update({ checked_in: checkedIn }).eq('id', registrationId).select('id').single();
if (error) throw new ApiError(error.message);
if (!data) throw new ApiError('Registration no longer exists');
/**
* Flip an attendee's event check-in state. When turning it OFF, the backend
* also removes every point this person earned from check-ins in the event
* (see set_registration_checked_in). Returns the number of points removed.
*/
export async function setCheckedIn(registrationId: string, checkedIn: boolean): Promise<number> {
const rows = await rpc<{ registration_id: string; checked_in: boolean; points_removed: number }[]>(
'set_registration_checked_in',
{ p_registration_id: registrationId, p_checked_in: checkedIn },
);
if (!rows?.length) throw new ApiError('Registration no longer exists');
return rows[0].points_removed;
}
export const mergeTickets = (sourceId: string, targetId: string) =>
+7 -1
View File
@@ -198,7 +198,13 @@ export function Registrations() {
setBusy(true);
setRegistrations((rows) => rows.map((row) => row.id === r.id ? { ...row, checked_in: v } : row));
try {
await setCheckedIn(r.id, v);
const removed = await setCheckedIn(r.id, v);
if (removed > 0) {
push('success', `${byEmail.get(r.contact_email)?.full_name ?? r.contact_email}: un-checked in, −${removed} check-in pts removed`);
}
// The RPC may have changed this attendee's points — refresh so the
// points column and leaderboard stay truthful.
await reloadRegistrations(r.event_id);
} catch (e) {
setRegistrations((rows) => rows.map((row) => row.id === r.id ? { ...row, checked_in: r.checked_in } : row));
push('error', e instanceof Error ? e.message : 'Update failed');