Most attendees arrive without their QR open, and taking money at the door meant leaving the scanner for the event dashboard, where the Add Ticket modal demanded an email and recorded no payment method. The screen now leads with manual name search, keeps the camera one tap away behind a fullscreen overlay, and creates and charges walk-ins inline. Check-in and payment are one action: anything done here is born confirmed, paid (or comp) and checked in through a single endpoint, POST /api/events/:eventId/door-checkin. There are no confirm dialogs anywhere, because they stall the queue; a ten-second Undo replaces them, reversing exactly what the action changed via the undo state recorded alongside its idempotency key. Writes fire in the background with retries, so venue wifi never blocks the person at the door, and a capacity limit only warns, since staff at the door are the authority. Every write carries a client-generated idempotency key, inserted in the same transaction as the writes it guards, so a double tap or a retry after a timeout cannot produce a second ticket, payment or check-in. Search runs entirely in memory over one preloaded list: names are matched accent- and case-insensitively in both directions, per word, prefix before substring, with a mostly-numeric query searching phone digits so two people with the same name can be told apart. Door money is recorded as payments.source 'door' plus payments.method (cash, bitcoin, transfer or guest) while provider keeps its existing value, so capacity counting, the stale-booking sweeps and the admin payment lists are unaffected and revenue can still be split pre-sale versus door. Bitcoin records the payment as made, on the same trust model as cash, with no invoice generated; lib/doorPayments.ts is where a real Lightning flow slots in later. Also fixes the SQLite tickets DDL, which still created the pre-split attendee_name column with NOT NULL email and phone. Only fresh databases were affected -- existing ones were relaxed by later ALTERs -- but on those, door walk-ins (and any other ticket) could not be inserted at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
2.3 KiB
TypeScript
57 lines
2.3 KiB
TypeScript
// Firing door actions without ever blocking the queue of people at the door.
|
|
//
|
|
// The UI flashes green and clears the input the moment staff taps; the write
|
|
// happens here, in the background, with retries. Venue wifi drops constantly, so
|
|
// every action carries an idempotency key: a retry that actually succeeded the
|
|
// first time returns the original result instead of double-charging anyone.
|
|
|
|
import { doorApi, type DoorCheckinRequest, type DoorCheckinResponse } from '@/lib/api';
|
|
|
|
/** UUID per action. crypto.randomUUID needs a secure context; fall back when absent. */
|
|
export function newIdempotencyKey(): string {
|
|
const cryptoRef = typeof crypto !== 'undefined' ? crypto : undefined;
|
|
if (cryptoRef?.randomUUID) return cryptoRef.randomUUID();
|
|
return `door-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
|
|
}
|
|
|
|
// Roughly 5 seconds of retrying in total — long enough to ride out a wifi blip,
|
|
// short enough that staff learn about a real failure while the person is still
|
|
// in front of them.
|
|
const RETRY_DELAYS_MS = [400, 1200, 3000];
|
|
|
|
/**
|
|
* Errors worth retrying are the ones a retry can fix: network failures, gateway
|
|
* errors, rate limits. A 400 "ticket belongs to a different event" will fail
|
|
* identically forever, so it surfaces immediately.
|
|
*/
|
|
function isRetryable(error: any): boolean {
|
|
const status = error?.status;
|
|
if (typeof status === 'number') return status >= 500 || status === 408 || status === 429;
|
|
// No status at all means the request never reached the server (fetch rejects
|
|
// with a TypeError when the connection drops) — exactly the case to retry.
|
|
return true;
|
|
}
|
|
|
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
|
export async function submitDoorAction(
|
|
eventId: string,
|
|
body: DoorCheckinRequest,
|
|
): Promise<DoorCheckinResponse> {
|
|
let lastError: any;
|
|
for (let attempt = 0; attempt <= RETRY_DELAYS_MS.length; attempt++) {
|
|
try {
|
|
return await doorApi.checkin(eventId, body);
|
|
} catch (error: any) {
|
|
lastError = error;
|
|
if (attempt === RETRY_DELAYS_MS.length || !isRetryable(error)) break;
|
|
await sleep(RETRY_DELAYS_MS[attempt]);
|
|
}
|
|
}
|
|
throw lastError;
|
|
}
|
|
|
|
export async function undoDoorAction(eventId: string, idempotencyKey: string): Promise<void> {
|
|
await doorApi.undo(eventId, idempotencyKey);
|
|
}
|