Archived
Add shared API types and type the smaller frontend pages
Expand src/types with User, Event, EventOption, Registration, Payment, Ticket, paginated results and dashboard stats, modelled on the Prisma schema. apiFetch now defaults to unknown instead of any. Dashboard loaders are wrapped in useCallback so their effects can list them as dependencies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ const CONSENT_LABEL: Record<string, { text: string; cls: string }> = {
|
||||
declined: { text: "consent declined", cls: "text-red-700" },
|
||||
};
|
||||
|
||||
type Attendee = {
|
||||
export type Attendee = {
|
||||
id: string; eventOptionId: string; variantId: string | null; name: string; email: string | null; phone: string | null;
|
||||
dateOfBirth?: string | null; gender?: string | null; parentName?: string | null; parentEmail?: string | null; parentPhone?: string | null;
|
||||
ticket?: { id: string; isUsed: boolean } | null;
|
||||
@@ -23,20 +23,41 @@ type Row = {
|
||||
dateOfBirth: string; gender: string; parentName: string; parentEmail: string; parentPhone: string;
|
||||
};
|
||||
|
||||
// The parts of a registration (with its attendees, options and event) this panel reads.
|
||||
export type AttendeesRegistration = {
|
||||
id: string;
|
||||
ticketDelivery?: "payer" | "each";
|
||||
attendees?: Attendee[];
|
||||
event?: {
|
||||
requiresParentalConsent?: boolean;
|
||||
collectGender?: boolean;
|
||||
allowNamedAttendees?: boolean;
|
||||
startDate?: string;
|
||||
} | null;
|
||||
registrationOptions?: {
|
||||
eventOptionId: string;
|
||||
variantId?: string | null;
|
||||
quantity: number;
|
||||
eventOption?: { name?: string; isMainTicket?: boolean } | null;
|
||||
variant?: { name?: string } | null;
|
||||
}[];
|
||||
formResponses?: { attendeeId?: string | null }[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Named attendees on a registration (group tickets): shows who each main-ticket place
|
||||
* is for, and lets the payer (or staff) name places, change details, choose where the
|
||||
* tickets go, and send an attendee the link to their own form.
|
||||
*/
|
||||
export function AttendeesPanel({ registration, token, canEdit, hasForm, onSaved, onMessage }: {
|
||||
registration: any;
|
||||
registration: AttendeesRegistration;
|
||||
token: string;
|
||||
canEdit: boolean;
|
||||
hasForm: boolean;
|
||||
onSaved: () => void;
|
||||
onMessage: (msg: string) => void;
|
||||
}) {
|
||||
const attendees: Attendee[] = registration.attendees || [];
|
||||
const attendees = useMemo<Attendee[]>(() => registration.attendees || [], [registration.attendees]);
|
||||
const youth = !!registration.event?.requiresParentalConsent;
|
||||
const collectGender = !!registration.event?.collectGender;
|
||||
const eventStart: string | undefined = registration.event?.startDate;
|
||||
@@ -117,7 +138,7 @@ export function AttendeesPanel({ registration, token, canEdit, hasForm, onSaved,
|
||||
}
|
||||
};
|
||||
|
||||
const answered = new Set((registration.formResponses || []).map((r: any) => r.attendeeId).filter(Boolean));
|
||||
const answered = new Set((registration.formResponses || []).map((r) => r.attendeeId).filter(Boolean));
|
||||
|
||||
const resendConsent = async (requestId: string) => {
|
||||
try {
|
||||
|
||||
@@ -6,8 +6,16 @@ import { apiFetch } from "@/lib/api";
|
||||
import { isMinorOn } from "@/components/shared/AttendeeNamesEditor";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
|
||||
type TransferTicket = { id: string; isUsed?: boolean; quantity?: number; usages?: unknown[] };
|
||||
type TransferEvent = {
|
||||
startDate?: string;
|
||||
allowTicketTransfer?: boolean;
|
||||
requiresParentalConsent?: boolean;
|
||||
collectGender?: boolean;
|
||||
};
|
||||
|
||||
/** Whether to offer "Transfer" on a ticket (the server checks the rules again). */
|
||||
export function canOfferTransfer(ticket: any, event: any, isSupervisor = false): boolean {
|
||||
export function canOfferTransfer(ticket: TransferTicket | null | undefined, event: TransferEvent | null | undefined, isSupervisor = false): boolean {
|
||||
if (!ticket || !event) return false;
|
||||
if ((ticket.usages || []).length > 0 || ticket.isUsed) return false;
|
||||
if (event.startDate && new Date(event.startDate) <= new Date()) return false;
|
||||
@@ -20,8 +28,8 @@ export function canOfferTransfer(ticket: any, event: any, isSupervisor = false):
|
||||
* to the details typed, and the ticket only moves (with a new QR code) once they accept.
|
||||
*/
|
||||
export function TransferTicketModal({ ticket, event, token, onClose, onDone }: {
|
||||
ticket: any;
|
||||
event: any;
|
||||
ticket: TransferTicket;
|
||||
event: TransferEvent | null | undefined;
|
||||
token: string;
|
||||
onClose: () => void;
|
||||
onDone: (message: string) => void;
|
||||
|
||||
Reference in New Issue
Block a user