Fix: door and manual registrations get their tickets; admin Corrections (1.52.0)
On events with a required attendee form, tickets waited for the forms, but
At the door and Manual registration never asked for them: payment was
recorded and nobody could be checked in.
- The form pops up at the door and in Manual registration; "Fill in later"
(any staff) issues the tickets once paid and sends the payer a link
(Registration.formWaivedAt, POST /api/v2/registrations/{id}/form-later).
- One form per person on picked-session bookings; a required form with no
questions no longer holds tickets back; every caller asks the ticket
generator (formsOutstanding).
- Kiosk asks for the forms the server says are missing; headings show as text.
- Admin Corrections page and /api/v2/corrections: issue missing tickets,
pay later (ticketsReleasedAt), make it free (complimentaryDiscount),
check in or undo after the event.
- Migration 20261102120000_corrections; unit and e2e tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { FileText } from "lucide-react";
|
||||
import { ModalOverlay } from "@/components/shared/ModalOverlay";
|
||||
import { ExtraFieldInput, isExtraFieldType } from "@/components/shared/FormFieldExtras";
|
||||
import { apiV2Data } from "@/lib/apiV2";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { Registration } from "@/types";
|
||||
|
||||
export type AttendeeFormField = { id?: string; type: string; label: string; isRequired?: boolean; helpText?: string | null; options?: unknown; order?: number };
|
||||
export type AttendeeFormDef = { isRequired?: boolean; fields?: AttendeeFormField[] } | null | undefined;
|
||||
|
||||
/** Fields that are only text to read (a statement, a heading). */
|
||||
const DISPLAY_FIELDS = ["statement", "paragraph"];
|
||||
|
||||
/** A required form with at least one question — the only kind tickets wait for. */
|
||||
export const formNeedsAnswers = (form: AttendeeFormDef) =>
|
||||
!!(form?.isRequired && (form.fields || []).some(f => !DISPLAY_FIELDS.includes(f.type)));
|
||||
|
||||
/**
|
||||
* Attendee forms a registration still needs before its tickets are issued (as the server works
|
||||
* it out, utils/ticketUtils.js formsOutstanding): one per main-ticket place — a picked-session
|
||||
* booking once, not once per session — less the forms in. 0 once the form was left for later.
|
||||
*/
|
||||
export function formsStillNeeded(form: AttendeeFormDef, reg: Registration | null | undefined): number {
|
||||
if (!reg || reg.formWaivedAt || !formNeedsAnswers(form)) return 0;
|
||||
let places = 0;
|
||||
const picked = new Map<string, number>();
|
||||
for (const ro of reg.registrationOptions || []) {
|
||||
if (!ro.eventOption?.isMainTicket) continue;
|
||||
if (!ro.sessionId) { places += ro.quantity || 0; continue; }
|
||||
const key = `${ro.eventOptionId}::${ro.variantId || ""}`;
|
||||
picked.set(key, Math.max(picked.get(key) || 0, ro.quantity || 0));
|
||||
}
|
||||
picked.forEach(q => { places += q; });
|
||||
return Math.max(0, places - (reg.formResponses || []).length);
|
||||
}
|
||||
|
||||
/**
|
||||
* The required attendee form at the door, in Manual registrations and in Corrections (1.52.0):
|
||||
* one form per attendee still to fill in (`needed`), or "Fill in later" — the tickets are issued
|
||||
* anyway and the payer is sent a link to fill it in. Closing the popup counts as "later", so a
|
||||
* registration never stays without tickets because the form was skipped.
|
||||
*/
|
||||
export function AttendeeFormModal({ registrationId, form, needed, token, attendeeName, onDone }: {
|
||||
registrationId: string;
|
||||
form: AttendeeFormDef;
|
||||
/** Attendee forms still to fill in. */
|
||||
needed: number;
|
||||
token: string | null;
|
||||
attendeeName?: string;
|
||||
/** `later`: the form was left for later. `ticketsIssued`: tickets made just now. */
|
||||
onDone: (result: { later: boolean; ticketsIssued: number; sentTo?: string[] }) => void;
|
||||
}) {
|
||||
const fields = useMemo(() => [...(form?.fields || [])].filter(f => !!f.id).sort((a, b) => (a.order || 0) - (b.order || 0)), [form]);
|
||||
const questions = fields.filter(f => !DISPLAY_FIELDS.includes(f.type));
|
||||
const [index, setIndex] = useState(0);
|
||||
const [answers, setAnswers] = useState<Record<string, string>[]>(() => Array.from({ length: Math.max(1, needed) }, () => ({})));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
|
||||
const current = answers[index] || {};
|
||||
const setAnswer = (fieldId: string, value: string) =>
|
||||
setAnswers(prev => prev.map((a, i) => (i === index ? { ...a, [fieldId]: value } : a)));
|
||||
|
||||
const later = async () => {
|
||||
if (busy) return;
|
||||
setBusy(true);
|
||||
setErr(null);
|
||||
try {
|
||||
const res = await (apiV2Data("post", "/registrations/{id}/form-later", { params: { id: registrationId }, authToken: token, body: {} }) as Promise<{ ticketsIssued: number; sentTo: string[] }>);
|
||||
onDone({ later: true, ticketsIssued: res?.ticketsIssued || 0, sentTo: res?.sentTo || [] });
|
||||
} catch (e) {
|
||||
setErr(errorMessage(e) || "Couldn't leave the form for later");
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const next = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
const missing = questions.find(f => f.isRequired && !String(current[f.id!] || "").trim());
|
||||
if (missing) { setErr(`"${missing.label}" is required.`); return; }
|
||||
setErr(null);
|
||||
if (index < needed - 1) { setIndex(i => i + 1); return; }
|
||||
setBusy(true);
|
||||
try {
|
||||
const res = await (apiV2Data("post", "/registrations/{id}/form-responses", {
|
||||
params: { id: registrationId }, authToken: token, body: { responses: answers.slice(0, needed).map(a => ({ answers: a })) },
|
||||
}) as Promise<{ generatedTickets?: unknown[] }>);
|
||||
onDone({ later: false, ticketsIssued: Array.isArray(res?.generatedTickets) ? res.generatedTickets.length : 0 });
|
||||
} catch (e2) {
|
||||
setErr(errorMessage(e2) || "Couldn't save the form");
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const input = (f: AttendeeFormField) => {
|
||||
const id = `door-form-${f.id}`;
|
||||
const value = current[f.id!] || "";
|
||||
const cls = "w-full border rounded px-3 py-2 text-sm";
|
||||
if (isExtraFieldType(f.type)) return <ExtraFieldInput field={f} idPrefix={`door${index}`} value={value} onChange={v => setAnswer(f.id!, v)} />;
|
||||
if (f.type === "yes_no") {
|
||||
return (
|
||||
<select id={id} className={cls} value={value} onChange={e => setAnswer(f.id!, e.target.value)}>
|
||||
<option value="">Select…</option>
|
||||
<option value="yes">Yes</option>
|
||||
<option value="no">No</option>
|
||||
</select>
|
||||
);
|
||||
}
|
||||
return <input id={id} className={cls} type={f.type === "numeric" ? "number" : f.type === "date" ? "date" : "text"} value={value} onChange={e => setAnswer(f.id!, e.target.value)} />;
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalOverlay labelledBy="attendee-form-title" onClose={busy ? undefined : later} className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4">
|
||||
<div className="bg-white rounded-2xl w-full max-w-lg shadow-xl max-h-[90vh] flex flex-col">
|
||||
<form onSubmit={next} className="p-6 space-y-4 overflow-y-auto">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="w-9 h-9 rounded-lg bg-amber-50 flex items-center justify-center shrink-0">
|
||||
<FileText className="w-5 h-5 text-amber-600" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 id="attendee-form-title" className="text-lg font-semibold text-gray-900">Attendee form{attendeeName ? ` — ${attendeeName}` : ""}</h2>
|
||||
<p className="text-xs text-gray-500">
|
||||
This event needs an attendee form before tickets are issued.
|
||||
{needed > 1 ? ` Attendee ${index + 1} of ${needed}.` : ""}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{fields.map(f => DISPLAY_FIELDS.includes(f.type) ? (
|
||||
<div key={f.id} className={f.type === "paragraph" ? "text-sm font-semibold text-gray-800" : "text-sm text-gray-600"}>
|
||||
{f.label}
|
||||
{f.helpText && <p className="text-xs font-normal text-gray-500 mt-0.5">{f.helpText}</p>}
|
||||
</div>
|
||||
) : (
|
||||
<div key={f.id}>
|
||||
<label htmlFor={`door-form-${f.id}`} className="block text-sm font-medium mb-1">
|
||||
{f.label}{f.isRequired && <span className="text-red-500 ml-0.5">*</span>}
|
||||
</label>
|
||||
{input(f)}
|
||||
{f.helpText && <p className="text-xs text-gray-500 mt-0.5">{f.helpText}</p>}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{err && <p role="alert" className="text-sm text-red-600">{err}</p>}
|
||||
|
||||
<div className="flex flex-col-reverse sm:flex-row gap-2 pt-2">
|
||||
<button type="button" onClick={later} disabled={busy} className="flex-1 py-2 border rounded text-sm disabled:opacity-50">
|
||||
Fill in later
|
||||
</button>
|
||||
{index > 0 && (
|
||||
<button type="button" onClick={() => setIndex(i => i - 1)} disabled={busy} className="py-2 px-4 border rounded text-sm disabled:opacity-50">
|
||||
Back
|
||||
</button>
|
||||
)}
|
||||
<button type="submit" disabled={busy} className="flex-1 py-2 rounded bg-emerald-600 text-white text-sm font-medium disabled:opacity-50">
|
||||
{busy ? "Saving…" : index < needed - 1 ? `Next — attendee ${index + 2}` : "Save form"}
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-[11px] text-gray-500">“Fill in later” issues the tickets now (once it’s paid) and sends the attendee a link to fill in the form.</p>
|
||||
</form>
|
||||
</div>
|
||||
</ModalOverlay>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user