Add group tickets with named attendees

Events can take a name (and optional email/phone) for each main-ticket
place. Each named person gets their own quantity-1 ticket and attendee
form; unnamed places share one ticket. Tickets go to the payer or to each
person, attendees matching one existing account are linked to it, and
the payer can edit names and send form links from My Events. Ticket
generation is now planned per line (utils/attendees.js), free
registrations use the same generator, and guest registration matches
accounts by phone too, refusing conflicting email/phone pairs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 12:12:33 +02:00
co-authored by Claude Opus 5.5
parent 4b413788ac
commit df0bf09a0e
31 changed files with 1323 additions and 113 deletions
@@ -4,6 +4,7 @@ import React, { useEffect, useMemo, useState } from "react";
import { useAuth } from "@/hooks/useAuth";
import { apiFetch } from "@/lib/api";
import { CouponCodeField, AppliedCoupon } from "@/components/shared/CouponCodeField";
import { AttendeeNamesEditor, AttendeeEntries, TicketDelivery, attendeesPayload } from "@/components/shared/AttendeeNamesEditor";
// Tiered low-stock threshold — mirrors events/[id]/page.tsx
function lowStockThreshold(stockLimit: number): number {
@@ -40,6 +41,7 @@ type Event = {
eventOptions?: EventOption[];
form?: { isRequired: boolean; fields?: any[] } | null;
requiresAuth?: boolean;
allowNamedAttendees?: boolean;
};
// Key format: "optionId" for no-variant options, "optionId:variantId" for variant options
@@ -248,6 +250,13 @@ export default function RegisterForm({ event }: { event: Event }) {
const [creatingCheckout, setCreatingCheckout] = useState(false);
const [creatingRegistration, setCreatingRegistration] = useState(false);
const [coupon, setCoupon] = useState<AppliedCoupon | null>(null);
const [namingOthers, setNamingOthers] = useState(false);
const [attendeeEntries, setAttendeeEntries] = useState<AttendeeEntries>({});
const [delivery, setDelivery] = useState<TicketDelivery>("payer");
const qtyFor = (optionId: string, variantId: string | null) => quantities[variantId ? `${optionId}:${variantId}` : optionId] || 0;
const namedAttendees = () => (event.allowNamedAttendees && namingOthers
? attendeesPayload(event.eventOptions || [], qtyFor, attendeeEntries)
: []);
// Guest details (for unauthenticated free-event registration)
const [guestName, setGuestName] = useState("");
@@ -330,7 +339,12 @@ export default function RegisterForm({ event }: { event: Event }) {
setCreatingRegistration(true);
const res = await apiFetch<{ id: string; totalDueComputed?: number; couponError?: string }>("/api/registrations", {
method: "POST",
body: { eventId, options: items, ...(coupon ? { couponCode: coupon.code } : {}) },
body: {
eventId,
options: items,
...(coupon ? { couponCode: coupon.code } : {}),
...(namedAttendees().length > 0 ? { attendees: namedAttendees(), ticketDelivery: delivery } : {}),
},
authToken: token,
});
if (res?.id) {
@@ -370,7 +384,10 @@ export default function RegisterForm({ event }: { event: Event }) {
setCreatingRegistration(true);
const res = await apiFetch<{ id: string }>("/api/registrations", {
method: "POST",
body: { eventId, options: items, guestName: guestName.trim(), guestEmail: guestEmail.trim(), guestPhone: guestPhone.trim() || undefined },
body: {
eventId, options: items, guestName: guestName.trim(), guestEmail: guestEmail.trim(), guestPhone: guestPhone.trim() || undefined,
...(namedAttendees().length > 0 ? { attendees: namedAttendees(), ticketDelivery: delivery } : {}),
},
});
if (res?.id) {
const hasForm = !!(event?.form && Array.isArray(event.form.fields) && event.form.fields.length > 0);
@@ -488,6 +505,21 @@ export default function RegisterForm({ event }: { event: Event }) {
);
})()}
{event.allowNamedAttendees && !eventSoldOut && (isLoggedIn || showGuestForm) && (
<div className="mt-6">
<AttendeeNamesEditor
options={event.eventOptions || []}
qtyFor={qtyFor}
enabled={namingOthers}
onEnabledChange={setNamingOthers}
entries={attendeeEntries}
onEntriesChange={setAttendeeEntries}
delivery={delivery}
onDeliveryChange={setDelivery}
/>
</div>
)}
{isLoggedIn && total > 0 && !eventSoldOut && (
<div className="mt-6">
<CouponCodeField eventId={eventId} basket={basket} token={token} applied={coupon} onChange={setCoupon} />