240 lines
6.6 KiB
JavaScript
240 lines
6.6 KiB
JavaScript
import React from "react";
|
|
import {
|
|
AppFormController,
|
|
useAppFormContext,
|
|
} from "../../hooks/appHooks/useAppForm";
|
|
import Label from "../common/Label";
|
|
import DatePicker from "../common/DatePicker";
|
|
import {
|
|
SelectFieldSearch,
|
|
SelectProjectField,
|
|
} from "../common/Forms/SelectFieldServerSide";
|
|
import {
|
|
useGlobaleOrganizations,
|
|
useOrganization,
|
|
useOrganizationsList,
|
|
} from "../../hooks/useOrganization";
|
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
|
|
|
const PurchasePartyDetails = () => {
|
|
const {
|
|
register,
|
|
control,
|
|
setValue,
|
|
watch,
|
|
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 */}
|
|
<div className="col-12 col-md-6">
|
|
<Label htmlFor="title" required>
|
|
Title
|
|
</Label>
|
|
|
|
<input
|
|
id="title"
|
|
type="text"
|
|
className={`form-control form-control-xs `}
|
|
{...register("title")}
|
|
/>
|
|
|
|
{errors?.title && (
|
|
<div className="danger-text">{errors.title.message}</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Project ID */}
|
|
<div className="col-12 col-md-6">
|
|
<SelectProjectField
|
|
className={`form-control form-control-xs ${
|
|
errors?.projectId ? "is-invalid" : ""
|
|
}`}
|
|
label="Project"
|
|
required
|
|
placeholder="Select Project"
|
|
value={watch("projectId")}
|
|
onChange={(val) =>
|
|
setValue("projectId", val, {
|
|
shouldDirty: true,
|
|
shouldValidate: true,
|
|
})
|
|
}
|
|
errors={errors}
|
|
/>
|
|
</div>
|
|
|
|
<div className="col-12 col-md-6 my-0">
|
|
<AppFormController
|
|
name="organizationId"
|
|
control={control}
|
|
render={({ field }) => (
|
|
<SelectFieldSearch
|
|
label="Organization"
|
|
placeholder="Select Organization"
|
|
required
|
|
value={field.value}
|
|
onChange={field.onChange}
|
|
valueKey="id"
|
|
labelKey="name"
|
|
useFetchHook={useGlobaleOrganizations}
|
|
hookParams={[ITEMS_PER_PAGE, 1]}
|
|
errors={errors?.organizationId}
|
|
/>
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
<div className="col-12 col-md-6 my-0">
|
|
<AppFormController
|
|
name="supplierId"
|
|
control={control}
|
|
render={({ field }) => (
|
|
<SelectFieldSearch
|
|
label="Supplier"
|
|
placeholder="Select Organization"
|
|
required
|
|
value={field.value}
|
|
onChange={field.onChange}
|
|
valueKey="id"
|
|
labelKey="name"
|
|
useFetchHook={useGlobaleOrganizations}
|
|
hookParams={[ITEMS_PER_PAGE, 1]}
|
|
errors={errors.supplierId}
|
|
/>
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
<div className="col-12 col-md-6 my-0">
|
|
<Label required htmlFor="billingAddress">Billing Address</Label>
|
|
|
|
<textarea
|
|
id="billingAddress"
|
|
rows="2"
|
|
className={`form-control form-control-xs `}
|
|
{...register("billingAddress")}
|
|
/>
|
|
|
|
{errors?.billingAddress && (
|
|
<div className="danger-text">{errors.billingAddress.message}</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="col-12 col-md-6 my-0 mb-1">
|
|
<Label required htmlFor="shippingAddress">Shipping Address</Label>
|
|
|
|
<textarea
|
|
id="shippingAddress"
|
|
rows="2"
|
|
className={`form-control form-control-xs `}
|
|
{...register("shippingAddress")}
|
|
/>
|
|
|
|
{errors?.shippingAddress && (
|
|
<div className="danger-text">{errors.shippingAddress.message}</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Purchase Order Number */}
|
|
<div className="col-12 col-md-6 ">
|
|
<Label htmlFor="purchaseOrderNumber" >
|
|
Purchase Order Number
|
|
</Label>
|
|
|
|
<input
|
|
id="purchaseOrderNumber"
|
|
type="text"
|
|
className={`form-control form-control-xs `}
|
|
{...register("purchaseOrderNumber")}
|
|
/>
|
|
|
|
{errors?.purchaseOrderNumber && (
|
|
<div className="danger-text">
|
|
{errors.purchaseOrderNumber.message}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Purchase Order Date */}
|
|
<div className="col-12 col-md-6 mb-1">
|
|
<Label htmlFor="purchaseOrderDate" >
|
|
Purchase Order Date
|
|
</Label>
|
|
|
|
<DatePicker
|
|
control={control}
|
|
name="purchaseOrderDate"
|
|
size="xs"
|
|
className={` w-full ${
|
|
errors?.purchaseOrderDate ? "is-invalid" : ""
|
|
}`}
|
|
/>
|
|
|
|
{errors?.purchaseOrderDate && (
|
|
<div className="danger-text">{errors.purchaseOrderDate.message}</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Proforma Invoice */}
|
|
<div className="col-12 col-md-6">
|
|
<Label htmlFor="proformaInvoiceNumber" required={anyField ? true : hasNumber}>Proforma Invoice Number</Label>
|
|
<input
|
|
id="proformaInvoiceNumber"
|
|
type="text"
|
|
className={`form-control `}
|
|
{...register("proformaInvoiceNumber")}
|
|
/>
|
|
|
|
{errors?.proformaInvoiceNumber && (
|
|
<div className="danger-text">
|
|
{errors.proformaInvoiceNumber.message}
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="col-12 col-md-6 mb-1">
|
|
<Label htmlFor="proformaInvoiceAmountt" required={anyField ? true : hasAmount}>Proforma Amount</Label>
|
|
<input
|
|
id="proformaInvoiceAmount"
|
|
type="text"
|
|
className={`form-control `}
|
|
{...register("proformaInvoiceAmount")}
|
|
/>
|
|
|
|
{errors?.proformaInvoiceAmount && (
|
|
<div className="danger-text">
|
|
{errors.proformaInvoiceAmount.message}
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="col-12 col-md-6 mb-2">
|
|
<Label htmlFor="proformaInvoiceDate" required={anyField ? true : hasDate}>Proforma Date</Label>
|
|
|
|
<DatePicker
|
|
control={control}
|
|
name="proformaInvoiceDate"
|
|
className="w-full"
|
|
size="xs"
|
|
/>
|
|
|
|
{errors?.proformaInvoiceDate && (
|
|
<div className="danger-text">
|
|
{errors.proformaInvoiceDate.message}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PurchasePartyDetails;
|