Files
co-lite/solvway-admin-portal/app/lib/services/adminGuests.ts
T

65 lines
2.3 KiB
TypeScript

import { apiDelete, apiGet, apiPost } from "@/app/lib/clientApi";
export interface EventGuest {
id: number;
name: string;
mobileE164: string | null;
email: string | null;
companyName: string | null;
salespersonUserId: number | null;
salespersonName: string | null;
/** Absent without BO_EVENT_GUESTS. */
token?: string;
invitedAt: string;
inviteSentCount: number;
registeredAt: string | null;
attended: boolean;
eventLeadUuid: string | null;
}
export interface GuestInput {
name: string;
mobile: string;
email: string;
companyName: string;
salespersonUserId?: number;
}
export interface GuestRejection {
index: number;
code: string;
field: string | null;
message: string;
}
export interface AddGuestsResult {
added: number;
rejected: GuestRejection[];
}
export interface Attendance {
invited: number;
cap: number | null;
registered: number;
attended: number;
walkIns: number;
/** add-event-ticket-orders: seats of awaiting and paid ticket orders; part of the total. */
heldTickets: number;
/** add-event-tickets: active tickets of awaiting and paid orders, and paid tickets checked in. */
ticketsAwaiting?: number;
ticketsPaid?: number;
ticketsCheckedIn?: number;
total: number;
capacity: number | null;
}
const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`;
export const listGuests = (uuid: string) => apiGet<EventGuest[]>(`${base(uuid)}/guests`);
// The API lists the added guests; the screen only needs how many.
export const addGuests = async (uuid: string, guests: GuestInput[], preview: boolean): Promise<AddGuestsResult> => {
const res = await apiPost<{ added?: unknown[]; rejected: GuestRejection[] }>(`${base(uuid)}/guests${preview ? "?preview=true" : ""}`, { guests });
return { added: res.added?.length ?? 0, rejected: res.rejected };
};
export const removeGuest = (uuid: string, id: number) => apiDelete<unknown>(`${base(uuid)}/guests/${id}`);
export const sendInvites = (uuid: string, target: { guestIds: number[] } | { allUnsent: true }) =>
apiPost<{ sent: number; skippedNoEmail: number }>(`${base(uuid)}/guests/send`, target);
export const getCheckin = (uuid: string) => apiGet<{ token: string }>(`${base(uuid)}/checkin`);
export const getAttendance = (uuid: string) => apiGet<Attendance>(`${base(uuid)}/attendance`);