Archived
Pick sessions (frontend), roadmap and handover docs
Event wizard: how people book (whole course / pick sessions), capacity per session and per-option session mode. Session picker on the public registration page, Manual registration and the kiosk; at the door points to Manual registration. Register, tickets and My Events handle picked sessions. Adds docs/ROADMAP-v2.md and docs/HANDOVER.md so work can carry on from another machine, and a pick-sessions e2e test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,8 @@ 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 { latePrice, registrationClosesAt } from "@/lib/sessions";
|
||||
import { 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";
|
||||
import { analyticsSessionId } from "@/lib/analytics";
|
||||
@@ -33,6 +34,8 @@ type EventOption = {
|
||||
isMainTicket?: boolean;
|
||||
earlyBirdTiers?: EarlyBirdTier[];
|
||||
variants?: OptionVariant[];
|
||||
sessionMode?: "all" | "pick";
|
||||
sessionAvailability?: Record<string, number>;
|
||||
};
|
||||
|
||||
export type RegisterEvent = {
|
||||
@@ -54,8 +57,10 @@ export type RegisterEvent = {
|
||||
waitlistEnabled?: boolean;
|
||||
bundles?: PublicBundle[];
|
||||
scheduleType?: "single" | "sessions";
|
||||
attendanceMode?: "whole" | "pick";
|
||||
sessions?: EventSession[];
|
||||
registrationClosesAt?: string;
|
||||
wholeCourseClosesAt?: string | null;
|
||||
lateJoin?: LateJoinInfo | null;
|
||||
};
|
||||
|
||||
@@ -66,7 +71,7 @@ function withLatePrices(event: RegisterEvent): RegisterEvent {
|
||||
if (!late) return event;
|
||||
return {
|
||||
...event,
|
||||
eventOptions: (event.eventOptions || []).map(o => (!o.isMainTicket ? o : {
|
||||
eventOptions: (event.eventOptions || []).map(o => (!o.isMainTicket || o.sessionMode === "pick" ? o : {
|
||||
...o,
|
||||
price: latePrice(o.price, late),
|
||||
earlyBirdTiers: (o.earlyBirdTiers || []).map(t => ({ ...t, price: latePrice(t.price, late) })),
|
||||
@@ -156,18 +161,27 @@ 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 };
|
||||
|
||||
function OptionCard({
|
||||
opt,
|
||||
quantities,
|
||||
onQtyChange,
|
||||
waitlist,
|
||||
pick,
|
||||
}: {
|
||||
opt: EventOption;
|
||||
quantities: QtyMap;
|
||||
onQtyChange: (key: string, val: number) => void;
|
||||
waitlist?: { eventId: string; guestsAllowed: boolean } | null;
|
||||
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} />
|
||||
) : null);
|
||||
const isSoldOut = (opt.stockLimit ?? 0) > 0 && opt.availableCount !== undefined && opt.availableCount <= 0;
|
||||
|
||||
if (hasVariants) {
|
||||
@@ -177,7 +191,7 @@ function OptionCard({
|
||||
const variantPrices = variants.map((v) => effectiveUnitForVariant(opt, v));
|
||||
const minPrice = Math.min(...variantPrices);
|
||||
const maxPrice = Math.max(...variantPrices);
|
||||
const priceLabel = minPrice === maxPrice ? `R${minPrice.toFixed(2)}` : `From R${minPrice.toFixed(2)}`;
|
||||
const priceLabel = (minPrice === maxPrice ? `R${minPrice.toFixed(2)}` : `From R${minPrice.toFixed(2)}`) + perSession;
|
||||
|
||||
return (
|
||||
<div className="border rounded-lg overflow-hidden bg-white shadow-sm">
|
||||
@@ -214,10 +228,11 @@ function OptionCard({
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<div key={variant.id} className="flex items-center justify-between px-4 py-2.5">
|
||||
<div key={variant.id} className="px-4 py-2.5">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="text-sm">{variant.name}</span>
|
||||
<span className="text-xs text-gray-500">R{unitPrice.toFixed(2)}</span>
|
||||
<span className="text-xs text-gray-500">R{unitPrice.toFixed(2)}{perSession}</span>
|
||||
<StockBadge stockLimit={variant.stockLimit} availableCount={variant.availableCount} />
|
||||
{waitlist && variantSoldOut && !isSoldOut && (
|
||||
<JoinWaitlistButton compact eventId={waitlist.eventId} guestsAllowed={waitlist.guestsAllowed}
|
||||
@@ -231,6 +246,8 @@ function OptionCard({
|
||||
max={maxQty}
|
||||
/>
|
||||
</div>
|
||||
{picker(key, qty, unitPrice)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
@@ -248,7 +265,8 @@ function OptionCard({
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-between border rounded-lg p-3 bg-white shadow-sm">
|
||||
<div className="border rounded-lg p-3 bg-white shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="min-w-0 flex-1 mr-3">
|
||||
<div className="font-medium text-sm">{opt.name}</div>
|
||||
<div className="text-xs text-gray-500 mt-0.5 flex items-center gap-2 flex-wrap">
|
||||
@@ -260,7 +278,7 @@ function OptionCard({
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<span>R{price.toFixed(2)}</span>
|
||||
<span>R{price.toFixed(2)}{perSession}</span>
|
||||
)}
|
||||
<StockBadge stockLimit={opt.stockLimit} availableCount={opt.availableCount} />
|
||||
{waitlist && isSoldOut && (
|
||||
@@ -275,6 +293,8 @@ function OptionCard({
|
||||
max={maxQty}
|
||||
/>
|
||||
</div>
|
||||
{picker(key, qty, price)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -432,18 +452,26 @@ 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.
|
||||
const [picks, setPicks] = useState<Record<string, string[]>>({});
|
||||
const wholeCourseClosed = event.attendanceMode === "pick" && !!event.wholeCourseClosesAt && Date.now() >= new Date(event.wholeCourseClosesAt).getTime();
|
||||
const pickFor = (opt: EventOption) => isPickOption(event, opt);
|
||||
const sessionsFor = (key: string, opt: EventOption) => (pickFor(opt) ? (picks[key] || []).length : 1);
|
||||
|
||||
const total = useMemo(() => {
|
||||
return (event.eventOptions || []).reduce((sum, opt) => {
|
||||
const hasVariants = Array.isArray(opt.variants) && opt.variants.length > 0;
|
||||
if (hasVariants) {
|
||||
return sum + opt.variants!.reduce((vsum, v) => {
|
||||
const qty = quantities[`${opt.id}:${v.id}`] || 0;
|
||||
return vsum + qty * effectiveUnitForVariant(opt, v);
|
||||
const key = `${opt.id}:${v.id}`;
|
||||
const qty = quantities[key] || 0;
|
||||
return vsum + qty * sessionsFor(key, opt) * effectiveUnitForVariant(opt, v);
|
||||
}, 0);
|
||||
}
|
||||
return sum + (quantities[opt.id] || 0) * effectiveUnitForOption(opt);
|
||||
return sum + (quantities[opt.id] || 0) * sessionsFor(opt.id, opt) * effectiveUnitForOption(opt);
|
||||
}, 0);
|
||||
}, [event, quantities]);
|
||||
}, [event, quantities, picks]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
const isGuestEligible = !!(event.requiresAuth === false);
|
||||
const isLoggedIn = !!user || !!token;
|
||||
@@ -454,7 +482,7 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
return limitedOpts.length > 0 && limitedOpts.every(o => o.availableCount !== undefined && o.availableCount <= 0);
|
||||
}, [event]);
|
||||
|
||||
const basket = useMemo(() => buildItems(), [quantities]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const basket = useMemo(() => buildItems(), [quantities, picks]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
const bundleQuote = useBundleQuote({ eventId, basket, token, enabled: (event.bundles || []).length > 0 });
|
||||
// The server prices the basket (staff price, tiers, bundle deals) when quoting or checking
|
||||
// a code, so its total wins.
|
||||
@@ -472,15 +500,13 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
: 0;
|
||||
|
||||
function buildItems() {
|
||||
const items: { eventOptionId: string; quantity: number; variantId?: string }[] = [];
|
||||
const items: { eventOptionId: string; quantity: number; variantId?: string; sessionIds?: string[] }[] = [];
|
||||
Object.entries(quantities).forEach(([key, qty]) => {
|
||||
if (qty <= 0) return;
|
||||
if (key.includes(":")) {
|
||||
const [eventOptionId, variantId] = key.split(":");
|
||||
items.push({ eventOptionId, quantity: qty, variantId });
|
||||
} else {
|
||||
items.push({ eventOptionId: key, quantity: qty });
|
||||
}
|
||||
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;
|
||||
items.push({ eventOptionId, quantity: qty, ...(variantId ? { variantId } : {}), ...(sessionIds ? { sessionIds } : {}) });
|
||||
});
|
||||
return items;
|
||||
}
|
||||
@@ -491,6 +517,11 @@ export default function RegisterForm({ event: baseEvent }: { event: RegisterEven
|
||||
setError("Select at least one ticket.");
|
||||
return;
|
||||
}
|
||||
const noSessions = items.find(i => i.sessionIds && i.sessionIds.length === 0);
|
||||
if (noSessions) {
|
||||
setError(`Choose the sessions for "${(event.eventOptions || []).find(o => o.id === noSessions.eventOptionId)?.name || "your ticket"}".`);
|
||||
return;
|
||||
}
|
||||
if (isYouthEvent) {
|
||||
const missing = consentDetailsMissing(event.eventOptions || [], qtyFor, attendeeEntries, event.startDate);
|
||||
if (missing) { setError(missing); return; }
|
||||
@@ -660,14 +691,18 @@ 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 || []).map((opt) => (
|
||||
{(event.eventOptions || []).filter(opt => !(wholeCourseClosed && !pickFor(opt))).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}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user