Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
148 lines
4.6 KiB
TypeScript
148 lines
4.6 KiB
TypeScript
// add-event-ticket-orders: what a TICKETS block, a ticket request and the public order page carry.
|
|
|
|
import { publicCall } from "@/app/lib/services/publicRegistration";
|
|
|
|
export interface PublicTicketType {
|
|
id: number;
|
|
name: string;
|
|
priceSen: number;
|
|
left: number;
|
|
state: "ON_SALE" | "SOLD_OUT" | "ENDED";
|
|
}
|
|
|
|
export interface TicketsInfo {
|
|
eventName: string;
|
|
startDate: string | null;
|
|
endDate: string;
|
|
location: string | null;
|
|
companyName: string;
|
|
notice: { id: number; textEn: string; textMs: string };
|
|
types: PublicTicketType[];
|
|
}
|
|
|
|
export interface OrderLine {
|
|
name: string;
|
|
unitPriceSen: number;
|
|
quantity: number;
|
|
}
|
|
|
|
/** A request's answer: a token only when an order was saved (the honeypot gets a thank-you without one). */
|
|
export interface TicketRequestResult {
|
|
eventName: string;
|
|
reference?: string;
|
|
token?: string;
|
|
status?: "AWAITING" | "PAID";
|
|
totalSen?: number;
|
|
holdUntil?: string | null;
|
|
lines?: OrderLine[];
|
|
paymentInstructions?: string;
|
|
}
|
|
|
|
export interface PublicOrder {
|
|
reference: string;
|
|
status: "AWAITING" | "PAID" | "CANCELLED" | "EXPIRED";
|
|
buyerName: string;
|
|
totalSen: number;
|
|
createdAt: string;
|
|
lines: OrderLine[];
|
|
eventName: string;
|
|
startDate: string | null;
|
|
endDate: string | null;
|
|
location: string | null;
|
|
holdUntil?: string | null;
|
|
paymentInstructions?: string | null;
|
|
/** add-event-tickets: only on a Paid order. */
|
|
tickets?: OrderTicket[];
|
|
}
|
|
|
|
/** One ticket on the buyer's order page: no attendee contact. */
|
|
export interface OrderTicket {
|
|
id: number;
|
|
typeName: string | null;
|
|
attendeeName: string | null;
|
|
code: string;
|
|
state: "VALID" | "CHECKED_IN" | "TICKET_CANCELLED";
|
|
checkedInAt: string | null;
|
|
}
|
|
|
|
export interface AttendeeBody {
|
|
name: string;
|
|
mobile: string;
|
|
email: string;
|
|
permission: boolean;
|
|
}
|
|
|
|
/** A Malaysia wall-clock time from the server ("2027-01-13T12:00:00") as "13 Jan 2027, 12:00". */
|
|
export function when(s: string | null | undefined): string {
|
|
if (!s) return "";
|
|
const d = new Date(s);
|
|
return Number.isNaN(d.getTime()) ? s : d.toLocaleString("en-GB", { day: "numeric", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit" });
|
|
}
|
|
|
|
export const getPublicOrder = (token: string) => publicCall<PublicOrder>(`/api/public/orders/${encodeURIComponent(token)}`);
|
|
|
|
// add-event-tickets: the ticket page, its staff view and naming attendees.
|
|
|
|
export type TicketState = "VALID" | "CHECKED_IN" | "AWAITING" | "ORDER_CANCELLED" | "ORDER_EXPIRED" | "TICKET_CANCELLED";
|
|
|
|
export interface TicketNotice {
|
|
id: number;
|
|
textEn: string;
|
|
textMs: string;
|
|
}
|
|
|
|
interface TicketEvent {
|
|
eventName: string;
|
|
startDate: string | null;
|
|
endDate: string | null;
|
|
location: string | null;
|
|
}
|
|
|
|
/** The public view: no contact details; the notice only when the attendee can still opt in. */
|
|
export interface PublicTicket extends TicketEvent {
|
|
companyName: string;
|
|
typeName: string | null;
|
|
attendeeFirstName: string | null;
|
|
named: boolean;
|
|
state: TicketState;
|
|
checkedInAt: string | null;
|
|
consented: boolean;
|
|
notice?: TicketNotice;
|
|
}
|
|
|
|
export interface StaffTicket extends TicketEvent {
|
|
companyName: string | null;
|
|
typeName: string | null;
|
|
attendeeName: string | null;
|
|
named: boolean;
|
|
consented: boolean;
|
|
state: TicketState;
|
|
checkedInAt: string | null;
|
|
checkedInBy: string | null;
|
|
notice?: TicketNotice;
|
|
}
|
|
|
|
export interface CheckInBody {
|
|
name?: string;
|
|
mobile?: string;
|
|
email?: string;
|
|
consent: boolean;
|
|
}
|
|
|
|
const code = (c: string) => `/api/public/tickets/${encodeURIComponent(c)}`;
|
|
|
|
export const getPublicTicket = (c: string) => publicCall<PublicTicket>(code(c));
|
|
export const ticketQrUrl = (c: string) => `${code(c)}/qr.png`;
|
|
export const consentTicket = (c: string) =>
|
|
publicCall<{ consented: boolean }>(`${code(c)}/consent`, { method: "POST", body: JSON.stringify({ consent: true }) });
|
|
|
|
// Staff calls use plain fetch, not clientApi: a signed-out visitor or another company's staff gets an error and keeps
|
|
// the public view, never a redirect to the login page.
|
|
export const getStaffTicket = (c: string) => publicCall<StaffTicket>(`/api/tickets/${encodeURIComponent(c)}`);
|
|
export const checkInTicket = (c: string, body: CheckInBody) =>
|
|
publicCall<StaffTicket>(`/api/tickets/${encodeURIComponent(c)}/checkin`, { method: "POST", body: JSON.stringify(body) });
|
|
|
|
/** The buyer names or renames an attendee: the ticket comes back with a new code. */
|
|
export const nameAttendee = (token: string, ticketId: number, body: AttendeeBody) =>
|
|
publicCall<OrderTicket>(`/api/public/orders/${encodeURIComponent(token)}/tickets/${ticketId}/attendee`, { method: "POST", body: JSON.stringify(body) });
|