diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index b0373e7..a7b7a9a 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -173,5 +173,10 @@ "button-cancel": "بستن", "description": "توضیحات", "description_error": "وارد کردن توضیحات الزامی است!" + }, + "UploadSystem": { + "upload_file": "آپلود فایل", + "delete": "پاک کردن", + "uploadfile_error": "حجم فایل بیشتر از 2 مگابایت می باشد" } } diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx index 08e21b6..6166ff4 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx @@ -12,11 +12,19 @@ import { useTranslations } from "next-intl"; import { useState } from "react"; import { useFormik } from "formik"; import * as Yup from "yup"; +import UploadSystem from "@/core/components/UploadSystem"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; +import useDirection from "@/lib/app/hooks/useDirection"; const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { const t = useTranslations(); + const { directionApp } = useDirection(); const [proposedAmount, setProposedAmount] = useState(""); const [description, setDescription] = useState(""); + const [selectedImage, setSelectedImage] = useState(""); + const [fileType, setfileType] = useState(null); + const [fileName, setfileName] = useState(null); + const [showAddIcon, setShowAddIcon] = useState(true); //formik const validationSchema = Yup.object().shape({ @@ -47,6 +55,23 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { formik.handleChange(event); }; + const handleUploadChange = (event) => { + const uploadedFile = event.target?.files?.[0]; + if (uploadedFile) { + const maxFileSize = 2 * 1024 * 1024; + if (uploadedFile.size > maxFileSize) { + UploadFileNotification(directionApp, t); + 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); + setShowAddIcon(false); + } + }; return ( {t("ConfirmDialog.confirm")} @@ -86,6 +111,19 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { sx={{ mt: 1 }} fullWidth /> + - - - - - {formik.errors.fileData && formik.errors.fileData} - + - - - - - {formik.errors.fileData && formik.errors.fileData} - + + + )} + + + ); +}; + +export default UploadSystem; diff --git a/src/core/components/notifications/UploadFileNotification.jsx b/src/core/components/notifications/UploadFileNotification.jsx new file mode 100644 index 0000000..d06783b --- /dev/null +++ b/src/core/components/notifications/UploadFileNotification.jsx @@ -0,0 +1,37 @@ +import DangerousIcon from "@mui/icons-material/Dangerous"; +import { Box, Typography } from "@mui/material"; +import { toast } from "react-toastify"; + +const UploadFileNotification = (directionApp, t) => { + toast( + ({ closeToast }) => ( + <> + + + + + + {t("UploadSystem.uploadfile_error")} + + + + + + ), + { + position: directionApp === "ltr" ? "top-left" : "top-right", + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); +}; + +export default UploadFileNotification;