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:
+178
-14
@@ -1,4 +1,9 @@
|
||||
// Shapes of the records the backend API returns. These mirror the Prisma models
|
||||
// (backend/prisma/schema.prisma) with dates as ISO strings. Relations are optional
|
||||
// because each endpoint includes a different subset of them.
|
||||
|
||||
export type Role = "user" | "staff" | "supervisor" | "admin";
|
||||
export type NotificationPreference = "email" | "whatsapp" | "both";
|
||||
|
||||
export type AuthUser = {
|
||||
id: string;
|
||||
@@ -16,27 +21,117 @@ export type AuthResponse = {
|
||||
user: AuthUser;
|
||||
};
|
||||
|
||||
// A user record as admin/supervisor endpoints return it (never includes the password).
|
||||
export type User = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
phoneNumber?: string | null;
|
||||
role?: Role;
|
||||
isActive?: boolean;
|
||||
notificationPreference?: NotificationPreference;
|
||||
twoFactorEnabled?: boolean;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
};
|
||||
|
||||
// The few user fields most endpoints embed in related records.
|
||||
export type UserSummary = Pick<User, "id" | "name" | "email"> & Partial<Pick<User, "phoneNumber" | "role">>;
|
||||
|
||||
export type OptionVariant = {
|
||||
id: string;
|
||||
eventOptionId?: string;
|
||||
name: string;
|
||||
price?: number | null;
|
||||
staffPrice?: number | null;
|
||||
stockLimit?: number;
|
||||
order?: number;
|
||||
};
|
||||
|
||||
export type EarlyBirdTier = {
|
||||
id: string;
|
||||
eventOptionId?: string;
|
||||
variantId?: string | null;
|
||||
deadline: string;
|
||||
price: number;
|
||||
order?: number;
|
||||
stockLimit?: number;
|
||||
};
|
||||
|
||||
export type EventOption = {
|
||||
id: string;
|
||||
eventId?: string;
|
||||
name: string;
|
||||
price: number;
|
||||
isMainTicket?: boolean;
|
||||
stockLimit?: number;
|
||||
staffPrice?: number | null;
|
||||
variants?: OptionVariant[];
|
||||
earlyBirdTiers?: EarlyBirdTier[];
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
};
|
||||
|
||||
export type FormFieldType =
|
||||
| "yes_no" | "text" | "date" | "numeric" | "statement" | "paragraph" | "rating" | "multiple_choice";
|
||||
|
||||
export type EventFormField = {
|
||||
id: string;
|
||||
formId?: string;
|
||||
type: FormFieldType;
|
||||
label: string;
|
||||
isRequired?: boolean;
|
||||
order?: number;
|
||||
helpText?: string | null;
|
||||
options?: unknown;
|
||||
};
|
||||
|
||||
export type EventForm = {
|
||||
id?: string;
|
||||
eventId?: string;
|
||||
isRequired: boolean;
|
||||
fields: EventFormField[];
|
||||
};
|
||||
|
||||
export type Event = {
|
||||
id: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
description?: string | null;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
registrationDeadline?: string | null;
|
||||
goLiveAt?: string;
|
||||
price: number;
|
||||
picture?: string;
|
||||
picture?: string | null;
|
||||
location?: string | null;
|
||||
isActive?: boolean;
|
||||
isHidden?: boolean;
|
||||
isLive?: boolean;
|
||||
requiresAuth?: boolean;
|
||||
requiresRegistration?: boolean;
|
||||
allowNamedAttendees?: boolean;
|
||||
requiresParentalConsent?: boolean;
|
||||
consentText?: string | null;
|
||||
consentTextVersion?: number;
|
||||
consentCollectMedical?: boolean;
|
||||
consentCollectEmergency?: boolean;
|
||||
consentCollectPhoto?: boolean;
|
||||
waitlistEnabled?: boolean;
|
||||
waitlistOfferHours?: number;
|
||||
waitlistPartialOffers?: boolean;
|
||||
allowTicketTransfer?: boolean;
|
||||
collectGender?: boolean;
|
||||
allowSponsorships?: boolean;
|
||||
sponsorshipGoalSpots?: number | null;
|
||||
showSponsorshipProgress?: boolean;
|
||||
contactName?: string | null;
|
||||
contactPhone?: string | null;
|
||||
contactEmail?: string | null;
|
||||
createdById?: string | null;
|
||||
redirectUrl?: string | null;
|
||||
options?: EventOption[];
|
||||
eventOptions?: EventOption[];
|
||||
form?: EventForm | null;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
cashupStatus?: "open" | "closed";
|
||||
@@ -143,22 +238,34 @@ export type EventFinancials = {
|
||||
salesByOption: SalesByOption[];
|
||||
history: EventCashup[];
|
||||
};
|
||||
export type RegistrationStatus = "pending" | "confirmed" | "partial_paid" | "paid" | "cancelled";
|
||||
|
||||
export type RegistrationItem = {
|
||||
id?: string;
|
||||
export type RegistrationOption = {
|
||||
id: string;
|
||||
registrationId?: string;
|
||||
eventOptionId: string;
|
||||
quantity: number;
|
||||
variantId?: string | null;
|
||||
priceSnapshot?: number | null;
|
||||
eventOption?: EventOption;
|
||||
variant?: OptionVariant | null;
|
||||
};
|
||||
|
||||
export type Registration = {
|
||||
id: string;
|
||||
userId: string;
|
||||
eventId: string;
|
||||
status: "pending" | "paid" | string;
|
||||
status: RegistrationStatus;
|
||||
discountTotal?: number;
|
||||
ticketDelivery?: "payer" | "each";
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
event?: Pick<Event, "id" | "title" | "price">;
|
||||
options?: RegistrationItem[];
|
||||
user?: UserSummary;
|
||||
event?: Event;
|
||||
registrationOptions?: RegistrationOption[];
|
||||
payments?: Payment[];
|
||||
// Tranche-aware total the backend attaches to registration responses.
|
||||
totalDueComputed?: number | null;
|
||||
};
|
||||
|
||||
export type Ticket = {
|
||||
@@ -167,11 +274,16 @@ export type Ticket = {
|
||||
registrationOptionId?: string;
|
||||
userId: string;
|
||||
eventId: string;
|
||||
quantity?: number;
|
||||
isUsed: boolean;
|
||||
emailSent: boolean;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
event?: Pick<Event, "id" | "title">;
|
||||
emailSent?: boolean;
|
||||
attendeeId?: string | null;
|
||||
holderUserId?: string | null;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
user?: UserSummary;
|
||||
event?: Event;
|
||||
registrationOption?: RegistrationOption;
|
||||
};
|
||||
|
||||
export type Payment = {
|
||||
@@ -179,9 +291,61 @@ export type Payment = {
|
||||
amount: number;
|
||||
method: string;
|
||||
userId: string;
|
||||
registrationId?: string;
|
||||
eventId?: string;
|
||||
recordedById?: string | null;
|
||||
registrationId?: string | null;
|
||||
eventId?: string | null;
|
||||
isDonation?: boolean;
|
||||
isSponsorship?: boolean;
|
||||
status?: string | null;
|
||||
externalId?: string | null;
|
||||
originalPaymentId?: string | null;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
user?: UserSummary;
|
||||
recordedBy?: UserSummary | null;
|
||||
event?: Pick<Event, "id" | "title"> | null;
|
||||
registration?: Registration | null;
|
||||
};
|
||||
|
||||
// A page of results from a paginated list endpoint (/api/users, /api/payments, ...).
|
||||
export type Paginated<T> = {
|
||||
data: T[];
|
||||
total: number;
|
||||
page: number;
|
||||
pages: number;
|
||||
};
|
||||
|
||||
// /api/stats/{staff,supervisor,admin} — dashboard summaries.
|
||||
export type ScanStats = {
|
||||
totalToday: number;
|
||||
myToday: number;
|
||||
lastHour: number;
|
||||
byStaff: { scannedById: string; name: string; count: number }[];
|
||||
};
|
||||
|
||||
export type PaymentStats = {
|
||||
totalToday: number;
|
||||
donationsToday?: number;
|
||||
totalWeek?: number;
|
||||
totalMonth?: number;
|
||||
};
|
||||
|
||||
export type RecentScan = {
|
||||
id: string;
|
||||
scannedAt: string;
|
||||
quantityRedeemed: number;
|
||||
scannedById?: string;
|
||||
scannedBy?: { id: string; name: string } | null;
|
||||
ticket?: {
|
||||
id: string;
|
||||
eventId?: string;
|
||||
event?: { title: string } | null;
|
||||
registrationOption?: { eventOption?: { name: string } | null } | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
export type DashboardStats = {
|
||||
scanStats: ScanStats;
|
||||
recentScans: RecentScan[];
|
||||
paymentStats: PaymentStats;
|
||||
activeEventsCount: number;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user