From d615f6ca8abcf34721b819502076cec45befdfd0 Mon Sep 17 00:00:00 2001 From: "pramod.mahajan" Date: Wed, 3 Dec 2025 14:53:14 +0530 Subject: [PATCH] added required start tick on field base proforma and base amount --- src/components/purchase/ManagePurchase.jsx | 3 +-- src/components/purchase/PurchasePartyDetails.jsx | 14 +++++++++++--- src/components/purchase/PurchasePaymentDetails.jsx | 14 ++++++++++---- src/components/purchase/PurchaseSchema.jsx | 11 ++++++++--- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/components/purchase/ManagePurchase.jsx b/src/components/purchase/ManagePurchase.jsx index 591c5984..bb53c70b 100644 --- a/src/components/purchase/ManagePurchase.jsx +++ b/src/components/purchase/ManagePurchase.jsx @@ -136,8 +136,7 @@ const ManagePurchase = ({ onClose, purchaseId }) => { }, [purchaseId, generatePatchOps, updatePurchase, CreateInvoice] ); - console.log(formState.errors) - console.log(formState.formData) + return (
{/* --- Steps Header --- */} diff --git a/src/components/purchase/PurchasePartyDetails.jsx b/src/components/purchase/PurchasePartyDetails.jsx index 6c275dce..8b5c007d 100644 --- a/src/components/purchase/PurchasePartyDetails.jsx +++ b/src/components/purchase/PurchasePartyDetails.jsx @@ -25,6 +25,14 @@ const PurchasePartyDetails = () => { formState: { errors }, } = useAppFormContext(); + const hasNumber = !! watch('proformaInvoiceNumber'); + const hasAmount = + watch("proformaInvoiceAmount") !== null && watch("proformaInvoiceAmount") > 0; + const hasDate = !!watch("proformaInvoiceDate"); + + // If any one field is filled → all must be valid + const anyField = hasNumber || hasAmount || hasDate; + return (
{/* Title */} @@ -179,7 +187,7 @@ const PurchasePartyDetails = () => { {/* Proforma Invoice */}
- + { )}
- + { )}
- + { shouldValidate: true, }); }; - + const hasNumber = !!watch("proformaInvoiceNumber"); return (
- + {
- + {
- + (Number.isNaN(val) ? null : val)), + .transform((val) => (Number.isNaN(val) ? null : val)) + .refine((val) => val === null || val >= 0, { + message: "Total amount must be 0 or greater", + }), + paymentDueDate: z.coerce.date().nullable(), transportCharges: z .number() @@ -117,7 +121,7 @@ export const PurchaseSchema = z path: ["baseAmount"], }); } - if (data.taxAmount === null || data.taxAmount === 0) { + if (data.taxAmount === null) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Tax amount is required.", @@ -133,13 +137,14 @@ export const PurchaseSchema = z }); } - if (data.transportCharges === null || data.transportCharges === 0) { + if (data.transportCharges === null) { ctx.addIssue({ code: z.ZodIssueCode.custom, message: "Transport charges are required.", path: ["transportCharges"], }); } + return; } });