Files

44 lines
1.5 KiB
TypeScript

import { ApiError, apiGet, apiPut } from "@/app/lib/clientApi";
export interface RegistrationLink {
token: string;
enabled: boolean;
}
export interface EventLinks {
event: RegistrationLink;
members: (RegistrationLink & { userId: number; name: string; username: string })[];
}
export interface MyLink extends RegistrationLink {
eventUuid: string;
eventName: string;
startDate: string;
endDate: string;
location: string;
/** When the caller joined the event team; null on older rows. */
addedAt?: string | null;
}
export interface PrivacyNotice {
id: number;
companyId: number;
textEn: string;
textMs: string;
createdBy: string;
createdAt: string;
}
export const getEventLinks = (uuid: string) => apiGet<EventLinks>(`/api/events/${encodeURIComponent(uuid)}/registration-links`);
export const setLinkEnabled = (uuid: string, token: string, enabled: boolean) =>
apiPut(`/api/events/${encodeURIComponent(uuid)}/registration-links/${encodeURIComponent(token)}`, { enabled });
export const getMyLinks = () => apiGet<MyLink[]>("/api/my-registration-links");
export async function getPrivacyNotice(companyId: number): Promise<PrivacyNotice | null> {
try {
return await apiGet<PrivacyNotice>(`/api/companies/${companyId}/privacy-notice`);
} catch (err) {
if (err instanceof ApiError && err.status === 404) return null; // no notice published yet
throw err;
}
}
export const savePrivacyNotice = (companyId: number, body: { textEn: string; textMs: string }) =>
apiPut<PrivacyNotice>(`/api/companies/${companyId}/privacy-notice`, body);