removed all required condition

This commit is contained in:
pramod.mahajan 2025-12-02 17:23:03 +05:30
parent aa2e732ff4
commit 3bfe108dab
4 changed files with 53 additions and 48 deletions

View File

@ -73,15 +73,16 @@ const PurchasePartyDetails = () => {
control={control} control={control}
render={({ field }) => ( render={({ field }) => (
<SelectFieldSearch <SelectFieldSearch
{...field}
label="Organization" label="Organization"
placeholder="Select Organization" placeholder="Select Organization"
required required
value={field.value}
onChange={field.onChange}
valueKey="id" valueKey="id"
labelKey="name" labelKey="name"
useFetchHook={useGlobaleOrganizations} useFetchHook={useGlobaleOrganizations}
hookParams={[ITEMS_PER_PAGE, 1]} hookParams={[ITEMS_PER_PAGE, 1]}
error={errors?.organizationId?.message} errors={errors?.organizationId}
/> />
)} )}
/> />
@ -109,7 +110,7 @@ const PurchasePartyDetails = () => {
</div> </div>
<div className="col-12 col-md-6 my-0"> <div className="col-12 col-md-6 my-0">
<Label htmlFor="billingAddress">Billing Address</Label> <Label required htmlFor="billingAddress">Billing Address</Label>
<textarea <textarea
id="billingAddress" id="billingAddress"
@ -124,7 +125,7 @@ const PurchasePartyDetails = () => {
</div> </div>
<div className="col-12 col-md-6 my-0 mb-1"> <div className="col-12 col-md-6 my-0 mb-1">
<Label htmlFor="shippingAddress">Shipping Address</Label> <Label required htmlFor="shippingAddress">Shipping Address</Label>
<textarea <textarea
id="shippingAddress" id="shippingAddress"
@ -140,7 +141,7 @@ const PurchasePartyDetails = () => {
{/* Purchase Order Number */} {/* Purchase Order Number */}
<div className="col-12 col-md-6 "> <div className="col-12 col-md-6 ">
<Label htmlFor="purchaseOrderNumber" required> <Label htmlFor="purchaseOrderNumber" >
Purchase Order Number Purchase Order Number
</Label> </Label>
@ -160,7 +161,7 @@ const PurchasePartyDetails = () => {
{/* Purchase Order Date */} {/* Purchase Order Date */}
<div className="col-12 col-md-6 mb-1"> <div className="col-12 col-md-6 mb-1">
<Label htmlFor="purchaseOrderDate" required> <Label htmlFor="purchaseOrderDate" >
Purchase Order Date Purchase Order Date
</Label> </Label>

View File

@ -26,15 +26,16 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
const baseAmount = watch("baseAmount"); const baseAmount = watch("baseAmount");
const taxAmount = watch("taxAmount"); const taxAmount = watch("taxAmount");
const trCharge = watch("transportCharges");
useEffect(() => { useEffect(() => {
const base = parseFloat(baseAmount) || 0; const base = parseFloat(baseAmount) || 0;
const tax = parseFloat(taxAmount) || 0; const tax = parseFloat(taxAmount) || 0;
const transportCharges = parseFloat(trCharge) || 0;
if (base || tax) { if (base || tax || transportCharges) {
setValue("totalAmount", (base + tax).toFixed(2)); setValue("totalAmount", (base + tax + transportCharges));
} }
}, [baseAmount, taxAmount, setValue]); }, [baseAmount, taxAmount, trCharge, setValue]);
const invoiceAttachmentType = watch("invoiceAttachmentTypeId"); const invoiceAttachmentType = watch("invoiceAttachmentTypeId");
const files = watch("attachments"); const files = watch("attachments");
const toBase64 = (file) => const toBase64 = (file) =>
@ -108,9 +109,7 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
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" required> <Label htmlFor="baseAmount">Base Amount</Label>
Base Amount
</Label>
<input <input
id="baseAmount" id="baseAmount"
@ -127,9 +126,7 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
</div> </div>
<div className="col-12 col-md-4"> <div className="col-12 col-md-4">
<Label htmlFor="taxAmount" required> <Label htmlFor="taxAmount">Tax Amount</Label>
Tax Amount
</Label>
<input <input
id="taxAmount" id="taxAmount"
@ -144,28 +141,7 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
</div> </div>
)} )}
</div> </div>
<div className="col-12 col-md-4"> <div className="col-12 col-md-4">
<Label htmlFor="totalAmount" required>
Total Amount
</Label>
<input
id="totalAmount"
type="number"
className="form-control form-control-xs"
{...register("totalAmount", { valueAsNumber: true })}
readOnly
/>
{errors?.totalAmount && (
<div className="small danger-text mt-1">
{errors.totalAmount.message}
</div>
)}
</div>
<div className="col-12 col-md-6">
<Label htmlFor="transportCharges">Transport Charges</Label> <Label htmlFor="transportCharges">Transport Charges</Label>
<input <input
@ -182,6 +158,23 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
)} )}
</div> </div>
<div className="col-12 col-md-6">
<Label htmlFor="totalAmount">Total Amount</Label>
<input
id="totalAmount"
type="number"
className="form-control form-control-xs"
{...register("totalAmount", { valueAsNumber: true })}
/>
{errors?.totalAmount && (
<div className="small danger-text mt-1">
{errors.totalAmount.message}
</div>
)}
</div>
<div className="col-12 col-md-6"> <div className="col-12 col-md-6">
<Label htmlFor="paymentDueDate">Payment Due Date</Label> <Label htmlFor="paymentDueDate">Payment Due Date</Label>
@ -200,9 +193,7 @@ const PurchasePaymentDetails = ({ purchaseId = null }) => {
</div> </div>
<div className="col-12 mb-2"> <div className="col-12 mb-2">
<Label htmlFor="description" required> <Label htmlFor="description">Description</Label>
Description
</Label>
<textarea <textarea
id="description" id="description"

View File

@ -48,12 +48,25 @@ export const PurchaseSchema = z.object({
acknowledgmentDate: z.coerce.date().nullable(), acknowledgmentDate: z.coerce.date().nullable(),
acknowledgmentNumber: z.string().nullable(), acknowledgmentNumber: z.string().nullable(),
baseAmount: z.number().min(1, { message: "Base amount is required" }), baseAmount: z
taxAmount: z.number().min(1, { message: "Tax amount is required" }), .number()
totalAmount: z.number().min(1, { message: "Total amount is required" }), .or(z.nan()) // allow NaN
.transform((val) => (Number.isNaN(val) ? null : val)),
taxAmount: z
.number()
.or(z.nan()) // allow NaN
.transform((val) => (Number.isNaN(val) ? null : val)),
totalAmount: z
.number()
.or(z.nan()) // allow NaN
.transform((val) => (Number.isNaN(val) ? null : val)),
paymentDueDate: z.coerce.date().nullable(), paymentDueDate: z.coerce.date().nullable(),
transportCharges: z.number().nullable(), transportCharges: z
description: z.string().min(1, { message: "Description is required" }), .number()
.or(z.nan()) // allow NaN
.transform((val) => (Number.isNaN(val) ? null : val)),
description: z.string(),
invoiceAttachmentTypeId: z.string().nullable(), invoiceAttachmentTypeId: z.string().nullable(),
attachments: z.array(AttachmentSchema), attachments: z.array(AttachmentSchema),
}); });
@ -85,7 +98,7 @@ export const defaultPurchaseValue = {
taxAmount: 0, taxAmount: 0,
totalAmount: 0, totalAmount: 0,
paymentDueDate: null, paymentDueDate: null,
transportCharges: null, transportCharges: 0,
description: "", description: "",
invoiceAttachmentTypeId: null, invoiceAttachmentTypeId: null,
attachments: [], attachments: [],

View File

@ -13,7 +13,7 @@ const PurchaseTransportDetails = () => {
<div className="row g-3 text-start"> <div className="row g-3 text-start">
{/* Invoice Number */} {/* Invoice Number */}
<div className="col-12 col-md-6"> <div className="col-12 col-md-6">
<Label htmlFor="invoiceNumber" required> <Label htmlFor="invoiceNumber" >
Invoice Number Invoice Number
</Label> </Label>