diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 089955b..ef91fef 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -109,13 +109,15 @@ "updated_at": "تاریخ بروزرسانی", "navgan_id": "کد ناوگان", "vehicle_type": "نوع ماشین", - "state_name": "وضعیت درخواست" + "state_name": "وضعیت درخواست", + "proposed_amount": "مقدار پیشنهادی" }, "ConfirmDialog": { "confirm": "تایید", "context": "آیا از تایید این آیتم اطمینان دارید", "button-confirm": "تایید", - "button-cancel": "بستن" + "button-cancel": "بستن", + "amount_error": "وارد کردن مقدار پیشنهادی الزامیست" }, "RejectDialog": { "reject": "عدم تایید", diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx index 5fd3f3b..754abce 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx @@ -1,3 +1,4 @@ +import { CONFIRM_MACHINARY_OFFICE } from "@/core/data/apiRoutes"; import { Dialog, DialogTitle, @@ -5,32 +6,86 @@ import { DialogContentText, DialogActions, Button, + TextField, } from "@mui/material"; import { useTranslations } from "next-intl"; +import { useState } from "react"; +import { useFormik } from "formik"; +import * as Yup from "yup"; -const ConfirmForm = ({ - open, - handleClose, - handleDelete, - rowId, - deleteData, -}) => { +const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => { const t = useTranslations(); - const handleDeleteExpert = () => { - handleDelete(); + const [proposedAmount, setProposedAmount] = useState(""); + const [description, setDescription] = useState(""); + + //formik + const validationSchema = Yup.object().shape({ + proposed_amount: Yup.string().required(t("ConfirmDialog.amount_error")), + }); + const formik = useFormik({ + initialValues: { + proposed_amount: "", + description: "", + }, + validationSchema, + onSubmit: () => { + const formData = new FormData(); + formData.append("proposed_amount", proposedAmount); + if (description != "") formData.append("expert_description", description); + handleClose(); + confirmData(CONFIRM_MACHINARY_OFFICE, rowId, formData); + }, + }); + + const handleDescriptionChange = (event) => { + setDescription(event.target.value); }; + const handleAmountChange = (event) => { + setProposedAmount(event.target.value); + formik.handleChange(event); + }; + return ( - {t("delete-dialog.confirm")} + {t("ConfirmDialog.confirm")} - {t("delete-dialog.context")} + {t("ConfirmDialog.context")} + + - diff --git a/src/components/dashboard/machinary-office/Form/RejectForm.jsx b/src/components/dashboard/machinary-office/Form/RejectForm.jsx index cf551a8..723f9a6 100644 --- a/src/components/dashboard/machinary-office/Form/RejectForm.jsx +++ b/src/components/dashboard/machinary-office/Form/RejectForm.jsx @@ -1,3 +1,4 @@ +import { REJECT_MACHINARY_OFFICE } from "@/core/data/apiRoutes"; import { Dialog, DialogTitle, @@ -5,29 +6,71 @@ import { DialogContentText, DialogActions, Button, + TextField, } from "@mui/material"; import { useTranslations } from "next-intl"; +import { useFormik } from "formik"; +import * as Yup from "yup"; +import { useState } from "react"; -const RejectForm = ({ open, handleClose, handleDelete, rowId, deleteData }) => { +const RejectForm = ({ open, handleClose, rowId, rejectData }) => { const t = useTranslations(); - const handleDeleteExpert = () => { - handleDelete(); + const [description, setDescription] = useState(""); + + const validationSchema = Yup.object().shape({ + description: Yup.string().required(t("RejectDialog.description_error")), + }); + + const formik = useFormik({ + initialValues: { + description: "", + }, + validationSchema, + onSubmit: () => { + const formData = new FormData(); + formData.append("expert_description", description); + handleClose(); + rejectData(REJECT_MACHINARY_OFFICE, rowId, formData); + }, + }); + + const handleDescriptionChange = (event) => { + setDescription(event.target.value); + formik.handleChange(event); }; + return ( - {t("delete-dialog.confirm")} + {t("RejectDialog.reject")} - {t("delete-dialog.context")} + {t("RejectDialog.context")} + - ); }; + export default RejectForm; diff --git a/src/components/dashboard/machinary-office/TableRowActions.jsx b/src/components/dashboard/machinary-office/TableRowActions.jsx index 832e77e..e9e815e 100644 --- a/src/components/dashboard/machinary-office/TableRowActions.jsx +++ b/src/components/dashboard/machinary-office/TableRowActions.jsx @@ -6,39 +6,47 @@ import { DataTableContext } from "@/lib/app/contexts/DataTableContext"; import ConfirmForm from "./Form/ConfirmForm"; import RejectForm from "./Form/RejectForm"; -// import DeleteForm from "./Form/DeleteForm"; - const TableRowActions = ({ row }) => { - // const { - // openDeleteDialog, - // handleOpenDeleteDialog, - // handleCloseDeleteDialog, - // handleDeleteDialog, - // rowId, - // deleteData, - // } = useContext(DataTableContext); + const { + openConfirmDialog, + openRejectDialog, + handleOpenConfirmDialog, + handleOpenRejectDialog, + handleCloseConfirmDialog, + handleCloseRejectDialog, + rowId, + confirmData, + rejectData, + } = useContext(DataTableContext); return ( - handleOpenDeleteDialog(row)}> + { + handleOpenConfirmDialog(row); + }} + > - {/* */} - handleOpenDeleteDialog(row)}> + {openConfirmDialog && ( + + )} + handleOpenRejectDialog(row)}> - {/* */} + {openRejectDialog && ( + + )} ); }; diff --git a/src/components/dashboard/machinary-office/index.jsx b/src/components/dashboard/machinary-office/index.jsx index a9af448..8a88f5f 100644 --- a/src/components/dashboard/machinary-office/index.jsx +++ b/src/components/dashboard/machinary-office/index.jsx @@ -3,7 +3,7 @@ import DashboardLayouts from "@/layouts/dashboardLayouts"; import { Box, Typography } from "@mui/material"; import { useMemo } from "react"; // import TableToolbar from "./TableTollbar"; -import { GET_PASSENGER_OFFICE } from "@/core/data/apiRoutes"; +import { GET_MACHINARY_OFFICE } from "@/core/data/apiRoutes"; import { useTranslations } from "next-intl"; import TableRowActions from "./TableRowActions"; @@ -153,7 +153,7 @@ function DashboardMachinaryOfficeComponent() { { const { openConfirmDialog, @@ -22,7 +20,12 @@ const TableRowActions = ({ row }) => { } = useContext(DataTableContext); return ( - handleOpenConfirmDialog(row)}> + { + handleOpenConfirmDialog(row); + }} + > {openConfirmDialog && ( diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 5c73fcf..79046bc 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -22,3 +22,14 @@ export const CONFIRM_PASSENGER_OFFICE = export const REJECT_PASSENGER_OFFICE = BASE_URL + "/dashboard/passenger_office_chief/reject"; //passenger office + +//machinary office +export const GET_MACHINARY_OFFICE = + BASE_URL + "/dashboard/machinery_expert/show"; + +export const CONFIRM_MACHINARY_OFFICE = + BASE_URL + "/dashboard/machinery_expert/confirm"; + +export const REJECT_MACHINARY_OFFICE = + BASE_URL + "/dashboard/machinery_expert/reject"; +//passenger office diff --git a/src/lib/app/hooks/useDatatable.jsx b/src/lib/app/hooks/useDatatable.jsx index 2a9d31f..9823aca 100644 --- a/src/lib/app/hooks/useDatatable.jsx +++ b/src/lib/app/hooks/useDatatable.jsx @@ -67,6 +67,7 @@ const useDataTable = () => { setReloadDataTable(true); }) .catch((error) => { + console.log(error); Notifications(directionApp, error.response, t); }); }, []);