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

56 lines
1.8 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;
total: number;
capacity: number | null;
}
const base = (uuid: string) => `/api/events/${encodeURIComponent(uuid)}`;
export const listGuests = (uuid: string) => apiGet<EventGuest[]>(`${base(uuid)}/guests`);
export const addGuests = (uuid: string, guests: GuestInput[], preview: boolean) =>
apiPost<AddGuestsResult>(`${base(uuid)}/guests${preview ? "?preview=true" : ""}`, { guests });
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`);