Compare commits
1 Commits
main
...
Collection
| Author | SHA1 | Date | |
|---|---|---|---|
| 246abee37b |
@ -16,10 +16,16 @@ import {
|
|||||||
import { formatFileSize, localToUtc } from "../../utils/appUtils";
|
import { formatFileSize, localToUtc } from "../../utils/appUtils";
|
||||||
import { useCollectionContext } from "../../pages/collections/CollectionPage";
|
import { useCollectionContext } from "../../pages/collections/CollectionPage";
|
||||||
import { formatDate } from "../../utils/dateUtils";
|
import { formatDate } from "../../utils/dateUtils";
|
||||||
|
import { SelectProjectField } from "../common/Forms/SelectFieldServerSide";
|
||||||
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
|
import { useOrganizationsList } from "../../hooks/useOrganization";
|
||||||
|
|
||||||
const ManageCollection = ({ collectionId, onClose }) => {
|
const ManageCollection = ({ collectionId, onClose }) => {
|
||||||
const { data, isError, isLoading, error } = useCollection(collectionId);
|
const { data, isError, isLoading, error } = useCollection(collectionId);
|
||||||
const { projectNames, projectLoading } = useProjectName(true);
|
const { projectNames, projectLoading } = useProjectName(true);
|
||||||
|
const { data: organization, isLoading: isLoadingOrganization } =
|
||||||
|
useOrganizationsList(ITEMS_PER_PAGE, 1, true);
|
||||||
|
|
||||||
const methods = useForm({
|
const methods = useForm({
|
||||||
resolver: zodResolver(newCollection),
|
resolver: zodResolver(newCollection),
|
||||||
defaultValues: defaultCollection,
|
defaultValues: defaultCollection,
|
||||||
@ -138,6 +144,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
taxAmount: data?.taxAmount,
|
taxAmount: data?.taxAmount,
|
||||||
basicAmount: data?.basicAmount,
|
basicAmount: data?.basicAmount,
|
||||||
description: data?.description,
|
description: data?.description,
|
||||||
|
billedToId: data?.billedToId,
|
||||||
attachments: data.attachments
|
attachments: data.attachments
|
||||||
? data.attachments.map((doc) => ({
|
? data.attachments.map((doc) => ({
|
||||||
fileName: doc.fileName,
|
fileName: doc.fileName,
|
||||||
@ -164,35 +171,60 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
<form onSubmit={handleSubmit(onSubmit)} className="p-0 text-start">
|
<form onSubmit={handleSubmit(onSubmit)} className="p-0 text-start">
|
||||||
<div className="row px-md-1 px-0">
|
<div className="row px-md-1 px-0">
|
||||||
<div className="col-12 col-md-6 mb-2">
|
<div className="col-12 col-md-6 mb-2">
|
||||||
<Label className="form-label" required>
|
<SelectProjectField
|
||||||
Select Project
|
label="Project"
|
||||||
</Label>
|
required
|
||||||
<select
|
placeholder="Select Project"
|
||||||
className="form-select form-select-sm"
|
value={watch("projectId")}
|
||||||
{...register("projectId")}
|
onChange={(val) =>
|
||||||
>
|
setValue("projectId", val, {
|
||||||
<option value="">Select Project</option>
|
shouldDirty: true,
|
||||||
{projectLoading ? (
|
shouldValidate: true,
|
||||||
<option>Loading...</option>
|
})
|
||||||
) : (
|
}
|
||||||
projectNames?.map((project) => (
|
/>
|
||||||
<option key={project.id} value={project.id}>
|
|
||||||
{project.name}
|
|
||||||
</option>
|
|
||||||
))
|
|
||||||
)}
|
|
||||||
</select>
|
|
||||||
{errors.projectId && (
|
{errors.projectId && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">{errors.projectId.message}</small>
|
||||||
{errors.projectId.message}
|
|
||||||
</small>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="col-12 col-md-6 mb-2">
|
||||||
|
<Label htmlFor="name" required>
|
||||||
|
Bill To
|
||||||
|
</Label>
|
||||||
|
<div className="d-flex align-items-center gap-2">
|
||||||
|
<select
|
||||||
|
className="select2 form-select form-select flex-grow-1"
|
||||||
|
aria-label="Default select example"
|
||||||
|
{...register("billedToId", {
|
||||||
|
required: "Client is required",
|
||||||
|
valueAsNumber: false,
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<option>Loading...</option>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<option value="">Select Client</option>
|
||||||
|
{organization?.data?.map((org) => (
|
||||||
|
<option key={org.id} value={org.id}>
|
||||||
|
{org.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{errors?.clientId && (
|
||||||
|
<span className="danger-text">{errors.billedToId.message}</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="col-12 col-md-6 mb-2">
|
<div className="col-12 col-md-6 mb-2">
|
||||||
<Label required>Title</Label>
|
<Label required>Title</Label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
{...register("title")}
|
{...register("title")}
|
||||||
/>
|
/>
|
||||||
{errors.title && (
|
{errors.title && (
|
||||||
@ -203,7 +235,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
<Label required>Invoice Number</Label>
|
<Label required>Invoice Number</Label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
{...register("invoiceNumber")}
|
{...register("invoiceNumber")}
|
||||||
/>
|
/>
|
||||||
{errors.invoiceId && (
|
{errors.invoiceId && (
|
||||||
@ -216,7 +248,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
<Label required>E-Invoice Number</Label>
|
<Label required>E-Invoice Number</Label>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
{...register("eInvoiceNumber")}
|
{...register("eInvoiceNumber")}
|
||||||
/>
|
/>
|
||||||
{errors.invoiceId && (
|
{errors.invoiceId && (
|
||||||
@ -232,6 +264,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
name="invoiceDate"
|
name="invoiceDate"
|
||||||
control={control}
|
control={control}
|
||||||
maxDate={new Date()}
|
maxDate={new Date()}
|
||||||
|
size="md"
|
||||||
/>
|
/>
|
||||||
{errors.invoiceDate && (
|
{errors.invoiceDate && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">
|
||||||
@ -246,6 +279,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
name="exceptedPaymentDate"
|
name="exceptedPaymentDate"
|
||||||
control={control}
|
control={control}
|
||||||
minDate={watch("invoiceDate")}
|
minDate={watch("invoiceDate")}
|
||||||
|
size="md"
|
||||||
/>
|
/>
|
||||||
{errors.exceptedPaymentDate && (
|
{errors.exceptedPaymentDate && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">
|
||||||
@ -260,6 +294,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
name="clientSubmitedDate"
|
name="clientSubmitedDate"
|
||||||
control={control}
|
control={control}
|
||||||
maxDate={new Date()}
|
maxDate={new Date()}
|
||||||
|
size="md"
|
||||||
/>
|
/>
|
||||||
{errors.exceptedPaymentDate && (
|
{errors.exceptedPaymentDate && (
|
||||||
<small className="danger-text">
|
<small className="danger-text">
|
||||||
@ -275,7 +310,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
id="basicAmount"
|
id="basicAmount"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
min="1"
|
min="1"
|
||||||
step="0.01"
|
step="0.01"
|
||||||
inputMode="decimal"
|
inputMode="decimal"
|
||||||
@ -294,7 +329,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
id="taxAmount"
|
id="taxAmount"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
min="1"
|
min="1"
|
||||||
step="0.01"
|
step="0.01"
|
||||||
inputMode="decimal"
|
inputMode="decimal"
|
||||||
@ -313,7 +348,7 @@ const ManageCollection = ({ collectionId, onClose }) => {
|
|||||||
</Label>
|
</Label>
|
||||||
<textarea
|
<textarea
|
||||||
id="description"
|
id="description"
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control"
|
||||||
{...register("description")}
|
{...register("description")}
|
||||||
rows="2"
|
rows="2"
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|||||||
@ -19,6 +19,7 @@ export const newCollection = z.object({
|
|||||||
invoiceDate: z.string().min(1, { message: "Date is required" }),
|
invoiceDate: z.string().min(1, { message: "Date is required" }),
|
||||||
description: z.string().trim().optional(),
|
description: z.string().trim().optional(),
|
||||||
clientSubmitedDate: z.string().min(1, { message: "Date is required" }),
|
clientSubmitedDate: z.string().min(1, { message: "Date is required" }),
|
||||||
|
billedToId: z.string().min(1, { message: "Date is required" }),
|
||||||
exceptedPaymentDate: z.string().min(1, { message: "Date is required" }),
|
exceptedPaymentDate: z.string().min(1, { message: "Date is required" }),
|
||||||
invoiceNumber: z
|
invoiceNumber: z
|
||||||
.string()
|
.string()
|
||||||
@ -75,6 +76,7 @@ export const defaultCollection = {
|
|||||||
taxAmount: "",
|
taxAmount: "",
|
||||||
basicAmount: "",
|
basicAmount: "",
|
||||||
description: "",
|
description: "",
|
||||||
|
billedToId:"",
|
||||||
attachments: [],
|
attachments: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user