@@ -1,7 +1,7 @@
|
||||
import { useEffect, useRef, useState, type FC } from "react";
|
||||
import Button from "@/components/Button";
|
||||
import Select from "@/components/Select";
|
||||
import { TickSquare } from "iconsax-react";
|
||||
import { Add, TickSquare } from "iconsax-react";
|
||||
import { toast } from "@/shared/toast";
|
||||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
import { Paths } from "@/config/Paths";
|
||||
@@ -57,7 +57,6 @@ const CreateInvoice: FC = () => {
|
||||
userId: !requestId
|
||||
? Yup.string().required("انتخاب مشتری اجباری است.")
|
||||
: Yup.string(),
|
||||
approvalDeadline: Yup.string().required("مهلت تایید اجباری است."),
|
||||
}),
|
||||
onSubmit: async (values) => {
|
||||
const validItems = items.filter(
|
||||
@@ -92,8 +91,12 @@ const CreateInvoice: FC = () => {
|
||||
description: i.description || "",
|
||||
})),
|
||||
enableTax: values.enableTax,
|
||||
approvalDeadline: moment(values.approvalDeadline, 'jYYYY/jMM/jDD').format('YYYY-MM-DD'),
|
||||
...(values.paymentMethod ? { paymentMethod: values.paymentMethod } : {}),
|
||||
...(values.approvalDeadline
|
||||
? { approvalDeadline: moment(values.approvalDeadline, 'jYYYY/jMM/jDD').format('YYYY-MM-DD') }
|
||||
: {}),
|
||||
...(values.paymentMethod?.trim()
|
||||
? { paymentMethod: values.paymentMethod.trim() }
|
||||
: {}),
|
||||
description: values.description,
|
||||
...(attachments.length ? { attachments } : {}),
|
||||
};
|
||||
@@ -141,8 +144,8 @@ const CreateInvoice: FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const addItem = (currentIndex: number) => {
|
||||
const current = items[currentIndex];
|
||||
const addItem = () => {
|
||||
const current = items[items.length - 1];
|
||||
const hasProduct = !!current?.productId;
|
||||
const hasQuantity = (current?.quantity ?? 0) > 0;
|
||||
const hasUnitPrice = (current?.unitPrice ?? 0) > 0;
|
||||
@@ -208,11 +211,21 @@ const CreateInvoice: FC = () => {
|
||||
item={item}
|
||||
index={index}
|
||||
onChange={handleItemChange}
|
||||
onAdd={() => addItem(index)}
|
||||
onRemove={() => removeItem(index)}
|
||||
canRemove={items.length > 1}
|
||||
/>
|
||||
))}
|
||||
<div className="mt-4 ">
|
||||
<button
|
||||
type="button"
|
||||
onClick={addItem}
|
||||
className="h-10 px-4 rounded-xl bg-primary flex items-center gap-2 hover:opacity-90 transition-opacity"
|
||||
aria-label="افزودن آیتم"
|
||||
>
|
||||
<Add size={18} color="black" />
|
||||
<span className="text-[13px] font-light">افزودن آیتم</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 flex gap-2 items-center">
|
||||
@@ -256,11 +269,6 @@ const CreateInvoice: FC = () => {
|
||||
value={formik.values.paymentMethod}
|
||||
onChange={(e) => formik.setFieldValue("paymentMethod", e.target.value)}
|
||||
onBlur={formik.handleBlur}
|
||||
error_text={
|
||||
formik.errors.paymentMethod && formik.touched.paymentMethod
|
||||
? formik.errors.paymentMethod
|
||||
: ""
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user