Archived
Public pages, auth, registration, payment, My Events and the kiosk: skip link, focus ring, labels tied to fields, named quantity buttons, announced errors, ModalOverlay popups (focus trap, Escape, focus return), contrast and underlined in-text links, reduced motion. Branding warns about a primary colour too light for white text and offers a darker shade. axe-core and keyboard checks in e2e/accessibility.spec.ts. 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-500" : 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>
|
|
);
|
|
}
|