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:
@@ -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>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { apiFetch } from "@/lib/api";
|
||||
import { CouponCodeField, AppliedCoupon } from "@/components/shared/CouponCodeField";
|
||||
import { BundleBuilder, BundleOffers, BundleSavings, useBundleQuote } from "@/components/shared/BundleDeals";
|
||||
import type { EventSession, LateJoinInfo, PublicBundle } from "@/types";
|
||||
import { isPickOption, latePrice, registrationClosesAt } from "@/lib/sessions";
|
||||
import { choosesSessions, isPickOption, latePrice, registrationClosesAt } from "@/lib/sessions";
|
||||
import { SessionPicker } from "@/components/events/SessionPicker";
|
||||
import { AttendeeNamesEditor, AttendeeEntries, TicketDelivery, attendeesPayload, consentDetailsMissing } from "@/components/shared/AttendeeNamesEditor";
|
||||
import { JoinWaitlistButton } from "@/components/events/JoinWaitlistButton";
|
||||
@@ -80,7 +80,7 @@ function withLatePrices(event: RegisterEvent): RegisterEvent {
|
||||
};
|
||||
}
|
||||
|
||||
type WaitlistOffer = { eventOptionId: string; variantId: string | null; quantity: number; expiresAt: string; optionName: string; variantName: string | null };
|
||||
type WaitlistOffer = { eventOptionId: string; variantId: string | null; sessionId?: string | null; lineName?: string; quantity: number; expiresAt: string; optionName: string; variantName: string | null };
|
||||
|
||||
// Key format: "optionId" for no-variant options, "optionId:variantId" for variant options
|
||||
type QtyMap = Record<string, number>;
|
||||
@@ -161,8 +161,9 @@ function QtyControl({
|
||||
);
|
||||
}
|
||||
|
||||
// A "pick sessions" option: the sessions chosen per quantity key, and the event's schedule.
|
||||
type PickProps = { event: RegisterEvent; picks: Record<string, string[]>; onPick: (key: string, ids: string[]) => void };
|
||||
// A "pick sessions" event: the sessions chosen per quantity key, and the event's schedule.
|
||||
// perSession: this ticket is charged per session (otherwise one price for the sessions ticked).
|
||||
type PickProps = { event: RegisterEvent; picks: Record<string, string[]>; onPick: (key: string, ids: string[]) => void; perSession: boolean };
|
||||
|
||||
function OptionCard({
|
||||
opt,
|
||||
@@ -178,9 +179,12 @@ function OptionCard({
|
||||
pick?: PickProps | null;
|
||||
}) {
|
||||
const hasVariants = Array.isArray(opt.variants) && opt.variants.length > 0;
|
||||
const perSession = pick ? " per session" : "";
|
||||
const picker = (key: string, qty: number, unit: number) => (pick && qty > 0 ? (
|
||||
<SessionPicker event={pick.event} option={opt} selected={pick.picks[key] || []} onChange={(ids) => pick.onPick(key, ids)} quantity={qty} unitPrice={unit} />
|
||||
const perSession = pick?.perSession ? " per session" : "";
|
||||
// The sessions show straight away; ticking one when the quantity is 0 makes it 1.
|
||||
const picker = (key: string, qty: number, unit: number, variant?: { id: string; name: string }) => (pick ? (
|
||||
<SessionPicker event={pick.event} option={opt} selected={qty > 0 ? pick.picks[key] || [] : []} quantity={Math.max(1, qty)} unitPrice={pick.perSession ? unit : undefined}
|
||||
onChange={(ids) => { pick.onPick(key, ids); if (qty === 0 && ids.length > 0) onQtyChange(key, 1); }}
|
||||
waitlist={waitlist ? { ...waitlist, variantId: variant?.id ?? null, label: variant ? `${opt.name} (${variant.name})` : opt.name } : null} />
|
||||
) : null);
|
||||
const isSoldOut = (opt.stockLimit ?? 0) > 0 && opt.availableCount !== undefined && opt.availableCount <= 0;
|
||||
|
||||
@@ -246,7 +250,7 @@ function OptionCard({
|
||||
max={maxQty}
|
||||
/>
|
||||
</div>
|
||||
{picker(key, qty, unitPrice)}
|
||||
{picker(key, qty, unitPrice, variant)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -397,6 +401,10 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
...priced,
|
||||
eventOptions: (priced.eventOptions || []).map(o => {
|
||||
if (o.id !== offer.eventOptionId) return o;
|
||||
if (offer.sessionId) {
|
||||
const left = o.sessionAvailability?.[offer.sessionId];
|
||||
return { ...o, ...(left !== undefined ? { sessionAvailability: { ...o.sessionAvailability, [offer.sessionId]: left + offer.quantity } } : {}) };
|
||||
}
|
||||
return {
|
||||
...o,
|
||||
availableCount: o.availableCount !== undefined ? o.availableCount + offer.quantity : o.availableCount,
|
||||
@@ -452,11 +460,17 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
setQuantities((q) => ({ ...q, [key]: val }));
|
||||
};
|
||||
|
||||
// "Pick sessions" options: the sessions chosen for each quantity key. Whole-course
|
||||
// tickets on such an event stop selling when the course starts.
|
||||
// "Pick sessions" events: the sessions chosen for each quantity key. Every ticket
|
||||
// shows the sessions; per-session tickets are charged once per session ticked.
|
||||
const [picks, setPicks] = useState<Record<string, string[]>>({});
|
||||
const wholeCourseClosed = event.attendanceMode === "pick" && !!event.wholeCourseClosesAt && Date.now() >= new Date(event.wholeCourseClosesAt).getTime();
|
||||
const choosing = choosesSessions(event);
|
||||
const pickFor = (opt: EventOption) => isPickOption(event, opt);
|
||||
// A waitlist offer for one session: that session is ticked for them.
|
||||
useEffect(() => {
|
||||
if (!offer?.sessionId) return;
|
||||
const key = offer.variantId ? `${offer.eventOptionId}:${offer.variantId}` : offer.eventOptionId;
|
||||
setPicks(p => ({ ...p, [key]: [offer.sessionId as string] }));
|
||||
}, [offer]);
|
||||
const sessionsFor = (key: string, opt: EventOption) => (pickFor(opt) ? (picks[key] || []).length : 1);
|
||||
|
||||
const total = useMemo(() => {
|
||||
@@ -505,7 +519,7 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
if (qty <= 0) return;
|
||||
const [eventOptionId, variantId] = key.includes(":") ? key.split(":") : [key, undefined];
|
||||
const opt = (event.eventOptions || []).find(o => o.id === eventOptionId);
|
||||
const sessionIds = opt && pickFor(opt) ? picks[key] || [] : undefined;
|
||||
const sessionIds = opt && choosing ? picks[key] || [] : undefined;
|
||||
items.push({ eventOptionId, quantity: qty, ...(variantId ? { variantId } : {}), ...(sessionIds ? { sessionIds } : {}) });
|
||||
});
|
||||
return items;
|
||||
@@ -636,7 +650,7 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
|
||||
{offer && (
|
||||
<div className="mb-4 p-4 border rounded-lg bg-green-50 border-green-200 text-sm text-green-900">
|
||||
<strong>Your waitlist place:</strong> {offer.quantity} × {offer.optionName}{offer.variantName ? ` (${offer.variantName})` : ""} — held for you until {new Date(offer.expiresAt).toLocaleString()}.
|
||||
<strong>Your waitlist place:</strong> {offer.quantity} × {offer.lineName || `${offer.optionName}${offer.variantName ? ` (${offer.variantName})` : ""}`} — held for you until {new Date(offer.expiresAt).toLocaleString()}.
|
||||
</div>
|
||||
)}
|
||||
{offerError && (
|
||||
@@ -691,18 +705,15 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
|
||||
{!eventSoldOut && <BundleOffers bundles={event.bundles} className="mb-3" />}
|
||||
|
||||
{wholeCourseClosed && (
|
||||
<p className="mb-3 text-sm text-gray-600 bg-gray-50 border rounded-lg px-3 py-2">The course has started, so whole-course tickets are no longer on sale — choose the sessions you'd like to come to.</p>
|
||||
)}
|
||||
<div className="space-y-3">
|
||||
{(event.eventOptions || []).filter(opt => !(wholeCourseClosed && !pickFor(opt))).map((opt) => (
|
||||
{(event.eventOptions || []).map((opt) => (
|
||||
<OptionCard
|
||||
key={opt.id}
|
||||
opt={opt}
|
||||
quantities={quantities}
|
||||
onQtyChange={handleQtyChange}
|
||||
waitlist={event.waitlistEnabled ? { eventId, guestsAllowed: event.requiresAuth === false } : null}
|
||||
pick={pickFor(opt) ? { event, picks, onPick: (key, ids) => setPicks(p => ({ ...p, [key]: ids })) } : null}
|
||||
pick={choosing ? { event, picks, onPick: (key, ids) => setPicks(p => ({ ...p, [key]: ids })), perSession: pickFor(opt) } : null}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,7 @@ import { BundleBuilder, BundleOffers, BundleSavings, useBundleQuote } from "@/co
|
||||
import { AttendeeNamesEditor, AttendeeEntries, TicketDelivery, attendeesPayload, consentDetailsMissing } from "@/components/shared/AttendeeNamesEditor";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { Event, PublicBundle, Registration } from "@/types";
|
||||
import { isPickOption } from "@/lib/sessions";
|
||||
import { choosesSessions, isPickOption } from "@/lib/sessions";
|
||||
import { SessionPicker } from "@/components/events/SessionPicker";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
@@ -230,11 +230,19 @@ export default function SelfServicePage() {
|
||||
const o = (kioskFull?.eventOptions || []).find(x => x.id === optionId);
|
||||
return kioskFull && o && isPickOption(kioskFull, 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 = (kioskFull?.eventOptions || []).find(x => x.id === optionId);
|
||||
return kioskFull && o && choosesSessions(kioskFull) ? 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 || !kioskFull || !(quantities[key] > 0)) return null;
|
||||
return <SessionPicker event={kioskFull} option={o} quantity={quantities[key]} selected={picks[key] || []} onChange={ids => setPicks(p => ({ ...p, [key]: ids }))} />;
|
||||
const o = choiceOpt(optionId);
|
||||
if (!o || !kioskFull) 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={kioskFull} option={o} 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 total = useMemo(() => {
|
||||
@@ -456,7 +464,7 @@ export default function SelfServicePage() {
|
||||
.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] || [] } : {}) };
|
||||
}),
|
||||
user,
|
||||
// If the visitor declined to create an account, don't push an unsolicited
|
||||
|
||||
@@ -14,6 +14,7 @@ type Claim = {
|
||||
eventStart: string;
|
||||
optionName: string;
|
||||
variantName: string | null;
|
||||
lineName?: string;
|
||||
quantity: number;
|
||||
requested: number;
|
||||
expiresAt: string;
|
||||
@@ -53,7 +54,7 @@ export default function WaitlistClaimPage() {
|
||||
{claim.status === "offered" ? (
|
||||
<>
|
||||
<p className="text-sm text-gray-700">
|
||||
{claim.name ? `Hi ${claim.name}, ` : ""}{claim.quantity} × {claim.optionName}{claim.variantName ? ` (${claim.variantName})` : ""} {claim.quantity === 1 ? "is" : "are"} being held for you until <strong>{new Date(claim.expiresAt).toLocaleString()}</strong>.
|
||||
{claim.name ? `Hi ${claim.name}, ` : ""}{claim.quantity} × {claim.lineName || `${claim.optionName}${claim.variantName ? ` (${claim.variantName})` : ""}`} {claim.quantity === 1 ? "is" : "are"} being held for you until <strong>{new Date(claim.expiresAt).toLocaleString()}</strong>.
|
||||
{claim.quantity < claim.requested && ` You asked for ${claim.requested}; this is what came free.`}
|
||||
</p>
|
||||
<a href={`/register/${claim.eventId}?waitlist=${encodeURIComponent(token)}`} className="inline-block px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700">
|
||||
|
||||
Reference in New Issue
Block a user