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]
);
console.log(formState.errors)
console.log(formState.formData)
return (
<div className="bs-stepper horizontically mt-2 b-secondry shadow-none border-0">
{/* --- Steps Header --- */}

View File

@ -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 (
<div className="row g-3 text-start">
{/* Title */}
@ -179,7 +187,7 @@ const PurchasePartyDetails = () => {
{/* Proforma Invoice */}
<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
id="proformaInvoiceNumber"
type="text"
@ -194,7 +202,7 @@ const PurchasePartyDetails = () => {
)}
</div>
<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
id="proformaInvoiceAmount"
type="text"
@ -209,7 +217,7 @@ const PurchasePartyDetails = () => {
)}
</div>
<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
control={control}

View File

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

View File

@ -60,7 +60,11 @@ export const PurchaseSchema = z
totalAmount: z
.number()
.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(),
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;
}
});