feat(scan): confirm before welcome check-in, with print warning

The staff scanner checked attendees in silently, and the default session
mode never prints — so a welcome-desk scan could check someone in with no
badge and no confirmation.

- new read-only RPC preview_welcome_checkin(qr): resolves the attendee and
  reports already + will_print (mirrors the exact welcome_checkin enqueue
  condition: first check-in AND a layout exists). Staff/admin only; checks
  nobody in, enqueues nothing.
- attendee Scan screen previews first and shows a Yes/No sheet: "You are
  checking in [Name]. By confirming, you will print this person's label."
  Only Yes runs welcome_checkin. Session check-in unchanged (never prints).
- badge_print_tests.sql +8 assertions (109 total); ScanPage + welcome specs
  drive the confirm step; new CONV-CHECKIN-003 (No cancels, Yes checks in).
- docs: rpcs.md, printing.md, releases/2026-10-19.md.
This commit is contained in:
Lago committed 2026-10-19 09:45:20 +02:00
1 parent c980effddc
commit 9a6e2e5c2a
11 files changed
+348 -7

No files matched your search

+51 -4
View File
@@ -1,9 +1,9 @@
import { useEffect, useMemo, useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { useEvent } from '../lib/useEvent';
import { checkinAttendee, createConnectionRequest, lanyardLookup, welcomeCheckin } from '../lib/api';
import { checkinAttendee, createConnectionRequest, lanyardLookup, previewWelcomeCheckin, welcomeCheckin } from '../lib/api';
import { capWords } from '../lib/time';
import type { CheckinResult, PublicContact, WelcomeCheckinResult } from '../lib/types';
import type { CheckinResult, PublicContact, WelcomeCheckinPreview, WelcomeCheckinResult } from '../lib/types';
import { Avatar, Scanner, Sheet, Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
@@ -17,6 +17,9 @@ export function Scan() {
const [connectTarget, setConnectTarget] = useState<{ contact: PublicContact; qr: string } | null>(null);
const [checkin, setCheckin] = useState<CheckinResult | null>(null);
const [welcome, setWelcome] = useState<WelcomeCheckinResult | null>(null);
// A welcome scan is previewed first and only committed after the staff
// confirms that they want to check the person in (and print their badge).
const [pendingWelcome, setPendingWelcome] = useState<{ token: string; preview: WelcomeCheckinPreview } | null>(null);
const [busy, setBusy] = useState(false);
const { toast } = useToast();
@@ -49,8 +52,10 @@ export function Scan() {
try {
if (activeStaff) {
if (welcomeMode) {
const res = await welcomeCheckin(token);
setWelcome(res);
// Preview first: resolve the name and whether a badge will print, then
// wait for the staff to confirm before checking in.
const preview = await previewWelcomeCheckin(token);
setPendingWelcome({ token, preview });
} else {
// Fall back to the first checkable session so a fast scan (before the
// async default-selection effect runs) never fails with "pick a session".
@@ -81,6 +86,20 @@ export function Scan() {
}
}
async function confirmWelcome() {
if (!pendingWelcome) return;
setBusy(true);
try {
const res = await welcomeCheckin(pendingWelcome.token);
setWelcome(res);
setPendingWelcome(null);
} catch (e) {
toast(e instanceof Error ? e.message : 'Something went wrong', 'err');
} finally {
setBusy(false);
}
}
async function confirmConnect() {
if (!connectTarget) return;
setBusy(true);
@@ -207,6 +226,34 @@ export function Scan() {
)}
</Sheet>
{/* Welcome check-in confirmation (shown before checking in / printing) */}
<Sheet open={!!pendingWelcome} onClose={() => !busy && setPendingWelcome(null)}>
{pendingWelcome && (
<div style={{ textAlign: 'center' }} data-testid="welcome-checkin-confirm">
<div style={{ fontSize: 52 }}>{pendingWelcome.preview.will_print ? '🏷️' : '👋'}</div>
<h3 style={{ marginTop: 10 }}>{pendingWelcome.preview.attendee_name}</h3>
<p className="sub" style={{ marginTop: 8 }}>
{pendingWelcome.preview.already
? 'Already checked in to the event.'
: pendingWelcome.preview.will_print
? `You are checking in ${pendingWelcome.preview.attendee_name}. By confirming, you will print this person's label.`
: `You are checking in ${pendingWelcome.preview.attendee_name}.`}
</p>
{!pendingWelcome.preview.will_print && !pendingWelcome.preview.already && (
<div className="muted small" style={{ marginTop: 6 }}>No badge will print (no layout for this event).</div>
)}
<div style={{ marginTop: 16 }}>
<button className="btn primary" data-testid="welcome-checkin-confirm-yes" disabled={busy} onClick={confirmWelcome}>
{busy ? 'Checking in…' : 'Yes, check in'}
</button>
<button className="btn ghost" style={{ marginTop: 8 }} disabled={busy} onClick={() => setPendingWelcome(null)}>
No
</button>
</div>
</div>
)}
</Sheet>
{/* Welcome check-in result sheet */}
<Sheet open={!!welcome} onClose={() => setWelcome(null)}>
{welcome && (