Files
co-lite/solvway-admin-portal/app/lib/services/publicRegistration.ts
T
ngqileandClaude Opus 5.5 08c45e9109 feat(portal): QR self-registration page, event QR card, My QR codes, privacy notice editor
The public /r/<code> page (no admin shell, never redirects a visitor to the
staff login), its proxy sending only the last X-Forwarded-For hop, the event
page's Registration QR card, a My QR codes page in the user menu, and the
super-admin privacy notice editor on Companies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-12-01 12:57:18 +08:00

48 lines
1.4 KiB
TypeScript

import { ApiError } from "@/app/lib/clientApi";
export interface RegistrationInfo {
eventName: string;
startDate: string;
endDate: string;
location: string;
companyName: string;
notice: { id: number; textEn: string; textMs: string };
interests: { id: number; name: string }[];
}
export interface RegistrationBody {
name: string;
mobile: string;
email: string;
companyName: string;
jobTitle: string;
interestIds: number[];
consent: boolean;
website: string;
}
const url = (token: string) => `/api/public/registration/${encodeURIComponent(token)}`;
// Plain fetch on purpose: clientApi redirects a 401 to the admin /login, which a visitor must never see.
async function call<T>(token: string, init?: RequestInit): Promise<T> {
let res: Response;
try {
res = await fetch(url(token), { ...init, headers: init?.body ? { "Content-Type": "application/json" } : {} });
} catch {
throw new ApiError("Request failed", 0);
}
const text = await res.text();
let data: unknown;
try {
data = text ? JSON.parse(text) : undefined;
} catch {
data = undefined;
}
if (!res.ok) throw new ApiError(`Request failed (${res.status})`, res.status, data);
return data as T;
}
export const getRegistration = (token: string) => call<RegistrationInfo>(token);
export const submitRegistration = (token: string, body: RegistrationBody) =>
call<{ eventName: string }>(token, { method: "POST", body: JSON.stringify(body) });