From ac9389274e8a667b30b25186ec623cca3b366b08 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 22 Jul 2023 14:44:41 +0330 Subject: [PATCH 01/11] add minSize tooltip and delete handleClose --- public/locales/fa/app.json | 1 + .../machinary-office/Form/ConfirmForm.jsx | 8 ++-- .../machinary-office/Form/RejectForm.jsx | 8 ++-- .../machinary-office/TableRowActions.jsx | 30 +++++++------ .../dashboard/machinary-office/index.jsx | 1 + .../passenger-boss/Form/ConfirmForm.jsx | 8 ++-- .../passenger-boss/Form/RejectForm.jsx | 8 ++-- .../passenger-boss/TableRowActions.jsx | 30 +++++++------ .../dashboard/passenger-boss/index.jsx | 1 + .../passenger-office/Form/ConfirmForm.jsx | 8 ++-- .../passenger-office/Form/RejectForm.jsx | 8 ++-- .../passenger-office/TableRowActions.jsx | 30 +++++++------ .../dashboard/passenger-office/index.jsx | 1 + .../province-manager/Form/ConfirmForm.jsx | 8 ++-- .../province-manager/Form/RejectForm.jsx | 8 ++-- .../province-manager/TableRowActions.jsx | 30 +++++++------ .../dashboard/province-manager/index.jsx | 1 + .../Form/ConfirmForm.jsx | 42 +++++++++++++++---- .../Form/RejectForm.jsx | 8 ++-- .../TableRowActions.jsx | 31 ++++++++------ .../transportation-assistance/index.jsx | 1 + src/core/utils/theme.jsx | 9 ++++ .../transportation-assistance/index.jsx | 2 +- 23 files changed, 178 insertions(+), 104 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index bf81001..b0373e7 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -52,6 +52,7 @@ "Dashboard": { "dashboard_page": "داشبورد", "passenger_boss_page": "رئیس مسافر", + "transportation_assistance": "معاونت حمل و نقل", "change_password": "تغییر رمز عبور", "province_manager_page": "مدیر کل استانی", "passenger_office_page": "اداره مسافر", diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx index 55ae682..08e21b6 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx @@ -48,7 +48,7 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { }; return ( - + {t("ConfirmDialog.confirm")} {t("ConfirmDialog.context")} @@ -88,12 +88,12 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { /> - + ); diff --git a/src/components/dashboard/machinary-office/Form/RejectForm.jsx b/src/components/dashboard/machinary-office/Form/RejectForm.jsx index 723f9a6..8b6192f 100644 --- a/src/components/dashboard/machinary-office/Form/RejectForm.jsx +++ b/src/components/dashboard/machinary-office/Form/RejectForm.jsx @@ -40,7 +40,7 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { }; return ( - + {t("RejectDialog.reject")} {t("RejectDialog.context")} @@ -62,12 +62,12 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { /> - + ); diff --git a/src/components/dashboard/machinary-office/TableRowActions.jsx b/src/components/dashboard/machinary-office/TableRowActions.jsx index e9e815e..c7ee618 100644 --- a/src/components/dashboard/machinary-office/TableRowActions.jsx +++ b/src/components/dashboard/machinary-office/TableRowActions.jsx @@ -1,12 +1,14 @@ import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import ThumbDownIcon from "@mui/icons-material/ThumbDown"; -import { Box, IconButton } from "@mui/material"; +import { Box, IconButton, Tooltip } from "@mui/material"; import { useContext } from "react"; import { DataTableContext } from "@/lib/app/contexts/DataTableContext"; import ConfirmForm from "./Form/ConfirmForm"; import RejectForm from "./Form/RejectForm"; +import { useTranslations } from "next-intl"; const TableRowActions = ({ row }) => { + const t = useTranslations(); const { openConfirmDialog, openRejectDialog, @@ -20,14 +22,16 @@ const TableRowActions = ({ row }) => { } = useContext(DataTableContext); return ( - { - handleOpenConfirmDialog(row); - }} - > - - + + { + handleOpenConfirmDialog(row); + }} + > + + + {openConfirmDialog && ( { confirmData={confirmData} /> )} - handleOpenRejectDialog(row)}> - - + + handleOpenRejectDialog(row)}> + + + {openRejectDialog && ( { }; return ( - + {t("ConfirmDialog.confirm")} {t("ConfirmDialog.context")} @@ -90,12 +90,12 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { /> - + ); diff --git a/src/components/dashboard/passenger-boss/Form/RejectForm.jsx b/src/components/dashboard/passenger-boss/Form/RejectForm.jsx index 18a48a7..e163b5f 100644 --- a/src/components/dashboard/passenger-boss/Form/RejectForm.jsx +++ b/src/components/dashboard/passenger-boss/Form/RejectForm.jsx @@ -40,7 +40,7 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { }; return ( - + {t("RejectDialog.reject")} {t("RejectDialog.context")} @@ -62,12 +62,12 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { /> - + ); diff --git a/src/components/dashboard/passenger-boss/TableRowActions.jsx b/src/components/dashboard/passenger-boss/TableRowActions.jsx index e9e815e..c7ee618 100644 --- a/src/components/dashboard/passenger-boss/TableRowActions.jsx +++ b/src/components/dashboard/passenger-boss/TableRowActions.jsx @@ -1,12 +1,14 @@ import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import ThumbDownIcon from "@mui/icons-material/ThumbDown"; -import { Box, IconButton } from "@mui/material"; +import { Box, IconButton, Tooltip } from "@mui/material"; import { useContext } from "react"; import { DataTableContext } from "@/lib/app/contexts/DataTableContext"; import ConfirmForm from "./Form/ConfirmForm"; import RejectForm from "./Form/RejectForm"; +import { useTranslations } from "next-intl"; const TableRowActions = ({ row }) => { + const t = useTranslations(); const { openConfirmDialog, openRejectDialog, @@ -20,14 +22,16 @@ const TableRowActions = ({ row }) => { } = useContext(DataTableContext); return ( - { - handleOpenConfirmDialog(row); - }} - > - - + + { + handleOpenConfirmDialog(row); + }} + > + + + {openConfirmDialog && ( { confirmData={confirmData} /> )} - handleOpenRejectDialog(row)}> - - + + handleOpenRejectDialog(row)}> + + + {openRejectDialog && ( { }; return ( - + {t("ConfirmDialog.confirm")} {t("ConfirmDialog.context")} @@ -115,12 +115,12 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { - + ); diff --git a/src/components/dashboard/passenger-office/Form/RejectForm.jsx b/src/components/dashboard/passenger-office/Form/RejectForm.jsx index 149c480..6840f7c 100644 --- a/src/components/dashboard/passenger-office/Form/RejectForm.jsx +++ b/src/components/dashboard/passenger-office/Form/RejectForm.jsx @@ -40,7 +40,7 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { }; return ( - + {t("RejectDialog.reject")} {t("RejectDialog.context")} @@ -62,12 +62,12 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { /> - + ); diff --git a/src/components/dashboard/passenger-office/TableRowActions.jsx b/src/components/dashboard/passenger-office/TableRowActions.jsx index e9e815e..c7ee618 100644 --- a/src/components/dashboard/passenger-office/TableRowActions.jsx +++ b/src/components/dashboard/passenger-office/TableRowActions.jsx @@ -1,12 +1,14 @@ import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import ThumbDownIcon from "@mui/icons-material/ThumbDown"; -import { Box, IconButton } from "@mui/material"; +import { Box, IconButton, Tooltip } from "@mui/material"; import { useContext } from "react"; import { DataTableContext } from "@/lib/app/contexts/DataTableContext"; import ConfirmForm from "./Form/ConfirmForm"; import RejectForm from "./Form/RejectForm"; +import { useTranslations } from "next-intl"; const TableRowActions = ({ row }) => { + const t = useTranslations(); const { openConfirmDialog, openRejectDialog, @@ -20,14 +22,16 @@ const TableRowActions = ({ row }) => { } = useContext(DataTableContext); return ( - { - handleOpenConfirmDialog(row); - }} - > - - + + { + handleOpenConfirmDialog(row); + }} + > + + + {openConfirmDialog && ( { confirmData={confirmData} /> )} - handleOpenRejectDialog(row)}> - - + + handleOpenRejectDialog(row)}> + + + {openRejectDialog && ( { }; return ( - + {t("ConfirmDialog.confirm")} {t("ConfirmDialog.context")} @@ -115,12 +115,12 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { - + ); diff --git a/src/components/dashboard/province-manager/Form/RejectForm.jsx b/src/components/dashboard/province-manager/Form/RejectForm.jsx index 53f3c62..4cd56a5 100644 --- a/src/components/dashboard/province-manager/Form/RejectForm.jsx +++ b/src/components/dashboard/province-manager/Form/RejectForm.jsx @@ -40,7 +40,7 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { }; return ( - + {t("RejectDialog.reject")} {t("RejectDialog.context")} @@ -62,12 +62,12 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { /> - + ); diff --git a/src/components/dashboard/province-manager/TableRowActions.jsx b/src/components/dashboard/province-manager/TableRowActions.jsx index e9e815e..c7ee618 100644 --- a/src/components/dashboard/province-manager/TableRowActions.jsx +++ b/src/components/dashboard/province-manager/TableRowActions.jsx @@ -1,12 +1,14 @@ import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import ThumbDownIcon from "@mui/icons-material/ThumbDown"; -import { Box, IconButton } from "@mui/material"; +import { Box, IconButton, Tooltip } from "@mui/material"; import { useContext } from "react"; import { DataTableContext } from "@/lib/app/contexts/DataTableContext"; import ConfirmForm from "./Form/ConfirmForm"; import RejectForm from "./Form/RejectForm"; +import { useTranslations } from "next-intl"; const TableRowActions = ({ row }) => { + const t = useTranslations(); const { openConfirmDialog, openRejectDialog, @@ -20,14 +22,16 @@ const TableRowActions = ({ row }) => { } = useContext(DataTableContext); return ( - { - handleOpenConfirmDialog(row); - }} - > - - + + { + handleOpenConfirmDialog(row); + }} + > + + + {openConfirmDialog && ( { confirmData={confirmData} /> )} - handleOpenRejectDialog(row)}> - - + + handleOpenRejectDialog(row)}> + + + {openRejectDialog && ( { const t = useTranslations(); - const handleConfirm = () => { - handleClose(); - confirmData(CONFIRM_TRANSPORTATION_ASSISTANCE, rowId); + const [description, setDescription] = useState(""); + + const formik = useFormik({ + initialValues: { + description: "", + }, + onSubmit: () => { + const formData = new FormData(); + if (description != "") formData.append("expert_description", description); + handleClose(); + confirmData(CONFIRM_TRANSPORTATION_ASSISTANCE, rowId, formData); + }, + }); + + const handleDescriptionChange = (event) => { + setDescription(event.target.value); }; + return ( - + {t("ConfirmDialog.confirm")} {t("ConfirmDialog.context")} + - + ); diff --git a/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx b/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx index 262f9db..1bd1464 100644 --- a/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx +++ b/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx @@ -40,7 +40,7 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { }; return ( - + {t("RejectDialog.reject")} {t("RejectDialog.context")} @@ -62,12 +62,12 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { /> - + ); diff --git a/src/components/dashboard/transportation-assistance/TableRowActions.jsx b/src/components/dashboard/transportation-assistance/TableRowActions.jsx index e9e815e..ccd5bde 100644 --- a/src/components/dashboard/transportation-assistance/TableRowActions.jsx +++ b/src/components/dashboard/transportation-assistance/TableRowActions.jsx @@ -1,12 +1,15 @@ import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import ThumbDownIcon from "@mui/icons-material/ThumbDown"; -import { Box, IconButton } from "@mui/material"; +import { Box, IconButton, Tooltip } from "@mui/material"; import { useContext } from "react"; import { DataTableContext } from "@/lib/app/contexts/DataTableContext"; import ConfirmForm from "./Form/ConfirmForm"; import RejectForm from "./Form/RejectForm"; +import { useTranslations } from "next-intl"; const TableRowActions = ({ row }) => { + const t = useTranslations(); + const { openConfirmDialog, openRejectDialog, @@ -20,14 +23,16 @@ const TableRowActions = ({ row }) => { } = useContext(DataTableContext); return ( - { - handleOpenConfirmDialog(row); - }} - > - - + + { + handleOpenConfirmDialog(row); + }} + > + + + {openConfirmDialog && ( { confirmData={confirmData} /> )} - handleOpenRejectDialog(row)}> - - + + handleOpenRejectDialog(row)}> + + + {openRejectDialog && ( - + ); From 3f43bf9f4ac4186a1668b57811a0344315467cf1 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 22 Jul 2023 15:26:57 +0330 Subject: [PATCH 02/11] warning notification --- .../notifications/WarningNotification.jsx | 41 +++++++++++++++++++ src/core/components/notifications/index.jsx | 1 + 2 files changed, 42 insertions(+) create mode 100644 src/core/components/notifications/WarningNotification.jsx diff --git a/src/core/components/notifications/WarningNotification.jsx b/src/core/components/notifications/WarningNotification.jsx new file mode 100644 index 0000000..1451031 --- /dev/null +++ b/src/core/components/notifications/WarningNotification.jsx @@ -0,0 +1,41 @@ +import ReportIcon from "@mui/icons-material/Report"; +import { Box, Divider, Typography } from "@mui/material"; +import { toast } from "react-toastify"; + +const WarningNotification = (directionApp, t, status) => { + toast( + ({ closeToast }) => ( + <> + + + + + + {t("warning")} ({t("code")}: {status}) + + + {t("warning_static_text")} + + + + + + + ), + { + position: directionApp === "ltr" ? "top-left" : "top-right", + autoClose: false, + closeOnClick: false, + draggable: false, + } + ); +}; + +export default WarningNotification; diff --git a/src/core/components/notifications/index.jsx b/src/core/components/notifications/index.jsx index f9eb82c..ddef384 100644 --- a/src/core/components/notifications/index.jsx +++ b/src/core/components/notifications/index.jsx @@ -1,4 +1,5 @@ import ErrorNotification from "./ErrorNotification"; +import WarningNotification from "./WarningNotification"; import SuccessNotification from "./successNotification"; const Notifications = async (directionApp, response, t) => { From cd51ee14ab398e4f520b8d062e2f1b04a3055b4c Mon Sep 17 00:00:00 2001 From: Yasiu1376 Date: Sat, 22 Jul 2023 15:51:44 +0330 Subject: [PATCH 03/11] upload_file --- public/locales/fa/app.json | 8 + .../machinary-office/Form/ConfirmForm.jsx | 30 ++++ .../machinary-office/Form/RejectForm.jsx | 31 ++++ .../passenger-boss/Form/ConfirmForm.jsx | 30 ++++ .../passenger-boss/Form/RejectForm.jsx | 31 ++++ .../passenger-office/Form/ConfirmForm.jsx | 84 ++++------ .../passenger-office/Form/RejectForm.jsx | 33 +++- .../province-manager/Form/ConfirmForm.jsx | 84 ++++------ .../province-manager/Form/RejectForm.jsx | 30 ++++ .../Form/RejectForm.jsx | 31 +++- src/core/components/UploadSystem.jsx | 154 ++++++++++++++++++ 11 files changed, 434 insertions(+), 112 deletions(-) create mode 100644 src/core/components/UploadSystem.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index bf81001..2a80338 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -172,5 +172,13 @@ "button-cancel": "بستن", "description": "توضیحات", "description_error": "وارد کردن توضیحات الزامی است!" + }, + "UploadSystem": { + "upload_file": "آپلود فایل", + "delete": "پاک کردن", + "button-reject": "عدم تایید", + "button-cancel": "بستن", + "description": "توضیحات", + "description_error": "وارد کردن توضیحات الزامی است!" } } diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx index 55ae682..d5d415b 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx @@ -12,11 +12,16 @@ import { useTranslations } from "next-intl"; import { useState } from "react"; import { useFormik } from "formik"; import * as Yup from "yup"; +import UploadSystem from "@/core/components/UploadSystem"; const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { const t = useTranslations(); 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 +52,18 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { formik.handleChange(event); }; + const handleUploadChange = (event) => { + const uploadedFile = event.target?.files?.[0]; + if (uploadedFile) { + 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 +103,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; From 1039d61605bd50b9ae609a9dc9055e389c8aef41 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sat, 22 Jul 2023 16:32:26 +0330 Subject: [PATCH 04/11] show username under avatar --- src/layouts/dashboardLayouts/header/ProfileData.jsx | 4 ++-- src/layouts/dashboardLayouts/header/ProfileMenu.jsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/layouts/dashboardLayouts/header/ProfileData.jsx b/src/layouts/dashboardLayouts/header/ProfileData.jsx index c3fdf58..e07dba6 100644 --- a/src/layouts/dashboardLayouts/header/ProfileData.jsx +++ b/src/layouts/dashboardLayouts/header/ProfileData.jsx @@ -8,10 +8,10 @@ export default function ProfileData() { - {user.user_username} + {user.username} ); diff --git a/src/layouts/dashboardLayouts/header/ProfileMenu.jsx b/src/layouts/dashboardLayouts/header/ProfileMenu.jsx index 50f34db..1c53ef5 100644 --- a/src/layouts/dashboardLayouts/header/ProfileMenu.jsx +++ b/src/layouts/dashboardLayouts/header/ProfileMenu.jsx @@ -29,7 +29,7 @@ function ProfileMenu() { color: "primary.main", }} alt="User Image" - src={user.user_avatar} + src={user.avatar} /> From 8866cbc52fbb69141a4c86daab91c69689060e0f Mon Sep 17 00:00:00 2001 From: Yasiu1376 Date: Sat, 22 Jul 2023 17:26:19 +0330 Subject: [PATCH 05/11] upload file --- public/locales/fa/app.json | 5 +-- .../machinary-office/Form/ConfirmForm.jsx | 8 ++++ .../machinary-office/Form/RejectForm.jsx | 8 ++++ .../passenger-boss/Form/ConfirmForm.jsx | 8 ++++ .../passenger-boss/Form/RejectForm.jsx | 10 ++++- .../passenger-office/Form/ConfirmForm.jsx | 15 ++++---- .../passenger-office/Form/RejectForm.jsx | 10 ++++- .../province-manager/Form/ConfirmForm.jsx | 13 ++++--- .../province-manager/Form/RejectForm.jsx | 8 ++++ .../Form/ConfirmForm.jsx | 38 +++++++++++++++++++ .../Form/RejectForm.jsx | 8 ++++ src/core/components/UploadSystem.jsx | 7 +++- .../notifications/UploadFileNotification.jsx | 37 ++++++++++++++++++ 13 files changed, 155 insertions(+), 20 deletions(-) create mode 100644 src/core/components/notifications/UploadFileNotification.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index a4791a5..a7b7a9a 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -177,9 +177,6 @@ "UploadSystem": { "upload_file": "آپلود فایل", "delete": "پاک کردن", - "button-reject": "عدم تایید", - "button-cancel": "بستن", - "description": "توضیحات", - "description_error": "وارد کردن توضیحات الزامی است!" + "uploadfile_error": "حجم فایل بیشتر از 2 مگابایت می باشد" } } diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx index f868aa0..6166ff4 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx @@ -13,9 +13,12 @@ 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(""); @@ -55,6 +58,11 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { 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)); diff --git a/src/components/dashboard/machinary-office/Form/RejectForm.jsx b/src/components/dashboard/machinary-office/Form/RejectForm.jsx index 69f7e61..70c606c 100644 --- a/src/components/dashboard/machinary-office/Form/RejectForm.jsx +++ b/src/components/dashboard/machinary-office/Form/RejectForm.jsx @@ -13,9 +13,12 @@ import { useFormik } from "formik"; import * as Yup from "yup"; import { useState } from "react"; import UploadSystem from "@/core/components/UploadSystem"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; +import useDirection from "@/lib/app/hooks/useDirection"; const RejectForm = ({ open, handleClose, rowId, rejectData }) => { const t = useTranslations(); + const { directionApp } = useDirection(); const [description, setDescription] = useState(""); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); @@ -47,6 +50,11 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { 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)); diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx index d8f3b00..788305c 100644 --- a/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx +++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx @@ -13,9 +13,12 @@ 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(""); @@ -56,6 +59,11 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { 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)); diff --git a/src/components/dashboard/passenger-boss/Form/RejectForm.jsx b/src/components/dashboard/passenger-boss/Form/RejectForm.jsx index d430af5..eeb23c1 100644 --- a/src/components/dashboard/passenger-boss/Form/RejectForm.jsx +++ b/src/components/dashboard/passenger-boss/Form/RejectForm.jsx @@ -13,9 +13,12 @@ import { useFormik } from "formik"; import * as Yup from "yup"; import { useState } from "react"; import UploadSystem from "@/core/components/UploadSystem"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; +import useDirection from "@/lib/app/hooks/useDirection"; const RejectForm = ({ open, handleClose, rowId, rejectData }) => { const t = useTranslations(); + const { directionApp } = useDirection(); const [description, setDescription] = useState(""); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); @@ -43,10 +46,15 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { setDescription(event.target.value); 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)); diff --git a/src/components/dashboard/passenger-office/Form/ConfirmForm.jsx b/src/components/dashboard/passenger-office/Form/ConfirmForm.jsx index 86eced4..645c2f6 100644 --- a/src/components/dashboard/passenger-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/passenger-office/Form/ConfirmForm.jsx @@ -1,5 +1,7 @@ import UploadSystem from "@/core/components/UploadSystem"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; import { CONFIRM_PASSENGER_OFFICE } from "@/core/data/apiRoutes"; +import useDirection from "@/lib/app/hooks/useDirection"; import { Dialog, DialogTitle, @@ -8,39 +10,33 @@ import { DialogActions, Button, TextField, - FormHelperText, } from "@mui/material"; import { useFormik } from "formik"; import { useTranslations } from "next-intl"; import { useRef, useState } from "react"; -const MAX_FILE_SIZE_IN_BYTES = 2 * 1024 * 1024; const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { const t = useTranslations(); + const { directionApp } = useDirection(); const [description, setDescription] = useState(""); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); const [fileName, setfileName] = useState(null); const [showAddIcon, setShowAddIcon] = useState(true); - const formik = useFormik({ initialValues: { description: "", - fileData: null, }, onSubmit: () => { const formData = new FormData(); if (description !== "") formData.append("expert_description", description); - if (fileData !== null) formData.append("file", fileData); handleClose(); confirmData(CONFIRM_PASSENGER_OFFICE, rowId, formData); }, }); - - const handleDescriptionChange = (event) => { setDescription(event.target.value); formik.handleChange(event); @@ -49,6 +45,11 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { 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)); diff --git a/src/components/dashboard/passenger-office/Form/RejectForm.jsx b/src/components/dashboard/passenger-office/Form/RejectForm.jsx index 5ee55f1..d4ab6d6 100644 --- a/src/components/dashboard/passenger-office/Form/RejectForm.jsx +++ b/src/components/dashboard/passenger-office/Form/RejectForm.jsx @@ -13,15 +13,18 @@ import { useFormik } from "formik"; import * as Yup from "yup"; import { useState } from "react"; import UploadSystem from "@/core/components/UploadSystem"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; +import useDirection from "@/lib/app/hooks/useDirection"; const RejectForm = ({ open, handleClose, rowId, rejectData }) => { const t = useTranslations(); + const { directionApp } = useDirection(); const [description, setDescription] = useState(""); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); const [fileName, setfileName] = useState(null); const [showAddIcon, setShowAddIcon] = useState(true); - + const validationSchema = Yup.object().shape({ description: Yup.string().required(t("RejectDialog.description_error")), }); @@ -46,6 +49,11 @@ const RejectForm = ({ open, handleClose, rowId, rejectData }) => { 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)); diff --git a/src/components/dashboard/province-manager/Form/ConfirmForm.jsx b/src/components/dashboard/province-manager/Form/ConfirmForm.jsx index 0a8078f..e5c04ec 100644 --- a/src/components/dashboard/province-manager/Form/ConfirmForm.jsx +++ b/src/components/dashboard/province-manager/Form/ConfirmForm.jsx @@ -1,5 +1,7 @@ import UploadSystem from "@/core/components/UploadSystem"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; import { CONFIRM_PROVINCE_MANAGER } from "@/core/data/apiRoutes"; +import useDirection from "@/lib/app/hooks/useDirection"; import { Dialog, DialogTitle, @@ -8,15 +10,14 @@ import { DialogActions, Button, TextField, - FormHelperText, } from "@mui/material"; import { useFormik } from "formik"; import { useTranslations } from "next-intl"; import { useRef, useState } from "react"; -const MAX_FILE_SIZE_IN_BYTES = 2 * 1024 * 1024; const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { const t = useTranslations(); + const { directionApp } = useDirection(); const [description, setDescription] = useState(""); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); @@ -26,13 +27,11 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { const formik = useFormik({ initialValues: { description: "", - fileData: null, }, onSubmit: () => { const formData = new FormData(); if (description !== "") formData.append("expert_description", description); - if (fileData !== null) formData.append("file", fileData); handleClose(); confirmData(CONFIRM_PROVINCE_MANAGER, rowId, formData); }, @@ -46,6 +45,11 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { 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)); @@ -86,7 +90,6 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { setShowAddIcon={setShowAddIcon} showAddIcon={showAddIcon} /> -