recive new data and remove conflicts
This commit is contained in:
@@ -110,5 +110,16 @@
|
|||||||
"navgan_id": "کد ناوگان",
|
"navgan_id": "کد ناوگان",
|
||||||
"vehicle_type": "نوع ماشین",
|
"vehicle_type": "نوع ماشین",
|
||||||
"state_name": "وضعیت درخواست"
|
"state_name": "وضعیت درخواست"
|
||||||
|
},
|
||||||
|
"ConfirmDialog": {
|
||||||
|
"confirm": "تایید",
|
||||||
|
"context": "آیا از تایید این آیتم اطمینان دارید",
|
||||||
|
"button-confirm": "تایید",
|
||||||
|
"button-cancel": "بستن"
|
||||||
|
},
|
||||||
|
"RejectDialog": {
|
||||||
|
"reject": "عدم تایید",
|
||||||
|
"context": "آیا از عدم تایید این آیتم اطمینان دارید",
|
||||||
|
"button-reject": "عدم تایید",
|
||||||
|
"button-cancel": "بستن"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,16 +21,16 @@ const ConfirmForm = ({
|
|||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={handleClose}>
|
<Dialog open={open} onClose={handleClose}>
|
||||||
<DialogTitle>{t("delete-dialog.confirm")}</DialogTitle>
|
<DialogTitle>{t("ConfirmDialog.confirm")}</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContentText>{t("delete-dialog.context")}</DialogContentText>
|
<DialogContentText>{t("ConfirmDialog.context")}</DialogContentText>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={handleDeleteExpert} color="primary">
|
<Button onClick={handleDeleteExpert} color="primary">
|
||||||
{t("delete-dialog.button-delete")}
|
{t("ConfirmDialog.button-confirm")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleClose} color="secondary" autoFocus>
|
<Button onClick={handleClose} color="secondary" autoFocus>
|
||||||
{t("delete-dialog.button-cancel")}
|
{t("ConfirmDialog.button-cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -10,21 +10,22 @@ import { useTranslations } from "next-intl";
|
|||||||
|
|
||||||
const RejectForm = ({ open, handleClose, handleDelete, rowId, deleteData }) => {
|
const RejectForm = ({ open, handleClose, handleDelete, rowId, deleteData }) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const handleDeleteExpert = () => {
|
const handleRejectRequest = () => {
|
||||||
handleDelete();
|
handleDelete();
|
||||||
};
|
};
|
||||||
|
console.log(rowId);
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onClose={handleClose}>
|
<Dialog open={open} onClose={handleClose}>
|
||||||
<DialogTitle>{t("delete-dialog.confirm")}</DialogTitle>
|
<DialogTitle>{t("RejectDialog.reject")}</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContentText>{t("delete-dialog.context")}</DialogContentText>
|
<DialogContentText>{t("RejectDialog.context")}</DialogContentText>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={handleDeleteExpert} color="primary">
|
<Button onClick={handleRejectRequest} color="primary">
|
||||||
{t("delete-dialog.button-delete")}
|
{t("RejectDialog.button-reject")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={handleClose} color="secondary" autoFocus>
|
<Button onClick={handleClose} color="secondary" autoFocus>
|
||||||
{t("delete-dialog.button-cancel")}
|
{t("RejectDialog.button-cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -9,36 +9,40 @@ import RejectForm from "./Form/RejectForm";
|
|||||||
// import DeleteForm from "./Form/DeleteForm";
|
// import DeleteForm from "./Form/DeleteForm";
|
||||||
|
|
||||||
const TableRowActions = ({ row }) => {
|
const TableRowActions = ({ row }) => {
|
||||||
// const {
|
const {
|
||||||
// openDeleteDialog,
|
openConfirmDialog,
|
||||||
// handleOpenDeleteDialog,
|
openRejectDialog,
|
||||||
// handleCloseDeleteDialog,
|
handleOpenConfirmDialog,
|
||||||
// handleDeleteDialog,
|
handleOpenRejectDialog,
|
||||||
// rowId,
|
handleCloseConfirmDialog,
|
||||||
// deleteData,
|
handleCloseRejectDialog,
|
||||||
// } = useContext(DataTableContext);
|
handleConfirmDialog,
|
||||||
|
handleRejectDialog,
|
||||||
|
rowId,
|
||||||
|
deleteData,
|
||||||
|
} = useContext(DataTableContext);
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", flexWrap: "nowrap", gap: "8px" }}>
|
<Box sx={{ display: "flex", flexWrap: "nowrap", gap: "8px" }}>
|
||||||
<IconButton color="primary" onClick={() => handleOpenDeleteDialog(row)}>
|
<IconButton color="primary" onClick={() => handleOpenConfirmDialog(row)}>
|
||||||
<ThumbUpAltIcon />
|
<ThumbUpAltIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
{/* <ConfirmForm
|
<ConfirmForm
|
||||||
rowId={rowId}
|
rowId={rowId}
|
||||||
open={openDeleteDialog}
|
open={openConfirmDialog}
|
||||||
handleClose={handleCloseDeleteDialog}
|
handleClose={handleCloseConfirmDialog}
|
||||||
handleDelete={handleDeleteDialog}
|
handleDelete={handleConfirmDialog}
|
||||||
deleteData={deleteData}
|
deleteData={deleteData}
|
||||||
/> */}
|
/>
|
||||||
<IconButton color="primary" onClick={() => handleOpenDeleteDialog(row)}>
|
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
|
||||||
<ThumbDownIcon />
|
<ThumbDownIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
{/* <RejectForm
|
<RejectForm
|
||||||
rowId={rowId}
|
rowId={rowId}
|
||||||
open={openDeleteDialog}
|
open={openRejectDialog}
|
||||||
handleClose={handleCloseDeleteDialog}
|
handleClose={handleCloseRejectDialog}
|
||||||
handleDelete={handleDeleteDialog}
|
handleDelete={handleRejectDialog}
|
||||||
deleteData={deleteData}
|
deleteData={deleteData}
|
||||||
/> */}
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { DataTableProvider } from "@/lib/app/contexts/DatatableContext";
|
import { DataTableProvider } from "@/lib/app/contexts/DataTableContext";
|
||||||
import DataTable from "./Datatable";
|
import DataTable from "./Datatable";
|
||||||
import { ReloadDataTableProvider } from "@/lib/app/contexts/ReloadDatatableContext";
|
import { ReloadDataTableProvider } from "@/lib/app/contexts/ReloadDatatableContext";
|
||||||
|
|
||||||
|
|||||||
@@ -1,46 +1,28 @@
|
|||||||
import { useMediaQuery } from "@mui/material";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import { useState, useReducer, useCallback, useContext } from "react";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import ImageResizer from "@/core/components/ImageConvertor";
|
import { useCallback, useContext, useReducer, useState } from "react";
|
||||||
|
import { ReloadDataTableContext } from "../contexts/ReloadDatatableContext";
|
||||||
import useUser from "./useUser";
|
import useUser from "./useUser";
|
||||||
// import { ReloadDataTableContext } from "../contexts/ReloadDatatableContext";
|
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
url: "",
|
url: "",
|
||||||
rowID: "",
|
rowID: "",
|
||||||
values: {},
|
values: {},
|
||||||
image: {
|
|
||||||
key: "",
|
|
||||||
value: {},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
const reducer = (state, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "ADD_DATA":
|
case "CONFIRM_DATA":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
url: action.url,
|
url: action.url,
|
||||||
values: action.values,
|
|
||||||
image: action.image,
|
|
||||||
rowID: "",
|
|
||||||
};
|
|
||||||
case "EDIT_DATA":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
url: action.url,
|
|
||||||
values: action.values,
|
|
||||||
rowID: action.rowID,
|
rowID: action.rowID,
|
||||||
image: action.image,
|
|
||||||
};
|
};
|
||||||
case "DELETE_DATA":
|
case "REJECT_DATA":
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
url: action.url,
|
url: action.url,
|
||||||
rowID: action.rowID,
|
rowID: action.rowID,
|
||||||
values: {},
|
values: {},
|
||||||
image: {},
|
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
@@ -48,120 +30,82 @@ const reducer = (state, action) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useDataTable = () => {
|
const useDataTable = () => {
|
||||||
// const { setReloadDataTable } = useContext(ReloadDataTableContext);
|
const { setReloadDataTable } = useContext(ReloadDataTableContext);
|
||||||
const [state, dispatch] = useReducer(reducer, initialValues);
|
const [state, dispatch] = useReducer(reducer, initialValues);
|
||||||
const [drawerContent, setDrawerContent] = useState(null);
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||||
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
|
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||||
const [rowId, setRowId] = useState(null);
|
const [rowId, setRowId] = useState(null);
|
||||||
const theme = useTheme();
|
|
||||||
const { token } = useUser();
|
const { token } = useUser();
|
||||||
|
|
||||||
const drawerDirection = useMediaQuery(theme.breakpoints.up("sm"))
|
const confirmData = useCallback(async (url, rowID) => {
|
||||||
? "right"
|
dispatch({ type: "CONFIRM_DATA", url: url, rowID: rowID });
|
||||||
: "bottom";
|
|
||||||
const [sweepableDrawer, setSweepableDrawer] = useState({
|
|
||||||
bottom: false,
|
|
||||||
right: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const addData = useCallback(async (url, values, image) => {
|
|
||||||
dispatch({ type: "ADD_DATA", url: url, values: values, image: image });
|
|
||||||
if (image != null) {
|
|
||||||
var resizedAvatar = await ImageResizer(image.value);
|
|
||||||
formData.append(image.key, resizedAvatar);
|
|
||||||
axios.post(url, formData, {
|
|
||||||
headers: {
|
|
||||||
authorization: `Bearer ${token}`,
|
|
||||||
"Content-Type": "multipart/form-data",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
axios
|
axios
|
||||||
.post(url, values, {
|
.post(`${url}/${rowID}`, {
|
||||||
headers: {
|
|
||||||
authorization: `Bearer ${token}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then(() => {})
|
|
||||||
.catch(() => {});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const deleteData = useCallback(async (url, rowID) => {
|
|
||||||
dispatch({ type: "DELETE_DATA", url: url, rowID: rowID });
|
|
||||||
axios
|
|
||||||
.delete(`${url}/${rowID}`, {
|
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `Bearer ${token}`,
|
authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// setReloadDataTable(true);
|
setReloadDataTable(true);
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const editData = useCallback(async (url, values, rowID, image) => {
|
const rejectData = useCallback(async (url, rowID) => {
|
||||||
dispatch({
|
dispatch({ type: "REJECT_DATA", url: url, rowID: rowID });
|
||||||
type: "EDIT_DATA",
|
|
||||||
url: url,
|
|
||||||
values: values,
|
|
||||||
rowID: rowID,
|
|
||||||
image: image,
|
|
||||||
});
|
|
||||||
if (image != null) {
|
|
||||||
var resizedAvatar = await ImageResizer(image.value);
|
|
||||||
formData.append(image.key, resizedAvatar);
|
|
||||||
axios.post(`${url}/${rowID}`, formData, {
|
|
||||||
headers: {
|
|
||||||
authorization: `Bearer ${token}`,
|
|
||||||
"Content-Type": "multipart/form-data",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
axios
|
axios
|
||||||
.post(`${url}/${rowID}`, values, {
|
.post(`${url}/${rowID}`, {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `Bearer ${token}`,
|
authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(() => {})
|
.then(() => {
|
||||||
|
setReloadDataTable(true);
|
||||||
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const toggleDrawer = (open) => {
|
const handleOpenConfirmDialog = (row) => {
|
||||||
open == false &&
|
|
||||||
setTimeout(() => {
|
|
||||||
setDrawerContent(null);
|
|
||||||
}, theme.transitions.duration.leavingScreen);
|
|
||||||
setSweepableDrawer({ ...sweepableDrawer, [drawerDirection]: open });
|
|
||||||
};
|
|
||||||
const handleOpenDeleteDialog = (row) => {
|
|
||||||
setRowId(row.getValue("id"));
|
setRowId(row.getValue("id"));
|
||||||
setOpenDeleteDialog(true);
|
setOpenConfirmDialog(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCloseDeleteDialog = () => {
|
const handleCloseConfirmDialog = () => {
|
||||||
setOpenDeleteDialog(false);
|
setOpenConfirmDialog(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteDialog = () => {
|
const handleConfirmDialog = () => {
|
||||||
setOpenDeleteDialog(false);
|
setOpenConfirmDialog(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reject Data
|
||||||
|
const handleOpenRejectDialog = (row) => {
|
||||||
|
setRowId(row.getValue("id"));
|
||||||
|
setOpenRejectDialog(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCloseRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
// End Reject Data
|
||||||
|
|
||||||
const contextValue = {
|
const contextValue = {
|
||||||
toggleDrawer,
|
handleOpenConfirmDialog,
|
||||||
drawerDirection,
|
handleCloseConfirmDialog,
|
||||||
sweepableDrawer,
|
handleConfirmDialog,
|
||||||
setSweepableDrawer,
|
handleOpenRejectDialog,
|
||||||
setDrawerContent,
|
handleCloseRejectDialog,
|
||||||
drawerContent,
|
handleRejectDialog,
|
||||||
openDeleteDialog,
|
|
||||||
handleOpenDeleteDialog,
|
|
||||||
handleCloseDeleteDialog,
|
|
||||||
handleDeleteDialog,
|
|
||||||
rowId,
|
rowId,
|
||||||
deleteData,
|
openConfirmDialog,
|
||||||
addData,
|
openRejectDialog,
|
||||||
|
rejectData,
|
||||||
|
confirmData,
|
||||||
};
|
};
|
||||||
return contextValue;
|
return contextValue;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user