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

+8
View File
@@ -16,6 +16,7 @@ import type {
Session,
Slot,
WelcomeCheckinResult,
WelcomeCheckinPreview,
AcceptConnectionResult,
TalkCohortMember,
} from './types';
@@ -201,6 +202,13 @@ export async function welcomeCheckin(attendeeQr: string): Promise<WelcomeCheckin
return rows[0];
}
/** Read-only preview of a welcome check-in: resolves the attendee and reports
* whether confirming will print their badge. Checks nobody in. */
export async function previewWelcomeCheckin(attendeeQr: string): Promise<WelcomeCheckinPreview> {
const rows = await rpc<WelcomeCheckinPreview[]>('preview_welcome_checkin', { p_attendee_qr: attendeeQr });
return rows[0];
}
export async function getMyFeedback(email: string): Promise<Feedback[]> {
const { data, error } = await supabase.from('feedback').select('*').eq('contact_email', email);
if (error) throw new ApiError(error.message);
+9
View File
@@ -187,6 +187,15 @@ export interface WelcomeCheckinResult {
already: boolean;
}
/** Read-only preview of a welcome check-in (shown before confirming). */
export interface WelcomeCheckinPreview {
attendee_email: string;
attendee_name: string;
already: boolean;
/** True when confirming will enqueue a badge print (first check-in + a layout exists). */
will_print: boolean;
}
/** Result of accepting a connection (the connection row + the shared-talk flag). */
export interface AcceptConnectionResult extends Connection {
/** True when both parties were checked into the same session (talk). */
+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 && (
+10
View File
@@ -125,6 +125,16 @@ worker) and stamps `last_seen_at`.
behaviour, plus the `badge_print` enqueue for a **genuine first check-in** only,
inside the same transaction (see [rpcs.md](./rpcs.md#welcome_checkinp_attendee_qr--attendee_email-attendee_name-already)).
The staff scanner (attendee app → Scan → Welcome check-in) does **not** fire
`welcome_checkin` directly. It first calls the read-only
`preview_welcome_checkin(qr)` and shows a confirmation — *"You are checking in
[Name]. By confirming, you will print this person's label."* — with **Yes/No**.
Only **Yes** runs `welcome_checkin`. The preview's `will_print` mirrors the exact
enqueue condition (first check-in **and** a layout exists), so the popup never
promises a print that won't happen; when it is `false` the popup says the person
is checked in without mentioning a label. Session check-in is unchanged and never
prints. (Added in `20261019090000_welcome_checkin_preview.sql`.)
## 5. Station tokens & security model
- Token format `cvp_…` (256 bits of entropy), generated server-side, shown
+15
View File
@@ -147,6 +147,21 @@ from `checkin_attendee`, which checks someone into a specific session).
- Sets `registrations.checked_in = true` (no points — that's the session
check-in's job).
- `already` is `true` if the attendee was already checked in to the event.
- On a **first** check-in (and only when the event has a badge layout), enqueues
a `badge_print` job in the same transaction (see [printing.md](printing.md)).
### `preview_welcome_checkin(p_attendee_qr)` → `(attendee_email, attendee_name, already, will_print)`
Read-only preview shown by the staff scanner **before** a welcome check-in is
committed, so the confirmation popup can name the attendee and be honest about
printing.
- **Role check:** `is_staff_or_admin()` or it raises `staff or admin only`
(same guard as `welcome_checkin`).
- Resolves the attendee by `qr_token` for the active event; raises
`no attendee found for that QR code` otherwise.
- `will_print` is `true` only for a genuine first check-in **and** when the
event has a badge layout with elements — exactly the condition under which
`welcome_checkin` enqueues a job.
- Checks nobody in and enqueues nothing; it is a pure lookup.
### `merge_tickets(p_source_id, p_target_id)` -> `jsonb`
+63
View File
@@ -0,0 +1,63 @@
# 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.
+23
View File
@@ -77,6 +77,29 @@ export class ScanPage {
return this.page.getByTestId('welcome-checkin-result');
}
/** The welcome check-in confirmation popup (shown after a welcome scan,
* before the attendee is actually checked in). */
welcomeConfirm(): ReturnType<Page['locator']> {
return this.page.getByTestId('welcome-checkin-confirm');
}
/** Confirm the pending welcome check-in (the "Yes, check in" button). */
async confirmWelcome(): Promise<void> {
await this.page.getByTestId('welcome-checkin-confirm-yes').click();
}
/** Decline the pending welcome check-in (the "No" button). */
async declineWelcome(): Promise<void> {
await this.page.getByRole('button', { name: 'No', exact: true }).click();
}
/** Scan a welcome code and confirm the popup in one step. */
async scanWelcome(code: string): Promise<void> {
await this.scanCode(code);
await this.welcomeConfirm().waitFor({ state: 'visible' });
await this.confirmWelcome();
}
/** Dismiss the open result sheet (the "Scan next" button) so the backdrop
* no longer intercepts clicks on the mode/toggle controls. */
async dismissResult(): Promise<void> {
+41 -2
View File
@@ -24,8 +24,11 @@ test.describe('Welcome Check-In + attendee access', () => {
await scan.setStaffMode();
await scan.setWelcomeMode();
// Scan ATTENDEE_NEW (manual code = the QR payload).
// Scan ATTENDEE_NEW (manual code = the QR payload). A confirmation popup
// appears first; the attendee is only checked in after confirming.
await scan.scanCode(ID.attendeeNew.qrToken);
await expect(scan.welcomeConfirm()).toBeVisible();
await scan.confirmWelcome();
await expect(scan.welcomeResult()).toBeVisible();
// Backend state is persisted: ATTENDEE_NEW is now welcome-checked-in.
@@ -42,8 +45,10 @@ test.describe('Welcome Check-In + attendee access', () => {
await scan.setStaffMode();
await scan.setWelcomeMode();
// Manual code input (the same token the QR would carry).
// Manual code input (the same token the QR would carry); confirm the popup.
await scan.scanCode(ID.attendeeNew.qrToken);
await expect(scan.welcomeConfirm()).toBeVisible();
await scan.confirmWelcome();
await expect(scan.welcomeResult()).toBeVisible();
// Equivalent backend state: welcome-checked-in, no session check-in created.
@@ -53,6 +58,39 @@ test.describe('Welcome Check-In + attendee access', () => {
expect(db.sessionCheckins(ID.attendeeNew.email)).toEqual([]);
});
test('CONV-CHECKIN-003 welcome scan shows a confirm popup; No cancels, Yes checks in', async ({ page }) => {
const app = new AppPage(page, APP_URL);
const scan = new ScanPage(page);
await login(page, APP_URL, ID.staff);
await app.waitForAdmitted();
await app.gotoTab('scan');
await scan.setStaffMode();
await scan.setWelcomeMode();
// Scanning shows a confirmation naming the attendee and the print warning,
// but does NOT check them in yet.
await scan.scanCode(ID.attendeeNew.qrToken);
const confirm = scan.welcomeConfirm();
await expect(confirm).toBeVisible();
await expect(confirm).toContainText(/You are checking in/);
await expect(confirm).toContainText(/print this person's label/i);
expect(db.isWelcomeCheckedIn(ID.attendeeNew.email)).toBe(false);
// "No" dismisses the popup and leaves the attendee unchecked in.
await scan.declineWelcome();
await expect(confirm).toBeHidden();
await new Promise((r) => setTimeout(r, 300));
expect(db.isWelcomeCheckedIn(ID.attendeeNew.email)).toBe(false);
// Scanning again and choosing "Yes" performs the check-in.
await scan.scanCode(ID.attendeeNew.qrToken);
await expect(scan.welcomeConfirm()).toBeVisible();
await scan.confirmWelcome();
await expect(scan.welcomeResult()).toBeVisible();
expect(await db.waitForWelcomeCheckedIn(ID.attendeeNew.email)).toBe(true);
});
test('CONV-ATT-AUTH-001 first-time attendee is gated before welcome check-in', async ({ page }) => {
const app = new AppPage(page, APP_URL);
@@ -85,6 +123,7 @@ test.describe('Welcome Check-In + attendee access', () => {
await sScan.setStaffMode();
await sScan.setWelcomeMode();
await sScan.scanCode(ID.attendeeNew.qrToken);
await sScan.confirmWelcome();
await expect(sScan.welcomeResult()).toBeVisible();
// 3. The attendee's open browser lifts the gate automatically (4s poll) —
+4 -1
View File
@@ -64,9 +64,12 @@ test.describe('Session Check-In', () => {
await app.waitForAdmitted();
await app.gotoTab('scan');
// 1. Welcome check-in only (no session).
// 1. Welcome check-in only (no session). A confirmation popup appears
// first; confirm it before the attendee is checked in.
await scan.setWelcomeMode();
await scan.scanCode(ID.attendeeA.qrToken);
await expect(scan.welcomeConfirm()).toBeVisible();
await scan.confirmWelcome();
await expect(scan.welcomeResult()).toBeVisible();
expect(await db.waitForWelcomeCheckedIn(ID.attendeeA.email)).toBe(true);
@@ -0,0 +1,54 @@
-- -----------------------------------------------------------------------------
-- Welcome check-in preview.
--
-- The staff scanner now shows a confirmation before a welcome check-in:
-- "You are checking in [Name]. By confirming, you will print this person's
-- label." This read-only RPC resolves a scanned QR token to the attendee and
-- reports whether a badge would actually print, so the popup can show the real
-- name and be honest about the print (a person already checked in, or an event
-- without a badge layout, will NOT print — mirroring welcome_checkin exactly).
--
-- It does NOT check anyone in and does NOT enqueue anything; it is a pure
-- lookup. Staff/admin only, same guard as welcome_checkin.
-- -----------------------------------------------------------------------------
create or replace function public.preview_welcome_checkin(p_attendee_qr text)
returns table (attendee_email text, attendee_name text, already boolean, will_print boolean)
language plpgsql stable security definer set search_path = public as $$
declare
v_staff text := public.current_email();
v_attendee text;
v_name text;
v_event_id uuid;
v_checked boolean;
v_reg_id uuid;
begin
if v_staff is null then raise exception 'not authenticated'; end if;
if not public.is_staff_or_admin() then raise exception 'staff or admin only'; end if;
select id into v_event_id from public.events where is_active limit 1;
if v_event_id is null then raise exception 'no active event'; end if;
select r.contact_email, c.full_name, r.id into v_attendee, v_name, v_reg_id
from public.registrations r
join public.contacts c on c.email = r.contact_email
where r.qr_token = p_attendee_qr
and r.event_id = v_event_id;
if v_attendee is null then raise exception 'no attendee found for that QR code'; end if;
select checked_in into v_checked
from public.registrations
where event_id = v_event_id and contact_email = v_attendee;
-- A badge prints only on a genuine first check-in AND when the event has a
-- layout with elements (the same condition welcome_checkin uses to enqueue).
will_print := coalesce(v_checked, false) is not true
and public._badge_print_payload(v_reg_id, 'checkin', v_staff) is not null;
return query select v_attendee, v_name, coalesce(v_checked, false), will_print;
end;
$$;
revoke execute on function public.preview_welcome_checkin(text) from public, anon;
grant execute on function public.preview_welcome_checkin(text) to authenticated;
notify pgrst, 'reload schema';
+70
View File
@@ -262,6 +262,76 @@ select pg_temp.assert_bp(
(select not checked_in from public.registrations where contact_email = '[email protected]'),
'rolled back check-in leaves the attendee unchecked');
-- -----------------------------------------------------------------------------
-- 2b. WELCOME CHECK-IN PREVIEW (read-only: resolves the name + will_print)
-- -----------------------------------------------------------------------------
-- bp-att5 is still unchecked (its scan was rolled back) and event A has a
-- layout, so the preview must report will_print = true WITHOUT checking in or
-- enqueueing anything.
create temporary table bp_prev1 as
select * from public.preview_welcome_checkin('BPQR-ATT-5');
select pg_temp.assert_bp(
(select attendee_email = '[email protected]' and attendee_name = 'Savepoint Sol' from bp_prev1),
'preview resolves the attendee name from the QR token');
select pg_temp.assert_bp(
(select already = false and will_print = true from bp_prev1),
'preview of an unchecked attendee reports will_print');
select pg_temp.assert_bp(
(select count(*) = 1 from pgmq.q_badge_print),
'preview enqueues nothing');
select pg_temp.assert_bp(
(select not checked_in from public.registrations where contact_email = '[email protected]'),
'preview does not check the attendee in');
-- An already-checked-in attendee: preview reports already and will_print = false.
create temporary table bp_prev2 as
select * from public.preview_welcome_checkin('BPQR-ATT-2');
select pg_temp.assert_bp(
(select already = true and will_print = false from bp_prev2),
'preview of a checked-in attendee reports no print');
-- An event without a badge layout: check-in would work but nothing prints.
-- (bp-attb was checked in by the section-2 scan; reset it so the preview
-- isolates the "no layout" reason rather than "already checked in".)
update public.registrations set checked_in = false where contact_email = '[email protected]';
update public.events set is_active = true where id = 'b9d00002-0000-0000-0000-00000000000b';
update public.events set is_active = false where id = 'b9d00001-0000-0000-0000-00000000000a';
create temporary table bp_prev3 as
select * from public.preview_welcome_checkin('BPQR-ATT-B');
select pg_temp.assert_bp(
(select already = false and will_print = false from bp_prev3),
'preview without a layout reports no print');
update public.events set is_active = true where id = 'b9d00001-0000-0000-0000-00000000000a';
update public.events set is_active = false where id = 'b9d00002-0000-0000-0000-00000000000b';
-- A plain (non-staff) viewer cannot preview; the guard matches welcome_checkin
-- (a plain RAISE EXCEPTION, i.e. sqlstate P0001 / raise_exception).
select set_config('request.jwt.claims', '{"email":"[email protected]","role":"authenticated"}', true);
do $$ begin
begin
perform * from public.preview_welcome_checkin('BPQR-ATT-5');
raise exception 'non-staff preview allowed';
exception when raise_exception then
if sqlerrm <> 'staff or admin only' then raise; end if;
end;
perform pg_temp.assert_bp(true, 'preview is staff/admin only');
end; $$;
-- The anonymous role cannot preview either.
select set_config('request.jwt.claims', '{"role":"anon"}', true);
set local role anon;
do $$ begin
begin
perform * from public.preview_welcome_checkin('BPQR-ATT-5');
raise exception 'anon preview allowed';
exception when insufficient_privilege then
null;
end;
perform pg_temp.assert_bp(true, 'anon cannot preview a check-in');
end; $$;
reset role;
-- -----------------------------------------------------------------------------
-- 3. PRINT STATION PROVISIONING AND PERMISSIONS
-- -----------------------------------------------------------------------------