Archived
Add shared API types and type the smaller frontend pages
Expand src/types with User, Event, EventOption, Registration, Payment, Ticket, paginated results and dashboard stats, modelled on the Prisma schema. apiFetch now defaults to unknown instead of any. Dashboard loaders are wrapped in useCallback so their effects can list them as dependencies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,10 +3,11 @@ import { ExtraFieldInput, isExtraFieldType } from "@/components/shared/FormField
|
||||
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { apiFetch } from "@/lib/api";
|
||||
import { TwoFactorChallenge, isTwoFactorChallenge } from "@/lib/auth";
|
||||
import { AuthResponse, TwoFactorChallenge, isTwoFactorChallenge } from "@/lib/auth";
|
||||
import { CouponCodeField, AppliedCoupon } from "@/components/shared/CouponCodeField";
|
||||
import { AttendeeNamesEditor, AttendeeEntries, TicketDelivery, attendeesPayload, consentDetailsMissing } from "@/components/shared/AttendeeNamesEditor";
|
||||
import { errorMessage } from "@/lib/utils";
|
||||
import type { Registration } from "@/types";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
type EarlyBirdTier = { deadline: string; price: number; order?: number; variantId?: string | null };
|
||||
@@ -26,7 +27,7 @@ type FormField = {
|
||||
isRequired: boolean;
|
||||
order: number;
|
||||
helpText?: string | null;
|
||||
options?: any;
|
||||
options?: unknown;
|
||||
};
|
||||
type EventForm = {
|
||||
id: string;
|
||||
@@ -294,11 +295,11 @@ export default function SelfServicePage() {
|
||||
// Second pass for accounts with two-factor on: exchange the code that was
|
||||
// sent after the password step. The kiosk never asks to be remembered.
|
||||
const data = setupChallenge
|
||||
? await apiFetch("/api/users/login/2fa", {
|
||||
? await apiFetch<AuthResponse>("/api/users/login/2fa", {
|
||||
method: "POST",
|
||||
body: { challengeId: setupChallenge.challengeId, code: setupCode, rememberDevice: false },
|
||||
})
|
||||
: await apiFetch("/api/users/login", {
|
||||
: await apiFetch<AuthResponse | TwoFactorChallenge>("/api/users/login", {
|
||||
method: "POST",
|
||||
body: { email: setupEmail, password: setupPassword },
|
||||
});
|
||||
@@ -405,7 +406,15 @@ export default function SelfServicePage() {
|
||||
async function handleRegister() {
|
||||
setFormLoading(true);
|
||||
try {
|
||||
const payload: any = {
|
||||
const user: { name: string; email?: string; phoneNumber?: string; password?: string } = {
|
||||
name: visitorName.trim(),
|
||||
...(visitorEmail.trim() ? { email: visitorEmail.trim() } : {}),
|
||||
...(visitorPhone.trim() ? { phoneNumber: visitorPhone.trim() } : {}),
|
||||
};
|
||||
if (createAccount && visitorPassword) {
|
||||
user.password = visitorPassword;
|
||||
}
|
||||
const payload: Record<string, unknown> = {
|
||||
eventId: selectedEventId,
|
||||
options: Object.entries(quantities)
|
||||
.filter(([, qty]) => qty > 0)
|
||||
@@ -413,11 +422,7 @@ export default function SelfServicePage() {
|
||||
const [eventOptionId, variantId] = key.split("::");
|
||||
return { eventOptionId, quantity, ...(variantId ? { variantId } : {}) };
|
||||
}),
|
||||
user: {
|
||||
name: visitorName.trim(),
|
||||
...(visitorEmail.trim() ? { email: visitorEmail.trim() } : {}),
|
||||
...(visitorPhone.trim() ? { phoneNumber: visitorPhone.trim() } : {}),
|
||||
},
|
||||
user,
|
||||
// If the visitor declined to create an account, don't push an unsolicited
|
||||
// activation email/WhatsApp at them afterward.
|
||||
skipActivationNotice: !createAccount,
|
||||
@@ -431,11 +436,7 @@ export default function SelfServicePage() {
|
||||
payload.attendees = kioskNames;
|
||||
payload.ticketDelivery = delivery;
|
||||
}
|
||||
if (createAccount && visitorPassword) {
|
||||
payload.user.password = visitorPassword;
|
||||
}
|
||||
|
||||
const result: any = await apiFetch("/api/registrations/manual", {
|
||||
const result = await apiFetch<Registration>("/api/registrations/manual", {
|
||||
method: "POST",
|
||||
body: payload,
|
||||
authToken: supervisorToken,
|
||||
|
||||
Reference in New Issue
Block a user