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>
67 lines
2.6 KiB
TypeScript
67 lines
2.6 KiB
TypeScript
"use client";
|
||
|
||
import React, { useCallback, useEffect, useState } from "react";
|
||
import { ListChecks } from "lucide-react";
|
||
import { apiFetch } from "@/lib/api";
|
||
import { errorMessage } from "@/lib/utils";
|
||
import { entryLineName } from "@/lib/waitlist";
|
||
|
||
type Entry = {
|
||
id: string;
|
||
status: "waiting" | "offered";
|
||
quantity: number;
|
||
offeredQuantity: number | null;
|
||
offerExpiresAt: string | null;
|
||
event: { id: string; title: string; startDate: string };
|
||
eventOption: { name: string };
|
||
variant: { name: string } | null;
|
||
session: { label: string | null; startsAt: string } | null;
|
||
};
|
||
|
||
/** My Events: the waitlists I'm on, with Leave (and a note when a place is on offer). */
|
||
export function MyWaitlists({ token, onMessage }: { token: string; onMessage: (m: string) => void }) {
|
||
const [entries, setEntries] = useState<Entry[]>([]);
|
||
const load = useCallback(() => {
|
||
apiFetch<Entry[]>("/api/waitlist/mine", { authToken: token }).then(setEntries).catch(() => setEntries([]));
|
||
}, [token]);
|
||
useEffect(() => { load(); }, [load]);
|
||
|
||
if (entries.length === 0) return null;
|
||
|
||
const leave = async (id: string) => {
|
||
try {
|
||
const res = await apiFetch<{ message: string }>(`/api/waitlist/${encodeURIComponent(id)}`, { method: "DELETE", authToken: token });
|
||
onMessage(res.message);
|
||
load();
|
||
} catch (e) {
|
||
onMessage(errorMessage(e) || "Couldn't leave the waitlist");
|
||
}
|
||
};
|
||
|
||
return (
|
||
<section className="border rounded-xl p-4 bg-white shadow-sm">
|
||
<div className="flex items-center gap-2 font-semibold text-gray-900 mb-2">
|
||
<ListChecks className="w-4 h-4 text-brand-600" /> Waitlists
|
||
</div>
|
||
<ul className="divide-y">
|
||
{entries.map(e => (
|
||
<li key={e.id} className="py-2 flex items-center justify-between gap-3 text-sm">
|
||
<div>
|
||
<div className="font-medium">{e.event.title}</div>
|
||
<div className="text-xs text-gray-500">{e.quantity} × {entryLineName(e)}</div>
|
||
{e.status === "offered" ? (
|
||
<div className="text-xs text-green-700 mt-0.5">
|
||
{e.offeredQuantity} place(s) held for you until {e.offerExpiresAt ? new Date(e.offerExpiresAt).toLocaleString() : ""} — use the link we sent you to claim.
|
||
</div>
|
||
) : (
|
||
<div className="text-xs text-gray-500 mt-0.5">Waiting — we'll email or WhatsApp you if a place opens up.</div>
|
||
)}
|
||
</div>
|
||
<button onClick={() => leave(e.id)} className="px-2.5 py-1 text-xs rounded border hover:bg-gray-50 shrink-0">Leave</button>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
);
|
||
}
|