added required start tick on field base proforma and base amount

This commit is contained in:
pramod.mahajan 2025-12-03 14:53:14 +05:30
parent 48f8d4aedb
commit d615f6ca8a
4 changed files with 30 additions and 12 deletions

View File

@ -136,8 +136,7 @@ const ManagePurchase = ({ onClose, purchaseId }) => {
}, },
[purchaseId, generatePatchOps, updatePurchase, CreateInvoice] [purchaseId, generatePatchOps, updatePurchase, CreateInvoice]
); );
console.log(formState.errors)
console.log(formState.formData)
return ( return (
<div className="bs-stepper horizontically mt-2 b-secondry shadow-none border-0"> <div className="bs-stepper horizontically mt-2 b-secondry shadow-none border-0">
{/* --- Steps Header --- */} {/* --- Steps Header --- */}

View File

@ -25,6 +25,14 @@ const PurchasePartyDetails = () => {
formState: { errors }, formState: { errors },
} = useAppFormContext(); } = 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 ( return (
<div className="row g-3 text-start"> <div className="row g-3 text-start">
{/* Title */} {/* Title */}
@ -179,7 +187,7 @@ const PurchasePartyDetails = () => {
{/* Proforma Invoice */} {/* Proforma Invoice */}
<div className="col-12 col-md-6"> <div className="col-12 col-md-6">
<Label htmlFor="proformaInvoiceNumber">Proforma Invoice Number</Label> <Label htmlFor="proformaInvoiceNumber" required={anyField ? true : hasNumber}>Proforma Invoice Number</Label>
<input <input
id="proformaInvoiceNumber" id="proformaInvoiceNumber"
type="text" type="text"
@ -194,7 +202,7 @@ const PurchasePartyDetails = () => {
)} )}
</div> </div>
<div className="col-12 col-md-6 mb-1"> <div className="col-12 col-md-6 mb-1">
<Label htmlFor="proformaInvoiceAmountt">Proforma Amount</Label> <Label htmlFor="proformaInvoiceAmountt" required={anyField ? true : hasAmount}>Proforma Amount</Label>
<input <input
id="proformaInvoiceAmount" id="proformaInvoiceAmount"
type="text" type="text"
@ -209,7 +217,7 @@ const PurchasePartyDetails = () => {
)} )}
</div> </div>
<div className="col-12 col-md-6 mb-2"> <div className="col-12 col-md-6 mb-2">
<Label htmlFor="proformaInvoiceDate">Proforma Date</Label> <Label htmlFor="proformaInvoiceDate" required={anyField ? true : hasDate}>Proforma Date</Label>
<DatePicker <DatePicker
control={control} control={control}

View File

@ -105,11 +105,13 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
shouldValidate: true, shouldValidate: true,
}); });
}; };
const hasNumber = !!watch("proformaInvoiceNumber");
return ( return (
<div className="row g-1 text-start"> <div className="row g-1 text-start">
<div className="col-12 col-md-4"> <div className="col-12 col-md-4">
<Label htmlFor="baseAmount">Base Amount</Label> <Label htmlFor="baseAmount" required={!hasNumber}>
Base Amount
</Label>
<input <input
id="baseAmount" id="baseAmount"
@ -126,7 +128,9 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
</div> </div>
<div className="col-12 col-md-4"> <div className="col-12 col-md-4">
<Label htmlFor="taxAmount">Tax Amount</Label> <Label htmlFor="taxAmount" required={!hasNumber}>
Tax Amount
</Label>
<input <input
id="taxAmount" id="taxAmount"
@ -159,7 +163,9 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
</div> </div>
<div className="col-12 col-md-6"> <div className="col-12 col-md-6">
<Label htmlFor="totalAmount">Total Amount</Label> <Label htmlFor="totalAmount" required={!hasNumber}>
Total Amount
</Label>
<input <input
id="totalAmount" id="totalAmount"

View File

@ -60,7 +60,11 @@ export const PurchaseSchema = z
totalAmount: z totalAmount: z
.number() .number()
.or(z.nan()) // allow NaN .or(z.nan()) // allow NaN
.transform((val) => (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(), paymentDueDate: z.coerce.date().nullable(),
transportCharges: z transportCharges: z
.number() .number()
@ -117,7 +121,7 @@ export const PurchaseSchema = z
path: ["baseAmount"], path: ["baseAmount"],
}); });
} }
if (data.taxAmount === null || data.taxAmount === 0) { if (data.taxAmount === null) {
ctx.addIssue({ ctx.addIssue({
code: z.ZodIssueCode.custom, code: z.ZodIssueCode.custom,
message: "Tax amount is required.", 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({ ctx.addIssue({
code: z.ZodIssueCode.custom, code: z.ZodIssueCode.custom,
message: "Transport charges are required.", message: "Transport charges are required.",
path: ["transportCharges"], path: ["transportCharges"],
}); });
} }
return;
} }
}); });