Add custom YCH typs for commission page
This commit is contained in:
@ -4,6 +4,7 @@ import { z } from "zod";
|
||||
|
||||
const submitPayloadSchema = z.object({
|
||||
typeId: z.string().optional().nullable(),
|
||||
customCardId: z.string().optional().nullable(),
|
||||
optionId: z.string().optional().nullable(),
|
||||
extraIds: z.array(z.string()).default([]),
|
||||
|
||||
@ -11,6 +12,23 @@ const submitPayloadSchema = z.object({
|
||||
customerEmail: z.string().email(),
|
||||
customerSocials: z.string().optional().nullable(),
|
||||
message: z.string().min(1),
|
||||
}).superRefine((data, ctx) => {
|
||||
const hasType = Boolean(data.typeId);
|
||||
const hasCustom = Boolean(data.customCardId);
|
||||
if (!hasType && !hasCustom) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["typeId"],
|
||||
message: "Missing commission type or custom card",
|
||||
});
|
||||
}
|
||||
if (hasType && hasCustom) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
path: ["typeId"],
|
||||
message: "Only one of typeId or customCardId is allowed",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export type SubmitCommissionPayload = z.infer<typeof submitPayloadSchema>;
|
||||
|
||||
Reference in New Issue
Block a user