ĐTB
Định Trương Bá

Default Component - Copy this React, Tailwind Component to your project

chỉnh tôi muốn có đầu đủ như này : const schema = z.object({ discount_name: z.string().nonempty("Discount name is required"), discount_description: z.string().optional(), discount_type: z.enum(["Percentage", "Fixed Amount"]), discount_value: z.number().min(1, "Discount value must be greater than 0"), discount_start_date: z.string().nonempty("Start date is required"), discount_end_date: z.string().nonempty("End date is required"), discount_code: z.string().nonempty("Discount code is required").transform((val) => val.toUpperCase()), discount_max_usage: z.number().min(1, "Max usage must be greater than 0"), discount_min_order: z.number().min(1, "Minimum order must be greater than 0"), discount_apply_to: z.enum(["All Products", "Specific Products"]), discount_specific_products: z.string().optional(), }).superRefine((data, ctx) => { if (data.discount_apply_to === "Specific Products" && !data.discount_specific_products) { ctx.addIssue({ path: ["discount_specific_products"], message: "This field is required when 'Discount Apply To' is 'Specific Products'", }); } if (data.discount_type === "Percentage" && (data.discount_value < 5 || data.discount_value > 60)) { ctx.addIssue({ path: ["discount_value"], message: "Percentage discount must be between 5 and 60", }); } if (data.discount_type === "Fixed Amount" && data.discount_value <= 0) { ctx.addIssue({ path: ["discount_value"], message: "Fixed amount discount must be greater than 0", }) } });

Prompt
Component Preview

About

DefaultComponent - A stylish discount form for your shop, featuring easy input fields, validation, and responsive design, built with Rea. Start coding now!

Share

Last updated 1 month ago