Archived
- 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>
54 lines
3.1 KiB
TypeScript
54 lines
3.1 KiB
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import type { Event } from "@/types";
|
|
import { bookableSessions, formatSessionWhen, sessionLabel } from "@/lib/sessions";
|
|
import { JoinWaitlistButton } from "@/components/events/JoinWaitlistButton";
|
|
|
|
// Tick boxes for the sessions of a "pick sessions" ticket. Full sessions (or ones with
|
|
// fewer places than `quantity`) can't be ticked; with `waitlist`, they get a "Join
|
|
// waitlist" button for that session instead.
|
|
export function SessionPicker({ event, option, selected, onChange, quantity = 1, staff = false, unitPrice, waitlist }: {
|
|
event: Pick<Event, "sessions">;
|
|
option: { id: string; sessionAvailability?: Record<string, number> };
|
|
selected: string[];
|
|
onChange: (ids: string[]) => void;
|
|
quantity?: number;
|
|
staff?: boolean;
|
|
unitPrice?: number;
|
|
waitlist?: { eventId: string; guestsAllowed: boolean; variantId?: string | null; label: string } | null;
|
|
}) {
|
|
const sessions = bookableSessions(event, option, staff);
|
|
if (sessions.length === 0) return <p className="text-xs text-gray-500 mt-2">No sessions left to book.</p>;
|
|
const toggle = (id: string) => onChange(selected.includes(id) ? selected.filter(x => x !== id) : [...selected, id]);
|
|
const allOpen = sessions.filter(s => s.left === null || s.left >= Math.max(1, quantity)).map(s => s.id);
|
|
return (
|
|
<div className="mt-2 space-y-1" role="group" aria-label="Choose sessions">
|
|
<div className="flex items-center justify-between text-xs text-gray-500">
|
|
<span>Choose your sessions{unitPrice !== undefined ? ` — R${unitPrice.toFixed(2)} each` : ""}</span>
|
|
<button type="button" className="text-brand-700 hover:underline" onClick={() => onChange(selected.length === allOpen.length ? [] : allOpen)}>
|
|
{selected.length === allOpen.length && allOpen.length > 0 ? "Clear" : "Select all"}
|
|
</button>
|
|
</div>
|
|
{sessions.map(s => {
|
|
const full = s.left !== null && s.left < Math.max(1, quantity);
|
|
const name = sessionLabel(s, event.sessions);
|
|
return (
|
|
<div key={s.id} className={`flex items-center gap-2 rounded border px-2 py-1.5 text-sm ${full ? "bg-gray-50 text-gray-400" : selected.includes(s.id) ? "border-brand-300 bg-brand-50" : "hover:bg-gray-50"}`}>
|
|
<label className="flex items-center gap-2 flex-1 min-w-0">
|
|
<input type="checkbox" disabled={full && !selected.includes(s.id)} checked={selected.includes(s.id)} onChange={() => toggle(s.id)} />
|
|
<span className="font-medium">{name}</span>
|
|
<span className="text-gray-500">{formatSessionWhen(s)}</span>
|
|
<span className="ml-auto text-xs">{s.left === null ? "" : s.left <= 0 ? "Full" : `${s.left} left`}</span>
|
|
</label>
|
|
{full && waitlist && !selected.includes(s.id) && (
|
|
<JoinWaitlistButton compact eventId={waitlist.eventId} guestsAllowed={waitlist.guestsAllowed}
|
|
lines={[{ eventOptionId: option.id, variantId: waitlist.variantId, sessionId: s.id, label: `${waitlist.label} — ${name}, ${formatSessionWhen(s)}` }]} />
|
|
)}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|