"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([]); const load = useCallback(() => { apiFetch("/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 (
Waitlists
    {entries.map(e => (
  • {e.event.title}
    {e.quantity} × {entryLineName(e)}
    {e.status === "offered" ? (
    {e.offeredQuantity} place(s) held for you until {e.offerExpiresAt ? new Date(e.offerExpiresAt).toLocaleString() : ""} — use the link we sent you to claim.
    ) : (
    Waiting — we'll email or WhatsApp you if a place opens up.
    )}
  • ))}
); }