diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx deleted file mode 100644 index 6319be8..0000000 --- a/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx +++ /dev/null @@ -1,141 +0,0 @@ -import {useTranslations} from "next-intl"; -import {useState} from "react"; -import { - Button, - Dialog, - DialogActions, - DialogContent, - DialogTitle, - IconButton, - Stack, - TextField, - Tooltip, - Typography -} from "@mui/material"; -import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; -import UploadSystem from "@/core/components/UploadSystem"; -import {useFormik} from "formik"; -import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; -import {CONFIRM_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes"; -import useRequest from "@/lib/app/hooks/useRequest"; -import useNotification from "@/lib/app/hooks/useNotification"; - - -const Confirm = ({rowId, fetchUrl, mutate}) => { - const t = useTranslations(); - const [selectedImage, setSelectedImage] = useState(""); - const [fileType, setfileType] = useState(null); - const [fileName, setfileName] = useState(null); - const [showAddIcon, setShowAddIcon] = useState(true); - const [openConfirmDialog, setOpenConfirmDialog] = useState(false); - const requestServer = useRequest({auth: true}) - const {update_notification} = useNotification() - - const formik = useFormik({ - initialValues: { - description: "", - confirm_img: null - }, - onSubmit: (values, {setSubmitting}) => { - const formData = new FormData(); - if (values.description != "") formData.append("expert_description", values.description); - if (values.confirm_img != null) formData.append("attachment", values.confirm_img); - - requestServer(`${CONFIRM_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { - data: formData, - }).then((response) => { - mutate(fetchUrl) - update_notification() - }).catch(() => { - }).finally(() => { - setSubmitting(false); - }); - }, - }); - - const handleDescriptionChange = (event) => { - formik.setFieldValue("description", event.target.value) - }; - 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); - setShowAddIcon(false); - } - }; - return ( - <> - - { - setOpenConfirmDialog(true) - }} - > - - - - - {t("ConfirmDialog.confirm")} - - - - - {t("ConfirmDialog.description")}{t("ConfirmDialog.optional")}} - value={formik.values.description} - onChange={handleDescriptionChange} - fullWidth - variant="outlined" - sx={{mt: 1}} - /> - - - {t("UploadSystem.upload_file")}{t("UploadSystem.optional")} - - - - - - - - - - - ); -}; -export default Confirm; \ No newline at end of file diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx new file mode 100644 index 0000000..70013f4 --- /dev/null +++ b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/ConfirmContent.jsx @@ -0,0 +1,116 @@ +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 { useFormik } from "formik"; +import { useTranslations } from "next-intl"; +import {CONFIRM_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes"; +import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; +import { useState } from "react"; + +const ConfirmContent = ({rowId, fetchUrl, mutate, setOpenConfirmDialog}) => { + const t = useTranslations(); + const [selectedImage, setSelectedImage] = useState(""); + const [fileType, setfileType] = useState(null); + const [fileName, setfileName] = useState(null); + const [showAddIcon, setShowAddIcon] = useState(true); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + + const formik = useFormik({ + initialValues: { + description: "", + confirm_img: null + }, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + if (values.description != "") formData.append("description", values.description); + if (values.confirm_img != null) formData.append("attachment", values.confirm_img); + + requestServer(`${CONFIRM_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + const handleDescriptionChange = (event) => { + formik.setFieldValue("description", event.target.value) + }; + + 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); + setShowAddIcon(false); + } + }; + + return( + <> + + + + + {t("ConfirmDialog.description")}{t("ConfirmDialog.optional")}} + value={formik.values.description} + onChange={handleDescriptionChange} + fullWidth + variant="outlined" + sx={{mt: 1}} + /> + + + {t("UploadSystem.upload_file")}{t("UploadSystem.optional")} + + + + + + + + + + ) + +} +export default ConfirmContent \ No newline at end of file diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm/index.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/index.jsx new file mode 100644 index 0000000..3683d82 --- /dev/null +++ b/src/components/dashboard/transportation-assistance/Form/ConfirmForm/index.jsx @@ -0,0 +1,31 @@ +import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material"; +import { useTranslations } from "next-intl"; +import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; +import { useState } from "react"; +import ConfirmContent from "./ConfirmContent"; + +const Confirm = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + return( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("ConfirmDialog.confirm")} + + + + ) + +} +export default Confirm; \ No newline at end of file diff --git a/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx b/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx deleted file mode 100644 index 2330e0b..0000000 --- a/src/components/dashboard/transportation-assistance/Form/RejectForm.jsx +++ /dev/null @@ -1,148 +0,0 @@ -import {REJECT_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes"; -import { - Button, - Dialog, - DialogActions, - DialogContent, - DialogTitle, - IconButton, - Stack, - TextField, - Tooltip, - Typography, -} from "@mui/material"; -import {useTranslations} from "next-intl"; -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"; -import ThumbDownIcon from "@mui/icons-material/ThumbDown"; -import useRequest from "@/lib/app/hooks/useRequest"; -import useNotification from "@/lib/app/hooks/useNotification"; - - -const Reject = ({rowId, fetchUrl, mutate}) => { - const [selectedImage, setSelectedImage] = useState(""); - const [fileType, setfileType] = useState(null); - const [fileName, setfileName] = useState(null); - const [showAddIcon, setShowAddIcon] = useState(true); - const t = useTranslations(); - const {directionApp} = useDirection(); - const [openRejectDialog, setOpenRejectDialog] = useState(false); - const requestServer = useRequest({auth: true}) - const {update_notification} = useNotification() - - const validationSchema = Yup.object().shape({ - description: Yup.string().required(t("RejectDialog.description_error")), - }); - - const formik = useFormik({ - initialValues: { - description: "", - reject_img: null - }, - validationSchema, - onSubmit: (values, {setSubmitting}) => { - const formData = new FormData(); - formData.append("expert_description", values.description); - if (values.reject_img != null) formData.append("attachment", values.reject_img); - - requestServer(`${REJECT_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { - data: formData, - }).then((response) => { - mutate(fetchUrl) - update_notification() - }).catch(() => { - }).finally(() => { - setSubmitting(false); - }); - }, - }); - - const handleDescriptionChange = (event) => { - formik.setFieldValue("description", 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(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("reject_img", uploadedFile); - setShowAddIcon(false); - } - }; - return ( - <> - - setOpenRejectDialog(true)}> - - - - - {t("RejectDialog.reject")} - - - - - - - {t("UploadSystem.upload_file")}{t("UploadSystem.optional")} - - - - - - - - - - - ); -}; -export default Reject; \ No newline at end of file diff --git a/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx b/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx new file mode 100644 index 0000000..3ce51e9 --- /dev/null +++ b/src/components/dashboard/transportation-assistance/Form/RejectForm/RejectContent.jsx @@ -0,0 +1,122 @@ +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 { useFormik } from "formik"; +import { useTranslations } from "next-intl"; +import { useState } from "react"; +import * as Yup from "yup"; +import {REJECT_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes"; + +const RejectContent = ({rowId, fetchUrl, mutate, setOpenRejectDialog}) => { + const [selectedImage, setSelectedImage] = useState(""); + const [fileType, setfileType] = useState(null); + const [fileName, setfileName] = useState(null); + const [showAddIcon, setShowAddIcon] = useState(true); + const t = useTranslations(); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + + const validationSchema = Yup.object().shape({ + description: Yup.string().required(t("RejectDialog.description_error")), + }); + + const formik = useFormik({ + initialValues: { + description: "", + reject_img: null + }, + validationSchema, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("description", values.description); + if (values.reject_img != null) formData.append("attachment", values.reject_img); + + requestServer(`${REJECT_TRANSPORTATION_ASSISTANCE}/${rowId}`, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + const handleDescriptionChange = (event) => { + formik.setFieldValue("description", 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(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("reject_img", uploadedFile); + setShowAddIcon(false); + } + }; + return( + <> + + + + + + + {t("UploadSystem.upload_file")}{t("UploadSystem.optional")} + + + + + + + + + + ) +} +export default RejectContent \ No newline at end of file diff --git a/src/components/dashboard/transportation-assistance/Form/RejectForm/index.jsx b/src/components/dashboard/transportation-assistance/Form/RejectForm/index.jsx new file mode 100644 index 0000000..678a842 --- /dev/null +++ b/src/components/dashboard/transportation-assistance/Form/RejectForm/index.jsx @@ -0,0 +1,25 @@ +import { Dialog, DialogTitle, IconButton, Tooltip } from "@mui/material" +import { useTranslations } from "next-intl"; +import { useState } from "react"; +import RejectContent from "./RejectContent"; +import ThumbDownIcon from "@mui/icons-material/ThumbDown"; + +const Reject = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openRejectDialog, setOpenRejectDialog] = useState(false); + return ( + <> + + setOpenRejectDialog(true)}> + + + + + {t("RejectDialog.reject")} + + + + ) +} +export default Reject \ No newline at end of file diff --git a/src/components/dashboard/transportation-assistance/TableRowActions.jsx b/src/components/dashboard/transportation-assistance/TableRowActions.jsx index 601240f..121d4e0 100644 --- a/src/components/dashboard/transportation-assistance/TableRowActions.jsx +++ b/src/components/dashboard/transportation-assistance/TableRowActions.jsx @@ -1,17 +1,17 @@ import {Box} from "@mui/material"; -import ConfirmForm from "./Form/ConfirmForm" -import RejectForm from "./Form/RejectForm" +import Confirm from "./Form/ConfirmForm"; +import Reject from "./Form/RejectForm"; const TableRow = ({row, mutate, fetchUrl}) => { return ( - -