This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { supportedLanguageCodes } from "@/lib/i18n/config"
|
||||
|
||||
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 optionalEmail = z.preprocess(
|
||||
(value) => {
|
||||
if (typeof value !== "string") return null
|
||||
|
||||
const trimmed = value.trim()
|
||||
return trimmed.length > 0 ? trimmed : null
|
||||
},
|
||||
z.email().nullable(),
|
||||
)
|
||||
|
||||
export const createInvitationSchema = z
|
||||
.object({
|
||||
displayName: z.string().trim().min(1, "Display name is required"),
|
||||
language: z.enum(supportedLanguageCodes, {
|
||||
error: "Select a supported language",
|
||||
}),
|
||||
contactEmail: optionalEmail.optional().default(null),
|
||||
contactPhone: optionalText.optional().default(null),
|
||||
maxPartySize: z.coerce
|
||||
.number()
|
||||
.int("Party size must be a whole number")
|
||||
.min(1, "Party size must be at least 1"),
|
||||
allowMemberEdits: z.coerce.boolean().default(false),
|
||||
notes: optionalText.optional().default(null),
|
||||
members: z
|
||||
.array(z.string().trim().min(1))
|
||||
.min(1, "Add at least one invitation member"),
|
||||
})
|
||||
.refine((value) => value.members.length <= value.maxPartySize, {
|
||||
message: "Members cannot exceed max party size",
|
||||
path: ["members"],
|
||||
})
|
||||
|
||||
export type CreateInvitationInput = z.infer<typeof createInvitationSchema>
|
||||
Reference in New Issue
Block a user