Session gaps: per-session waitlist, door session picker, all-sessions choice

- Waitlist per session: entries for pick-sessions tickets name a session;
  offers use that session's free places, never run past its start, and
  claim links tick it. Held offers count towards session capacity.
- At the door: the Select items pop-up has the session picker, with
  today's session preselected for new attendees.
- On pick-sessions events every ticket shows the session list straight
  away. "All sessions" tickets record the ticked sessions
  (RegistrationOption.sessionIds) at one price; scanning, attendance,
  certificates, reminders and capacity follow them.
- Fix: per-session stock limits weren't enforced (takenCount filtered
  WaitlistEntry by a sessionId column that didn't exist, and the error
  was swallowed), and the public event page lost its stock info.
- Fix: editing a door registration with picked sessions couldn't be saved.
- Fix: the offline-scanning service worker served /_next/static cache-first
  forever, so dev browsers that had opened the scanner ran stale code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 11:38:21 +02:00
co-authored by Claude Opus 5.5
parent f6d19a596e
commit e368be4dce
38 changed files with 685 additions and 182 deletions
@@ -1,6 +1,5 @@
"use client";
import Link from "next/link";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import { useAuth } from "@/hooks/useAuth";
import { useRouter } from "next/navigation";
@@ -16,7 +15,8 @@ import { DoorOpen, UserPlus, CreditCard, CheckSquare, Ticket, RotateCcw, type Lu
import { errorMessage } from "@/lib/utils";
import { optionUnitNow, variantUnitNow } from "@/lib/pricing";
import { printTicketCards, ticketTypeLabel as ticketLabel } from "@/lib/ticketPrint";
import { isPickOption, todaysSession } from "@/lib/sessions";
import { bookableSessions, choosesSessions, isPickOption, todaysSession } from "@/lib/sessions";
import { SessionPicker } from "@/components/events/SessionPicker";
import type { Event, EventOption, PublicBundle, Registration, Ticket as TicketRecord, UserSummary } from "@/types";
type NewAttendee = { name: string; email: string | null; phone: string | null; notifPref: "email" | "whatsapp" | "both" };
@@ -98,6 +98,10 @@ export default function AtTheDoorPage() {
const [eventOptions, setEventOptions] = useState<EventOption[]>([]);
const [doorHasPickOptions, setDoorHasPickOptions] = useState(false);
// "Pick sessions" events: the event (for its sessions) and the sessions chosen per
// quantity key. Picked sessions are booked on new registrations only.
const [doorEvent, setDoorEvent] = useState<Event | null>(null);
const [picks, setPicks] = useState<Record<string, string[]>>({});
const [showOptionsModal, setShowOptionsModal] = useState(false);
const [pendingUser, setPendingUser] = useState<NewAttendee | null>(null);
const [doorCoupon, setDoorCoupon] = useState<AppliedCoupon | null>(null);
@@ -160,16 +164,16 @@ export default function AtTheDoorPage() {
authToken: token
});
// Per-session tickets ("pick sessions") are booked from Manual registration,
// which has the session picker.
const all = ev.options || ev.eventOptions || [];
setEventOptions(all.filter(o => !isPickOption(ev, o)));
setDoorHasPickOptions(all.some(o => isPickOption(ev, o)));
setDoorEvent(ev);
setEventOptions(all);
setDoorHasPickOptions(choosesSessions(ev));
setDoorAllowsNames(!!ev.allowNamedAttendees || !!ev.requiresParentalConsent);
setDoorYouthStart(ev.requiresParentalConsent ? ev.startDate : null);
setDoorCollectGender(!!ev.collectGender);
setDoorBundles(ev.bundles || []);
} catch {
setDoorEvent(null);
setEventOptions([]);
setDoorBundles([]);
}
@@ -213,6 +217,10 @@ export default function AtTheDoorPage() {
}, [activeRegistration]);
// Charged per session / has sessions to tick (every ticket on a "pick sessions" event).
const isPick = (optionId: string) => isPickOption(doorEvent, eventOptions.find(o => o.id === optionId));
const choosing = choosesSessions(doorEvent);
const confirmRegistration = async () => {
if (confirming) return;
@@ -220,13 +228,18 @@ export default function AtTheDoorPage() {
.filter(([, qty]) => qty > 0)
.map(([key, quantity]) => {
const [eventOptionId, variantId] = key.split("::");
return { eventOptionId, quantity, ...(variantId ? { variantId } : {}) };
return { eventOptionId, quantity, ...(variantId ? { variantId } : {}), ...(choosing && !pendingEditReg ? { sessionIds: picks[key] || [] } : {}) };
});
if (!opts.length) {
setError("Select at least one item");
return;
}
const noSessions = opts.find(o => "sessionIds" in o && o.sessionIds && o.sessionIds.length === 0);
if (noSessions) {
setError(`Choose the sessions for "${eventOptions.find(o => o.id === noSessions.eventOptionId)?.name || "the ticket"}".`);
return;
}
for (const [key, minQty] of Object.entries(minQuantities)) {
if (minQty > 0 && (quantities[key] || 0) < minQty) {
@@ -244,6 +257,8 @@ export default function AtTheDoorPage() {
if (missing) { setError(missing); return; }
}
// Picked-session lines take no names.
const nameOptions = eventOptions.filter(o => !isPick(o.id));
setConfirming(true);
try {
if (pendingEditReg) {
@@ -286,8 +301,8 @@ export default function AtTheDoorPage() {
options: opts,
notificationPreference: pendingUser.notifPref,
...(doorCoupon ? { couponCode: doorCoupon.code } : {}),
...(doorAllowsNames && (doorNaming || doorYouthStart) && attendeesPayload(eventOptions, (o, v) => quantities[v ? `${o}::${v}` : o] || 0, doorEntries).length > 0
? { attendees: attendeesPayload(eventOptions, (o, v) => quantities[v ? `${o}::${v}` : o] || 0, doorEntries), ticketDelivery: doorDelivery }
...(doorAllowsNames && (doorNaming || doorYouthStart) && attendeesPayload(nameOptions, (o, v) => quantities[v ? `${o}::${v}` : o] || 0, doorEntries).length > 0
? { attendees: attendeesPayload(nameOptions, (o, v) => quantities[v ? `${o}::${v}` : o] || 0, doorEntries), ticketDelivery: doorDelivery }
: {}),
}
});
@@ -311,16 +326,20 @@ export default function AtTheDoorPage() {
// Called when NewAttendeeModal is confirmed — proceed to options selection
const handleNewAttendeeConfirm = ({ name, email, phone, notifPref }: { name: string; email: string; phone: string; notifPref: "email" | "whatsapp" | "both" }) => {
const qtyMap = initQuantities(eventOptions);
// Default main ticket to 1 (first variant if variants exist)
const pickMap: Record<string, string[]> = {};
// Default main ticket to 1 (first variant if variants exist). On a "pick sessions"
// event with a session today that still has room, that's one place in today's session.
const today = todaysSession(doorEvent);
const todayPick = today && doorEvent && choosing ? eventOptions.find(o => o.isMainTicket
&& bookableSessions(doorEvent, o, true).some(s => s.id === today.id && (s.left === null || s.left > 0))) : undefined;
eventOptions.forEach(o => {
if (!o.isMainTicket) return;
if ((o.variants || []).length > 0) {
qtyMap[`${o.id}::${(o.variants || [])[0].id}`] = 1;
} else {
qtyMap[o.id] = 1;
}
if (!o.isMainTicket || (todayPick ? o !== todayPick : choosing)) return;
const key = (o.variants || []).length > 0 ? `${o.id}::${(o.variants || [])[0].id}` : o.id;
qtyMap[key] = 1;
if (o === todayPick && today) pickMap[key] = [today.id];
});
setQuantities(qtyMap);
setPicks(pickMap);
setMinQuantities({});
setPendingUser({ name, email: email || null, phone: phone || null, notifPref });
setPendingEditReg(null);
@@ -345,8 +364,8 @@ export default function AtTheDoorPage() {
return;
}
const qtyMap = initQuantities(eventOptions);
const regOptions = freshReg.registrationOptions || [];
const qtyMap = initQuantities(eventOptions.filter(o => !isPick(o.id)));
const regOptions = (freshReg.registrationOptions || []).filter(ro => !ro.sessionId);
regOptions.forEach((ro) => {
const key = ro.variantId ? `${ro.eventOptionId}::${ro.variantId}` : ro.eventOptionId;
if (key in qtyMap) qtyMap[key] = ro.quantity || 0;
@@ -361,6 +380,7 @@ export default function AtTheDoorPage() {
});
setQuantities(qtyMap);
setPicks({});
setMinQuantities(minQtyMap);
setPendingEditReg(freshReg);
setPendingUser(null);
@@ -499,15 +519,11 @@ export default function AtTheDoorPage() {
{mode === "refund" && (
<DoorRefundPanel token={token} eventId={eventId} setInfo={setInfo} />
)}
{doorHasPickOptions && (
<div className="mt-4 p-3 border rounded bg-amber-50 border-amber-200 text-amber-900 text-sm">
This event has per-session tickets. Book those from <Link className="underline font-medium" href="/dashboard/supervisor/manual">Manual registration</Link>, which lets you choose the sessions.
</div>
)}
<OptionsModal
open={showOptionsModal}
onClose={() => { setShowOptionsModal(false); setPendingEditReg(null); }}
options={eventOptions}
options={pendingEditReg ? eventOptions.filter(o => !isPick(o.id)) : eventOptions}
pick={doorEvent && doorHasPickOptions ? { event: doorEvent, picks, setPicks } : null}
quantities={quantities}
setQuantities={setQuantities}
minQuantities={minQuantities}
@@ -1194,15 +1210,30 @@ type OptionsModalProps = {
bundles: PublicBundle[];
// Named-attendee editor settings, or null when the event doesn't take names.
names: Omit<React.ComponentProps<typeof AttendeeNamesEditor>, "options" | "qtyFor" | "payerLabel"> | null;
// A "pick sessions" event: its sessions and the sessions chosen per quantity key.
pick: { event: Event; picks: Record<string, string[]>; setPicks: React.Dispatch<React.SetStateAction<Record<string, string[]>>> } | null;
};
function OptionsModal({ open, onClose, options, quantities, setQuantities, minQuantities = {}, onConfirm, confirming, isEdit, totalPaid = 0, eventId, token, coupon, setCoupon, couponForUserId, existingCode, bundles, names }: OptionsModalProps) {
function OptionsModal({ open, onClose, options, quantities, setQuantities, minQuantities = {}, onConfirm, confirming, isEdit, totalPaid = 0, eventId, token, coupon, setCoupon, couponForUserId, existingCode, bundles, names, pick }: OptionsModalProps) {
const pickOpt = (optionId: string) => !!pick && isPickOption(pick.event, (options || []).find(o => o.id === optionId));
// Sessions are ticked on new bookings only (edits leave booked sessions as they are).
const choiceOpt = (optionId: string) => !!pick && !isEdit && (options || []).some(o => o.id === optionId);
// A picked option is priced per session.
const times = (key: string) => (pick && pickOpt(key.split("::")[0]) ? (pick.picks[key] || []).length : 1);
const basket = Object.entries(quantities)
.filter(([, qty]) => qty > 0)
.map(([key, quantity]) => {
const [eventOptionId, variantId] = key.split("::");
return { eventOptionId, quantity, variantId: variantId || null };
return { eventOptionId, quantity, variantId: variantId || null, ...(pick && choiceOpt(eventOptionId) ? { sessionIds: pick.picks[key] || [] } : {}) };
});
// The sessions show straight away; ticking one when the quantity is 0 makes it 1.
const picker = (key: string, option: EventOption) => {
if (!pick || !choiceOpt(option.id)) return null;
const qty = quantities[key] || 0;
return <SessionPicker event={pick.event} option={option} staff quantity={Math.max(1, qty)} selected={qty > 0 ? pick.picks[key] || [] : []}
onChange={ids => { pick.setPicks(p => ({ ...p, [key]: ids })); if (qty === 0 && ids.length > 0) setQuantities(q => ({ ...q, [key]: 1 })); }} />;
};
const perSession = (o: EventOption) => (pickOpt(o.id) ? " per session" : "");
// Bundle deals apply to the whole registration, so this holds for edits too.
const bundleQuote = useBundleQuote({ eventId, basket, token, forUserId: couponForUserId, enabled: open });
@@ -1213,9 +1244,9 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
const total = safeOptions.reduce((sum, o) => {
if ((o.variants || []).length > 0) {
return sum + (o.variants || []).reduce((vs, v) =>
vs + (quantities[`${o.id}::${v.id}`] || 0) * variantUnitNow(o, v), 0);
vs + (quantities[`${o.id}::${v.id}`] || 0) * times(`${o.id}::${v.id}`) * variantUnitNow(o, v), 0);
}
return sum + (quantities[o.id] || 0) * optionUnitNow(o);
return sum + (quantities[o.id] || 0) * times(o.id) * optionUnitNow(o);
}, 0);
const afterBundles = bundleQuote ? bundleQuote.total : total;
@@ -1236,6 +1267,11 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
<div className="text-xl font-semibold">
{isEdit ? "Edit Registration" : "Select Items"}
</div>
{isEdit && pick && (
<div className="text-sm text-gray-500 mt-1">
Sessions already booked stay as they are. To add sessions, book them as a new registration.
</div>
)}
{isEdit && totalPaid > 0 && (
<div className="text-sm text-gray-500 mt-1">
Already paid: <strong>R {Number(totalPaid).toFixed(2)}</strong> — new total must be at least this amount.
@@ -1267,11 +1303,12 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
const key = `${opt.id}::${v.id}`;
const minQty = minQuantities[key] || 0;
return (
<div key={v.id} className="flex items-center justify-between px-4 py-2.5 border-b last:border-b-0">
<div key={v.id} className="px-4 py-2.5 border-b last:border-b-0">
<div className="flex items-center justify-between">
<div>
<div className="text-sm">{v.name}</div>
<div className="text-xs text-gray-500">
R {unit.toFixed(2)}
R {unit.toFixed(2)}{perSession(opt)}
{unit < basePrice && basePrice > 0 && <span className="ml-1 text-green-600">(early bird)</span>}
</div>
{minQty > 0 && <div className="text-xs text-gray-400">{minQty} already issued</div>}
@@ -1282,6 +1319,8 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
<button onClick={() => stepper(key, 1)} className="w-8 h-8 border rounded flex items-center justify-center text-lg font-bold bg-emerald-50 border-emerald-300 text-emerald-700">+</button>
</div>
</div>
{picker(key, opt)}
</div>
);
})}
</div>
@@ -1293,7 +1332,7 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
<div key={opt.id} className="border rounded-xl p-3">
<div className="font-medium">{opt.name}</div>
<div className="text-xs text-gray-500">
R {unit.toFixed(2)}
R {unit.toFixed(2)}{perSession(opt)}
{unit < opt.price && opt.price > 0 && <span className="ml-1 text-green-600">(early bird, was R {opt.price.toFixed(2)})</span>}
{opt.isMainTicket ? " • Main" : ""}
</div>
@@ -1303,6 +1342,7 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
<div className="w-6 text-center text-lg font-semibold">{quantities[opt.id] || 0}</div>
<button onClick={() => stepper(opt.id, 1)} className="w-8 h-8 border rounded flex items-center justify-center text-lg font-bold bg-emerald-50 border-emerald-300 text-emerald-700">+</button>
</div>
{picker(opt.id, opt)}
</div>
);
})}
@@ -1323,7 +1363,7 @@ function OptionsModal({ open, onClose, options, quantities, setQuantities, minQu
{names && (
<div className="mb-3 max-h-64 overflow-y-auto">
<AttendeeNamesEditor
options={safeOptions}
options={safeOptions.filter(o => !pickOpt(o.id))}
qtyFor={(o: string, v: string | null) => quantities[v ? `${o}::${v}` : o] || 0}
{...names}
payerLabel="the person registering"
@@ -12,7 +12,7 @@ import { AttendeeNamesEditor, AttendeeEntries, TicketDelivery, attendeesPayload,
import { UserPlus, CreditCard } from "lucide-react";
import { errorMessage } from "@/lib/utils";
import { optionUnitNow, variantUnitNow } from "@/lib/pricing";
import { isPickOption } from "@/lib/sessions";
import { choosesSessions, isPickOption } from "@/lib/sessions";
import { SessionPicker } from "@/components/events/SessionPicker";
import type { Event, EventOption, PublicBundle, Registration, RegistrationOption, User } from "@/types";
import { BackLink } from "@/components/shared/BackLink";
@@ -289,11 +289,19 @@ export default function ManualRegistrationPage() {
const o = (fullEvent?.eventOptions || []).find(x => x.id === optionId);
return fullEvent && o && isPickOption(fullEvent, o) ? o : null;
};
// On a "pick sessions" event every ticket has sessions to tick; only pickOpt ones are charged per session.
const choiceOpt = (optionId: string) => {
const o = (fullEvent?.eventOptions || []).find(x => x.id === optionId);
return fullEvent && o && choosesSessions(fullEvent) ? o : null;
};
const times = (key: string) => (pickOpt(key.split("::")[0]) ? (picks[key] || []).length : 1);
const picker = (key: string, optionId: string) => {
const o = pickOpt(optionId);
if (!o || !fullEvent || !(quantities[key] > 0)) return null;
return <SessionPicker event={fullEvent} option={o} staff quantity={quantities[key]} selected={picks[key] || []} onChange={ids => setPicks(p => ({ ...p, [key]: ids }))} />;
const o = choiceOpt(optionId);
if (!o || !fullEvent) return null;
// The sessions show straight away; ticking one when the quantity is 0 makes it 1.
const qty = quantities[key] || 0;
return <SessionPicker event={fullEvent} option={o} staff quantity={Math.max(1, qty)} selected={qty > 0 ? picks[key] || [] : []}
onChange={ids => { setPicks(p => ({ ...p, [key]: ids })); if (qty === 0 && ids.length > 0) setQuantities(q => ({ ...q, [key]: 1 })); }} />;
};
const totalDue = useMemo(() => {
@@ -307,7 +315,7 @@ export default function ManualRegistrationPage() {
const basket = useMemo(() => Object.entries(quantities).map(([key, quantity]) => {
const [eventOptionId, variantId] = key.split("::");
return { eventOptionId, quantity, variantId: variantId || null, ...(pickOpt(eventOptionId) ? { sessionIds: picks[key] || [] } : {}) };
return { eventOptionId, quantity, variantId: variantId || null, ...(choiceOpt(eventOptionId) ? { sessionIds: picks[key] || [] } : {}) };
}), [quantities, picks, fullEvent]); // eslint-disable-line react-hooks/exhaustive-deps
const bundleQuote = useBundleQuote({ eventId: selectedEventId, basket, token, forUserId: pickedUserId });
const payable = coupon ? coupon.total : bundleQuote ? bundleQuote.total : totalDue;
@@ -322,7 +330,7 @@ export default function ManualRegistrationPage() {
.filter(([, qty]) => qty > 0)
.map(([key, quantity]) => {
const [eventOptionId, variantId] = key.split("::");
return { eventOptionId, quantity, ...(variantId ? { variantId } : {}), ...(pickOpt(eventOptionId) ? { sessionIds: picks[key] || [] } : {}) };
return { eventOptionId, quantity, ...(variantId ? { variantId } : {}), ...(choiceOpt(eventOptionId) ? { sessionIds: picks[key] || [] } : {}) };
});
if (opts.length === 0) { setError("Please select at least one ticket option."); return; }
const noSessions = opts.find(o => "sessionIds" in o && o.sessionIds && o.sessionIds.length === 0);
@@ -9,6 +9,7 @@ import { useDismissingState } from "@/hooks/useDismissingState";
import { ListChecks, ArrowUp, ArrowDown } from "lucide-react";
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "@/components/ui/table";
import { errorMessage } from "@/lib/utils";
import { entryLineName } from "@/lib/waitlist";
import type { Event } from "@/types";
import { BackLink } from "@/components/shared/BackLink";
@@ -22,6 +23,7 @@ type Entry = {
createdAt: string;
eventOption: { name: string };
variant: { name: string } | null;
session: { label: string | null; startsAt: string } | null;
user: { name: string; email: string; phoneNumber: string | null };
};
@@ -153,7 +155,7 @@ export default function WaitlistPage() {
<div className="text-sm font-medium">{e.user.name}</div>
<div className="text-xs text-gray-500">{[e.user.email, e.user.phoneNumber].filter(Boolean).join(" · ")}</div>
</TableCell>
<TableCell className="text-sm">{e.eventOption.name}{e.variant ? ` (${e.variant.name})` : ""}</TableCell>
<TableCell className="text-sm">{entryLineName(e)}</TableCell>
<TableCell className="text-sm">{e.quantity}{e.status === "offered" && e.offeredQuantity !== e.quantity ? ` (${e.offeredQuantity} offered)` : ""}</TableCell>
<TableCell className="text-xs text-gray-600">{formatDate(new Date(e.createdAt))}</TableCell>
<TableCell>