diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json
index ba420e7..0500aa2 100644
--- a/public/locales/fa/app.json
+++ b/public/locales/fa/app.json
@@ -161,7 +161,7 @@
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست",
- "confirm" : "ارجاع به کارشناس ماشین آلات"
+ "confirm": "ارجاع به کارشناس ماشین آلات"
},
"CommercialChief": {
"name": "نام",
@@ -184,7 +184,7 @@
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست",
- "confirm" : "تایید نهایی و ارجاع به بانک"
+ "confirm": "تایید نهایی و ارجاع به بانک"
},
"PassengerBoss": {
"name": "نام",
@@ -196,7 +196,11 @@
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست",
- "confirm" : "ارجاع به معاون حمل و نقل"
+ "confirm": "ارجاع به معاون حمل و نقل",
+ "upload_file": "صورت جلسه کارگروه را وارد کنید",
+ "upload_file_required": "وارد کردن صورت جلسه کارگروه الزامیست",
+ "upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد",
+ "upload_file_format": "فرمت قابل قبول : png,jpg,pdf"
},
"RefahiProvinceManager": {
"name": "نام",
@@ -265,7 +269,7 @@
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست",
- "confirm" : "ارجاع به مدیر کل استانی"
+ "confirm": "ارجاع به مدیر کل استانی"
},
"InspectorExpert": {
"name": "نام",
@@ -288,10 +292,10 @@
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست",
- "confirm" : "ارجاع به کارگروه استانی",
+ "confirm": "ارجاع به کارگروه استانی",
"upload_file": "گزارش کارشناسی را وارد کنید",
"upload_file_required": "وارد کردن گزارش کارشناسی الزامیست",
- "upload_file_unit": "حداکثر 2Mb",
+ "upload_file_unit": "فایل بارگذاری شده باید حداکثر 2Mb باشد",
"upload_file_format": "فرمت قابل قبول : png,jpg,pdf",
"delete": "پاک کردن",
"phone_number": "شماره تلفن",
diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx
index 94106a1..75dd563 100644
--- a/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx
+++ b/src/components/dashboard/machinary-office/Form/ConfirmForm/ConfirmContent.jsx
@@ -1,19 +1,10 @@
import UploadSystem from "@/core/components/UploadSystem";
import useNotification from "@/lib/app/hooks/useNotification";
import useRequest from "@/lib/app/hooks/useRequest";
-import {
- Button,
- DialogActions,
- DialogContent,
- FormHelperText,
- Stack,
- TextField,
- Typography
-} from "@mui/material"
+import {Button, DialogActions, DialogContent, FormHelperText, Stack, TextField, Typography} from "@mui/material"
import {useFormik} from "formik";
import {useTranslations} from "next-intl";
import {CONFIRM_MACHINARY_OFFICE} from "@/core/data/apiRoutes";
-import UploadFileNotification from "@/core/components/notifications/UploadFileNotification";
import {useState} from "react";
import PriceField from "@/core/components/PriceField";
import * as Yup from "yup";
@@ -79,19 +70,14 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
const handleUploadChange = (event) => {
const uploadedFile = event.target?.files?.[0];
if (uploadedFile) {
- const maxFileSize = 2 * 1024 * 1024;
- if (uploadedFile.size > maxFileSize) {
- UploadFileNotification(t);
- event.target.value = "";
- return;
- }
-
const fileType = event.target?.files?.[0].type;
const fileName = event.target?.files?.[0].name;
setSelectedImage(URL.createObjectURL(uploadedFile));
setfileType(fileType);
setfileName(fileName);
- formik.setFieldValue("confirm_img", uploadedFile);
+ formik.setFieldValue("confirm_img", uploadedFile).then(() => {
+ formik.setFieldTouched("confirm_img", true);
+ })
setShowAddIcon(false);
}
};
@@ -164,16 +150,13 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
formik.touched.confirm_img &&
Boolean(formik.errors.confirm_img)
}
- helperText={
- formik.touched.confirm_img && formik.errors.confirm_img
- }
setShowAddIcon={setShowAddIcon}
showAddIcon={showAddIcon}
/>
- {formik.errors.confirm_img ? formik.errors.confirm_img : null}
+ {formik.touched.confirm_img && formik.errors.confirm_img}
diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx
index d189a6b..e51d01c 100644
--- a/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx
+++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm/ConfirmContent.jsx
@@ -1,11 +1,10 @@
import UploadSystem from "@/core/components/UploadSystem";
import useNotification from "@/lib/app/hooks/useNotification";
import useRequest from "@/lib/app/hooks/useRequest";
-import {Button, DialogActions, DialogContent, Stack, TextField, Typography} from "@mui/material"
+import {Button, DialogActions, DialogContent, FormHelperText, Stack, TextField, Typography} from "@mui/material"
import {useFormik} from "formik";
import {useTranslations} from "next-intl";
import {CONFIRM_PASSENGER_BOSS} from "@/core/data/apiRoutes";
-import UploadFileNotification from "@/core/components/notifications/UploadFileNotification";
import {useState} from "react";
import PriceField from "@/core/components/PriceField";
import * as Yup from "yup";
@@ -25,7 +24,16 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
`${t("ConfirmDialog.approved_amount_number")}`,
(value) => !isNaN(value)
).test("positive", `${t("ConfirmDialog.approved_amount_positive")}`, (value) => value >= 0)
- .required(t("ConfirmDialog.approved_amount_error"))
+ .required(t("ConfirmDialog.approved_amount_error")),
+ confirm_img: Yup.mixed()
+ .required(t("PassengerBoss.upload_file_required"))
+ .test('fileSize', `${t("PassengerBoss.upload_file_unit")}`, (value) => {
+ return value.size <= 2 * 1024 * 1024;
+ })
+ .test('fileType', `${t("PassengerBoss.upload_file_format")}`, (value) => {
+ const allowedTypes = ['image/jpg', 'image/png', 'application/pdf']; // Define your allowed file types
+ return allowedTypes.includes(value.type);
+ })
});
const formik = useFormik({
@@ -38,7 +46,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
const formData = new FormData();
formData.append("approved_amount", values.approved_amount);
if (values.description != "") formData.append("expert_description", values.description);
- if (values.confirm_img != null) formData.append("attachment", values.confirm_img);
+ formData.append("attachment", values.confirm_img);
requestServer(`${CONFIRM_PASSENGER_BOSS}/${rowId}`, 'post', {
data: formData,
@@ -60,19 +68,14 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
const handleUploadChange = (event) => {
const uploadedFile = event.target?.files?.[0];
if (uploadedFile) {
- const maxFileSize = 2 * 1024 * 1024;
- if (uploadedFile.size > maxFileSize) {
- UploadFileNotification(t);
- event.target.value = "";
- return;
- }
-
const fileType = event.target?.files?.[0].type;
const fileName = event.target?.files?.[0].name;
setSelectedImage(URL.createObjectURL(uploadedFile));
setfileType(fileType);
setfileName(fileName);
- formik.setFieldValue("confirm_img", uploadedFile);
+ formik.setFieldValue("confirm_img", uploadedFile).then(() => {
+ formik.setFieldTouched("confirm_img", true);
+ })
setShowAddIcon(false);
}
};
@@ -83,7 +86,6 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
formik.setFieldValue("approved_amount", formik.values.approved_amount)
}
};
-
return (
<>
@@ -129,7 +131,7 @@ const ConfirmContent = ({rowId, mutate, setOpenConfirmDialog}) => {
/>
- {t("UploadSystem.upload_file")}{t("UploadSystem.optional")}
+ {t("PassengerBoss.upload_file")}
{
imageSize={[250, 150]}
setShowAddIcon={setShowAddIcon}
showAddIcon={showAddIcon}
+ onBlur={() => formik.handleBlur("confirm_img")}
+ error={
+ formik.touched.confirm_img &&
+ Boolean(formik.errors.confirm_img)
+ }
/>
+
+ {formik.touched.confirm_img && formik.errors.confirm_img}
+
diff --git a/src/core/components/UploadSystem.jsx b/src/core/components/UploadSystem.jsx
index 5bdec75..7a25890 100644
--- a/src/core/components/UploadSystem.jsx
+++ b/src/core/components/UploadSystem.jsx
@@ -18,7 +18,6 @@ const UploadSystem = ({
}) => {
const t = useTranslations();
const fileInputRef = useRef(null);
-
const handleClick = () => {
fileInputRef.current.click();
};