up
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-06-26 11:04:03 +03:30
parent eff7744f0b
commit d6a5697998
8 changed files with 65 additions and 49 deletions
+25 -18
View File
@@ -1,12 +1,11 @@
import { useEffect, useState, type FC } from "react";
import Button from "@/components/Button";
import { TickSquare } from "iconsax-react";
import { Add, TickSquare } from "iconsax-react";
import { toast } from "@/shared/toast";
import { useNavigate, useParams } from "react-router-dom";
import { Paths } from "@/config/Paths";
import { extractErrorMessage } from "@/config/func";
import { useFormik } from "formik";
import * as Yup from "yup";
import type { CreatePreInvoiceItemType, UpdatePreInvoiceType } from "./types/Types";
import InvoiceItemRow from "./components/InvoiceItemRow";
import { Checkbox } from "@/components/ui/checkbox";
@@ -55,9 +54,6 @@ const UpdateInvoice: FC = () => {
paymentMethod: "",
description: "",
},
validationSchema: Yup.object({
approvalDeadline: Yup.string().required("مهلت تایید اجباری است."),
}),
onSubmit: async (values) => {
const validItems = items.filter(
(i) => i.productId && i.quantity > 0 && i.unitPrice >= 0
@@ -96,11 +92,17 @@ const UpdateInvoice: 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 } : {}),
};
@@ -164,8 +166,8 @@ const UpdateInvoice: 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;
@@ -231,11 +233,21 @@ const UpdateInvoice: FC = () => {
item={item}
index={index}
onChange={handleItemChange}
onAdd={() => addItem(index)}
onRemove={() => removeItem(index)}
canRemove={items.length > 1}
/>
))}
<div className="mt-4 flex justify-center">
<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">
@@ -279,11 +291,6 @@ const UpdateInvoice: 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>