This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { z } from "zod"
|
||||
|
||||
export const mealPreferenceSchema = z.enum([
|
||||
"meat",
|
||||
"fish",
|
||||
"vegetarian",
|
||||
"vegan",
|
||||
"kids",
|
||||
"other",
|
||||
])
|
||||
|
||||
const optionalText = z.preprocess(
|
||||
(value) => {
|
||||
if (typeof value !== "string") return null
|
||||
|
||||
const trimmed = value.trim()
|
||||
return trimmed.length > 0 ? trimmed : null
|
||||
},
|
||||
z.string().nullable(),
|
||||
)
|
||||
|
||||
const optionalDate = z.preprocess(
|
||||
(value) => {
|
||||
if (typeof value !== "string") return null
|
||||
|
||||
const trimmed = value.trim()
|
||||
return trimmed.length > 0 ? trimmed : null
|
||||
},
|
||||
z.iso.date().nullable(),
|
||||
)
|
||||
|
||||
const memberResponseSchema = z
|
||||
.object({
|
||||
memberId: z.uuid(),
|
||||
attending: z.boolean(),
|
||||
mealPreference: mealPreferenceSchema.nullable(),
|
||||
dietaryRestrictions: optionalText,
|
||||
})
|
||||
.refine((value) => !value.attending || value.mealPreference !== null, {
|
||||
message: "Meal preference is required for attending guests",
|
||||
path: ["mealPreference"],
|
||||
})
|
||||
|
||||
export const submitInvitationResponseSchema = z.object({
|
||||
token: z.string().min(1),
|
||||
members: z.array(memberResponseSchema).min(1),
|
||||
arrivalDate: optionalDate,
|
||||
departureDate: optionalDate,
|
||||
stayLocation: optionalText,
|
||||
needsTransportHelp: z.boolean().nullable(),
|
||||
messageToCouple: optionalText,
|
||||
})
|
||||
|
||||
export type SubmitInvitationResponseInput = z.infer<typeof submitInvitationResponseSchema>
|
||||
export type MealPreference = z.infer<typeof mealPreferenceSchema>
|
||||
Reference in New Issue
Block a user