c652c61e0c
* feat: refactor UI to use coss + coupons UI * fix: use TRPCError and remove sensitive logging in createCoupon handler - Replace plain Error with TRPCError for consistent tRPC error handling - Use INTERNAL_SERVER_ERROR for missing env configuration - Use UNAUTHORIZED for permission denied errors - Use BAD_REQUEST for API failure errors - Remove console.warn that logged username (sensitive info) Co-Authored-By: unknown <> * feat: add copy button and fix 0 on % off --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
33 lines
932 B
TypeScript
33 lines
932 B
TypeScript
import { z } from "zod";
|
|
|
|
import { emailSchema } from "@calcom/lib/emailSchema";
|
|
|
|
const DiscountType = z.enum(["percent", "fixed"]);
|
|
const CouponDuration = z.enum(["once", "repeating", "forever"]);
|
|
|
|
export const ZCreateCouponSchema = z
|
|
.object({
|
|
billingEmail: emailSchema,
|
|
discountType: DiscountType,
|
|
discountAmount: z.number().int().min(1),
|
|
currency: z.string().optional().default("USD"),
|
|
duration: CouponDuration,
|
|
durationInMonths: z.number().int().min(1).max(36).optional(),
|
|
code: z.string().min(1),
|
|
couponName: z.string().optional(),
|
|
})
|
|
.refine(
|
|
(data) => {
|
|
if (data.duration === "repeating") {
|
|
return data.durationInMonths !== undefined;
|
|
}
|
|
return true;
|
|
},
|
|
{
|
|
message: "durationInMonths is required when duration is 'repeating'",
|
|
path: ["durationInMonths"],
|
|
}
|
|
);
|
|
|
|
export type TCreateCouponSchema = z.infer<typeof ZCreateCouponSchema>;
|