Merge branch 'feature/maintainer' into 'develop'
cleaning datatable component and make it more flexible/ debug notification and... See merge request witel3/loan-facilities-expert!64
This commit is contained in:
@@ -16,6 +16,6 @@ NEXT_PUBLIC_SECONDARY_DARK = "#ad3a07"
|
|||||||
|
|
||||||
NEXT_PUBLIC_API_URL = "http://Your IP:3000"
|
NEXT_PUBLIC_API_URL = "http://Your IP:3000"
|
||||||
|
|
||||||
NEXT_PUBLIC_BASE_URL = "deploy api"
|
NEXT_PUBLIC_BASE_URL = "https://loan.witel.ir"
|
||||||
|
|
||||||
NODE_ENV = "development"
|
NODE_ENV = "development"
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
"notifications": {
|
"notifications": {
|
||||||
"code": "کد",
|
"code": "کد",
|
||||||
"error": "خطا",
|
"error": "خطا",
|
||||||
"warning": "خطر",
|
"warning": "خطا",
|
||||||
"success": "موفق",
|
"success": "موفق",
|
||||||
"error_static_text": "عملیات شما با خطا مواجه شد",
|
"error_static_text": "عملیات شما با خطا مواجه شد",
|
||||||
"warning_static_text": "خطا سرور",
|
"warning_static_text": "خطا سرور",
|
||||||
|
|||||||
@@ -20,13 +20,7 @@ const DashboardChangePasswordComponent = () => {
|
|||||||
const {directionApp} = useDirection();
|
const {directionApp} = useDirection();
|
||||||
|
|
||||||
const handleSubmit = (values, {setSubmitting, resetForm}) => {
|
const handleSubmit = (values, {setSubmitting, resetForm}) => {
|
||||||
toast.dismiss();
|
Notifications(directionApp, t);
|
||||||
const pendingToast = toast(t("notifications.pending"), {
|
|
||||||
position: directionApp === "ltr" ? "top-left" : "top-right",
|
|
||||||
autoClose: false,
|
|
||||||
closeOnClick: false,
|
|
||||||
draggable: false,
|
|
||||||
});
|
|
||||||
axios
|
axios
|
||||||
.post(
|
.post(
|
||||||
CHANGE_PASSWORD,
|
CHANGE_PASSWORD,
|
||||||
@@ -41,12 +35,12 @@ const DashboardChangePasswordComponent = () => {
|
|||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
toast.dismiss(pendingToast); // Dismiss the pending toast notification
|
toast.dismiss(pendingToast); // Dismiss the pending toast notification
|
||||||
Notifications(directionApp, response, t);
|
Notifications(directionApp, t, response);
|
||||||
resetForm();
|
resetForm();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast.dismiss(pendingToast); // Dismiss the pending toast notification
|
toast.dismiss(pendingToast); // Dismiss the pending toast notification
|
||||||
Notifications(directionApp, error.response, t);
|
Notifications(directionApp, t, error.response);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setSubmitting(false); // Set `setSubmitting` to false after the API request completes
|
setSubmitting(false); // Set `setSubmitting` to false after the API request completes
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const DashboardEditProfile = () => {
|
|||||||
const {directionApp} = useDirection();
|
const {directionApp} = useDirection();
|
||||||
|
|
||||||
const editAvatar = async (avatar) => {
|
const editAvatar = async (avatar) => {
|
||||||
|
Notifications(directionApp, t);
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
@@ -36,7 +37,7 @@ const DashboardEditProfile = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Notifications(directionApp, error.response, t);
|
Notifications(directionApp, t, error.response);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -54,13 +55,13 @@ const DashboardEditProfile = () => {
|
|||||||
// });
|
// });
|
||||||
// })
|
// })
|
||||||
// .then((response) => {
|
// .then((response) => {
|
||||||
// Notifications(directionApp, response, t);
|
// Notifications(directionApp, t, response);
|
||||||
// getUser((data) => {
|
// getUser((data) => {
|
||||||
// changeUser(data);
|
// changeUser(data);
|
||||||
// });
|
// });
|
||||||
// })
|
// })
|
||||||
// .catch((error) => {
|
// .catch((error) => {
|
||||||
// Notifications(directionApp, error.response, t);
|
// Notifications(directionApp, t, error.response);
|
||||||
// })
|
// })
|
||||||
// .finally(() => {
|
// .finally(() => {
|
||||||
// setSubmitting(false);
|
// setSubmitting(false);
|
||||||
@@ -74,13 +75,13 @@ const DashboardEditProfile = () => {
|
|||||||
// },
|
// },
|
||||||
// })
|
// })
|
||||||
// .then((response) => {
|
// .then((response) => {
|
||||||
// Notifications(directionApp, response, t);
|
// Notifications(directionApp, t, response);
|
||||||
// getUser((data) => {
|
// getUser((data) => {
|
||||||
// changeUser(data);
|
// changeUser(data);
|
||||||
// });
|
// });
|
||||||
// })
|
// })
|
||||||
// .catch((error) => {
|
// .catch((error) => {
|
||||||
// Notifications(directionApp, error.response, t);
|
// Notifications(directionApp, t, error.response);
|
||||||
// })
|
// })
|
||||||
// .finally(() => {
|
// .finally(() => {
|
||||||
// setSubmitting(false);
|
// setSubmitting(false);
|
||||||
|
|||||||
@@ -1,58 +1,92 @@
|
|||||||
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
||||||
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
||||||
import {Box, IconButton, Tooltip} from "@mui/material";
|
import {Box, IconButton, Tooltip} from "@mui/material";
|
||||||
import {useContext} from "react";
|
|
||||||
import ConfirmForm from "./Form/ConfirmForm";
|
import ConfirmForm from "./Form/ConfirmForm";
|
||||||
import RejectForm from "./Form/RejectForm";
|
import RejectForm from "./Form/RejectForm";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {DataTableContext} from "@/lib/app/contexts/DatatableContext";
|
import {useCallback, useState} from "react";
|
||||||
|
import axios from "axios";
|
||||||
|
import Notifications from "@/core/components/notifications";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import useDirection from "@/lib/app/hooks/useDirection";
|
||||||
|
|
||||||
const TableRowActions = ({row}) => {
|
const TableRowActions = ({row, mutate, fetchUrl}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {
|
const {token} = useUser();
|
||||||
openConfirmDialog,
|
const {directionApp} = useDirection();
|
||||||
openRejectDialog,
|
|
||||||
handleOpenConfirmDialog,
|
// Confirm
|
||||||
handleOpenRejectDialog,
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||||
handleCloseConfirmDialog,
|
const handleCloseConfirmDialog = () => {
|
||||||
handleCloseRejectDialog,
|
setOpenConfirmDialog(false);
|
||||||
rowId,
|
};
|
||||||
confirmData,
|
const confirmData = useCallback((url, rowID, values) => {
|
||||||
rejectData,
|
Notifications(directionApp, t, undefined)
|
||||||
} = useContext(DataTableContext);
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Confirm
|
||||||
|
|
||||||
|
// Reject
|
||||||
|
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||||
|
const handleCloseRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rejectData = useCallback((url, rowID, values) => {
|
||||||
|
Notifications(directionApp, t)
|
||||||
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Reject
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
||||||
<Tooltip title={t("ConfirmDialog.confirm")}>
|
<Tooltip title={t("ConfirmDialog.confirm")}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleOpenConfirmDialog(row);
|
setOpenConfirmDialog(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThumbUpAltIcon/>
|
<ThumbUpAltIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openConfirmDialog && (
|
<ConfirmForm
|
||||||
<ConfirmForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openConfirmDialog}
|
||||||
open={openConfirmDialog}
|
handleClose={handleCloseConfirmDialog}
|
||||||
handleClose={handleCloseConfirmDialog}
|
confirmData={confirmData}
|
||||||
confirmData={confirmData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Tooltip title={t("RejectDialog.reject")}>
|
<Tooltip title={t("RejectDialog.reject")}>
|
||||||
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
|
<IconButton color="primary" onClick={() => setOpenRejectDialog(true)}>
|
||||||
<ThumbDownIcon/>
|
<ThumbDownIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openRejectDialog && (
|
<RejectForm
|
||||||
<RejectForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openRejectDialog}
|
||||||
open={openRejectDialog}
|
handleClose={handleCloseRejectDialog}
|
||||||
handleClose={handleCloseRejectDialog}
|
rejectData={rejectData}
|
||||||
rejectData={rejectData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import DataTableStructure from "@/core/components/DatatableStructure";
|
|
||||||
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
||||||
import {Box, IconButton, Typography} from "@mui/material";
|
import {Box, IconButton, Typography} from "@mui/material";
|
||||||
import ClearIcon from "@mui/icons-material/Clear";
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
// import TableToolbar from "./TableTollbar";
|
|
||||||
import {GET_MACHINARY_OFFICE} from "@/core/data/apiRoutes";
|
import {GET_MACHINARY_OFFICE} from "@/core/data/apiRoutes";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import TableRowActions from "./TableRowActions";
|
import TableRowActions from "./TableRowActions";
|
||||||
@@ -11,6 +9,7 @@ import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
|||||||
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import {faIR} from "@mui/x-date-pickers/locales";
|
import {faIR} from "@mui/x-date-pickers/locales";
|
||||||
|
import DataTable from "@/core/components/DataTable";
|
||||||
|
|
||||||
function DashboardMachinaryOfficeComponent() {
|
function DashboardMachinaryOfficeComponent() {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
@@ -23,7 +22,6 @@ function DashboardMachinaryOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -94,7 +92,6 @@ function DashboardMachinaryOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "date",
|
datatype: "date",
|
||||||
filterFn: "lessThan",
|
filterFn: "lessThan",
|
||||||
minSize: 200,
|
|
||||||
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
||||||
Cell: ({renderedCellValue}) => {
|
Cell: ({renderedCellValue}) => {
|
||||||
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
||||||
@@ -170,7 +167,6 @@ function DashboardMachinaryOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -201,7 +197,6 @@ function DashboardMachinaryOfficeComponent() {
|
|||||||
header: t("MachinaryOffice.state_name"),
|
header: t("MachinaryOffice.state_name"),
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
minSize: 300,
|
|
||||||
// filterFn: "equals",
|
// filterFn: "equals",
|
||||||
// filterSelectOptions: [
|
// filterSelectOptions: [
|
||||||
// ],
|
// ],
|
||||||
@@ -216,22 +211,22 @@ function DashboardMachinaryOfficeComponent() {
|
|||||||
return (
|
return (
|
||||||
<DashboardLayouts>
|
<DashboardLayouts>
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTableStructure
|
<DataTable
|
||||||
tableUrl={GET_MACHINARY_OFFICE}
|
tableUrl={GET_MACHINARY_OFFICE}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
enableCustomToolbar={true}
|
enableCustomToolbar={true}
|
||||||
// CustomToolbar={<TableToolbar />}
|
|
||||||
enableLastUpdate={true}
|
enableLastUpdate={true}
|
||||||
enablePinning={true}
|
enablePinning={true}
|
||||||
enableDensityToggle={true}
|
enableDensityToggle={false}
|
||||||
|
initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large)
|
||||||
enableColumnFilters={true}
|
enableColumnFilters={true}
|
||||||
enableHiding={true}
|
enableHiding={true}
|
||||||
enableFullScreenToggle={false}
|
enableFullScreenToggle={false}
|
||||||
enableGlobalFilter={false}
|
enableGlobalFilter={false}
|
||||||
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
||||||
enableRowActions={true}
|
enableRowActions={true}
|
||||||
renderRowActions={({row}) => <TableRowActions row={row}/>}
|
TableRowAction={TableRowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</DashboardLayouts>
|
</DashboardLayouts>
|
||||||
|
|||||||
@@ -1,58 +1,92 @@
|
|||||||
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
||||||
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
||||||
import {Box, IconButton, Tooltip} from "@mui/material";
|
import {Box, IconButton, Tooltip} from "@mui/material";
|
||||||
import {useContext} from "react";
|
import {useCallback, useState} from "react";
|
||||||
import ConfirmForm from "./Form/ConfirmForm";
|
import ConfirmForm from "./Form/ConfirmForm";
|
||||||
import RejectForm from "./Form/RejectForm";
|
import RejectForm from "./Form/RejectForm";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {DataTableContext} from "@/lib/app/contexts/DatatableContext";
|
import Notifications from "@/core/components/notifications";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import useDirection from "@/lib/app/hooks/useDirection";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
const TableRowActions = ({row}) => {
|
const TableRowActions = ({row, mutate, fetchUrl}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {
|
const {token} = useUser();
|
||||||
openConfirmDialog,
|
const {directionApp} = useDirection();
|
||||||
openRejectDialog,
|
|
||||||
handleOpenConfirmDialog,
|
// Confirm
|
||||||
handleOpenRejectDialog,
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||||
handleCloseConfirmDialog,
|
const handleCloseConfirmDialog = () => {
|
||||||
handleCloseRejectDialog,
|
setOpenConfirmDialog(false);
|
||||||
rowId,
|
};
|
||||||
confirmData,
|
const confirmData = useCallback((url, rowID, values) => {
|
||||||
rejectData,
|
Notifications(directionApp, t, undefined)
|
||||||
} = useContext(DataTableContext);
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Confirm
|
||||||
|
|
||||||
|
// Reject
|
||||||
|
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||||
|
const handleCloseRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rejectData = useCallback((url, rowID, values) => {
|
||||||
|
Notifications(directionApp, t)
|
||||||
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Reject
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
||||||
<Tooltip title={t("ConfirmDialog.confirm")}>
|
<Tooltip title={t("ConfirmDialog.confirm")}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleOpenConfirmDialog(row);
|
setOpenConfirmDialog(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThumbUpAltIcon/>
|
<ThumbUpAltIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openConfirmDialog && (
|
<ConfirmForm
|
||||||
<ConfirmForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openConfirmDialog}
|
||||||
open={openConfirmDialog}
|
handleClose={handleCloseConfirmDialog}
|
||||||
handleClose={handleCloseConfirmDialog}
|
confirmData={confirmData}
|
||||||
confirmData={confirmData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Tooltip title={t("RejectDialog.reject")}>
|
<Tooltip title={t("RejectDialog.reject")}>
|
||||||
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
|
<IconButton color="primary" onClick={() => setOpenRejectDialog(true)}>
|
||||||
<ThumbDownIcon/>
|
<ThumbDownIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openRejectDialog && (
|
<RejectForm
|
||||||
<RejectForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openRejectDialog}
|
||||||
open={openRejectDialog}
|
handleClose={handleCloseRejectDialog}
|
||||||
handleClose={handleCloseRejectDialog}
|
rejectData={rejectData}
|
||||||
rejectData={rejectData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import DataTableStructure from "@/core/components/DatatableStructure";
|
|
||||||
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
||||||
import {Box, IconButton, Typography} from "@mui/material";
|
import {Box, IconButton, Typography} from "@mui/material";
|
||||||
import ClearIcon from "@mui/icons-material/Clear";
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
// import TableToolbar from "./TableTollbar";
|
import {GET_PASSENGER_BOSS, GET_PASSENGER_OFFICE} from "@/core/data/apiRoutes";
|
||||||
import {GET_PASSENGER_BOSS} from "@/core/data/apiRoutes";
|
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import TableRowActions from "./TableRowActions";
|
import TableRowActions from "./TableRowActions";
|
||||||
import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
||||||
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import {faIR} from "@mui/x-date-pickers/locales";
|
import {faIR} from "@mui/x-date-pickers/locales";
|
||||||
|
import DataTable from "@/core/components/DataTable";
|
||||||
|
|
||||||
function DashboardPassengerOfficeComponent() {
|
function DashboardPassengerOfficeComponent() {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
@@ -24,7 +23,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -95,7 +93,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "date",
|
datatype: "date",
|
||||||
filterFn: "lessThan",
|
filterFn: "lessThan",
|
||||||
minSize: 200,
|
|
||||||
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
||||||
Cell: ({renderedCellValue}) => {
|
Cell: ({renderedCellValue}) => {
|
||||||
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
||||||
@@ -171,7 +168,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -202,7 +198,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
header: t("PassengerBoss.state_name"),
|
header: t("PassengerBoss.state_name"),
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
minSize: 300,
|
|
||||||
// filterFn: "equals",
|
// filterFn: "equals",
|
||||||
// filterSelectOptions: [
|
// filterSelectOptions: [
|
||||||
// ],
|
// ],
|
||||||
@@ -217,7 +212,7 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
return (
|
return (
|
||||||
<DashboardLayouts>
|
<DashboardLayouts>
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTableStructure
|
<DataTable
|
||||||
tableUrl={GET_PASSENGER_BOSS}
|
tableUrl={GET_PASSENGER_BOSS}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
@@ -225,14 +220,15 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
// CustomToolbar={<TableToolbar />}
|
// CustomToolbar={<TableToolbar />}
|
||||||
enableLastUpdate={true}
|
enableLastUpdate={true}
|
||||||
enablePinning={true}
|
enablePinning={true}
|
||||||
enableDensityToggle={true}
|
enableDensityToggle={false}
|
||||||
|
initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large)
|
||||||
enableColumnFilters={true}
|
enableColumnFilters={true}
|
||||||
enableHiding={true}
|
enableHiding={true}
|
||||||
enableFullScreenToggle={false}
|
enableFullScreenToggle={false}
|
||||||
enableGlobalFilter={false}
|
enableGlobalFilter={false}
|
||||||
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
||||||
enableRowActions={true}
|
enableRowActions={true}
|
||||||
renderRowActions={({row}) => <TableRowActions row={row}/>}
|
TableRowAction={TableRowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</DashboardLayouts>
|
</DashboardLayouts>
|
||||||
|
|||||||
@@ -1,58 +1,92 @@
|
|||||||
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
||||||
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
||||||
import {Box, IconButton, Tooltip} from "@mui/material";
|
import {Box, IconButton, Tooltip} from "@mui/material";
|
||||||
import {useContext} from "react";
|
import {useCallback, useState} from "react";
|
||||||
import ConfirmForm from "./Form/ConfirmForm";
|
import ConfirmForm from "./Form/ConfirmForm";
|
||||||
import RejectForm from "./Form/RejectForm";
|
import RejectForm from "./Form/RejectForm";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {DataTableContext} from "@/lib/app/contexts/DatatableContext";
|
import axios from "axios";
|
||||||
|
import Notifications from "@/core/components/notifications";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import useDirection from "@/lib/app/hooks/useDirection";
|
||||||
|
|
||||||
const TableRowActions = ({row}) => {
|
const TableRowActions = ({row, mutate, fetchUrl}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {
|
const {token} = useUser();
|
||||||
openConfirmDialog,
|
const {directionApp} = useDirection();
|
||||||
openRejectDialog,
|
|
||||||
handleOpenConfirmDialog,
|
// Confirm
|
||||||
handleOpenRejectDialog,
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||||
handleCloseConfirmDialog,
|
const handleCloseConfirmDialog = () => {
|
||||||
handleCloseRejectDialog,
|
setOpenConfirmDialog(false);
|
||||||
rowId,
|
};
|
||||||
confirmData,
|
const confirmData = useCallback((url, rowID, values) => {
|
||||||
rejectData,
|
Notifications(directionApp, t, undefined)
|
||||||
} = useContext(DataTableContext);
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Confirm
|
||||||
|
|
||||||
|
// Reject
|
||||||
|
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||||
|
const handleCloseRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rejectData = useCallback((url, rowID, values) => {
|
||||||
|
Notifications(directionApp, t)
|
||||||
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Reject
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
||||||
<Tooltip title={t("ConfirmDialog.confirm")}>
|
<Tooltip title={t("ConfirmDialog.confirm")}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleOpenConfirmDialog(row);
|
setOpenConfirmDialog(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThumbUpAltIcon/>
|
<ThumbUpAltIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openConfirmDialog && (
|
<ConfirmForm
|
||||||
<ConfirmForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openConfirmDialog}
|
||||||
open={openConfirmDialog}
|
handleClose={handleCloseConfirmDialog}
|
||||||
handleClose={handleCloseConfirmDialog}
|
confirmData={confirmData}
|
||||||
confirmData={confirmData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Tooltip title={t("RejectDialog.reject")}>
|
<Tooltip title={t("RejectDialog.reject")}>
|
||||||
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
|
<IconButton color="primary" onClick={() => setOpenRejectDialog(true)}>
|
||||||
<ThumbDownIcon/>
|
<ThumbDownIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openRejectDialog && (
|
<RejectForm
|
||||||
<RejectForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openRejectDialog}
|
||||||
open={openRejectDialog}
|
handleClose={handleCloseRejectDialog}
|
||||||
handleClose={handleCloseRejectDialog}
|
rejectData={rejectData}
|
||||||
rejectData={rejectData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import DataTableStructure from "@/core/components/DatatableStructure";
|
|
||||||
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
||||||
import {Box, IconButton, Typography} from "@mui/material";
|
import {Box, IconButton, Typography} from "@mui/material";
|
||||||
import ClearIcon from "@mui/icons-material/Clear";
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
import {faIR} from "@mui/x-date-pickers/locales";
|
import {faIR} from "@mui/x-date-pickers/locales";
|
||||||
// import TableToolbar from "./TableTollbar";
|
|
||||||
import {GET_PASSENGER_OFFICE} from "@/core/data/apiRoutes";
|
import {GET_PASSENGER_OFFICE} from "@/core/data/apiRoutes";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import TableRowActions from "./TableRowActions";
|
import TableRowActions from "./TableRowActions";
|
||||||
import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
||||||
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
|
import DataTable from "@/core/components/DataTable";
|
||||||
|
|
||||||
function DashboardPassengerOfficeComponent() {
|
function DashboardPassengerOfficeComponent() {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
@@ -23,7 +22,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
header: t("PassengerOffice.id"),
|
header: t("PassengerOffice.id"),
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
maxSize: 100,
|
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
@@ -95,7 +93,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "date",
|
datatype: "date",
|
||||||
filterFn: "lessThan",
|
filterFn: "lessThan",
|
||||||
minSize: 200,
|
|
||||||
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
||||||
Cell: ({renderedCellValue}) => {
|
Cell: ({renderedCellValue}) => {
|
||||||
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
||||||
@@ -127,7 +124,7 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
helperText: `${t("filter_mode")}: ${t(filterFnValue)}`,
|
helperText: `${t("filter_mode")}: ${t(filterFnValue)}`,
|
||||||
sx: {minWidth: "120px"},
|
sx: {minWidth: "120px"},
|
||||||
variant: "standard",
|
variant: "standard",
|
||||||
actionBar: {actions: ["accept", "today"]},
|
actionbar: {actions: ["accept", "today"]},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
value={
|
value={
|
||||||
@@ -171,7 +168,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
header: t("PassengerOffice.navgan_id"),
|
header: t("PassengerOffice.navgan_id"),
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
maxSize: 100,
|
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
@@ -203,7 +199,6 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
header: t("PassengerOffice.state_name"),
|
header: t("PassengerOffice.state_name"),
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
minSize: 300,
|
|
||||||
// filterFn: "equals",
|
// filterFn: "equals",
|
||||||
// filterSelectOptions: [
|
// filterSelectOptions: [
|
||||||
// ],
|
// ],
|
||||||
@@ -218,7 +213,7 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
return (
|
return (
|
||||||
<DashboardLayouts>
|
<DashboardLayouts>
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTableStructure
|
<DataTable
|
||||||
tableUrl={GET_PASSENGER_OFFICE}
|
tableUrl={GET_PASSENGER_OFFICE}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
@@ -226,14 +221,15 @@ function DashboardPassengerOfficeComponent() {
|
|||||||
// CustomToolbar={<TableToolbar />}
|
// CustomToolbar={<TableToolbar />}
|
||||||
enableLastUpdate={true}
|
enableLastUpdate={true}
|
||||||
enablePinning={true}
|
enablePinning={true}
|
||||||
enableDensityToggle={true}
|
enableDensityToggle={false}
|
||||||
|
initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large)
|
||||||
enableColumnFilters={true}
|
enableColumnFilters={true}
|
||||||
enableHiding={true}
|
enableHiding={true}
|
||||||
enableFullScreenToggle={false}
|
enableFullScreenToggle={false}
|
||||||
enableGlobalFilter={false}
|
enableGlobalFilter={false}
|
||||||
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
||||||
enableRowActions={true}
|
enableRowActions={true}
|
||||||
renderRowActions={({row}) => <TableRowActions row={row}/>}
|
TableRowAction={TableRowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</DashboardLayouts>
|
</DashboardLayouts>
|
||||||
|
|||||||
@@ -1,58 +1,92 @@
|
|||||||
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
||||||
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
||||||
import {Box, IconButton, Tooltip} from "@mui/material";
|
import {Box, IconButton, Tooltip} from "@mui/material";
|
||||||
import {useContext} from "react";
|
import {useCallback, useState} from "react";
|
||||||
import ConfirmForm from "./Form/ConfirmForm";
|
import ConfirmForm from "./Form/ConfirmForm";
|
||||||
import RejectForm from "./Form/RejectForm";
|
import RejectForm from "./Form/RejectForm";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {DataTableContext} from "@/lib/app/contexts/DatatableContext";
|
import Notifications from "@/core/components/notifications";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import useDirection from "@/lib/app/hooks/useDirection";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
const TableRowActions = ({row}) => {
|
const TableRowActions = ({row, mutate, fetchUrl}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {
|
const {token} = useUser();
|
||||||
openConfirmDialog,
|
const {directionApp} = useDirection();
|
||||||
openRejectDialog,
|
|
||||||
handleOpenConfirmDialog,
|
// Confirm
|
||||||
handleOpenRejectDialog,
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||||
handleCloseConfirmDialog,
|
const handleCloseConfirmDialog = () => {
|
||||||
handleCloseRejectDialog,
|
setOpenConfirmDialog(false);
|
||||||
rowId,
|
};
|
||||||
confirmData,
|
const confirmData = useCallback((url, rowID, values) => {
|
||||||
rejectData,
|
Notifications(directionApp, t, undefined)
|
||||||
} = useContext(DataTableContext);
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Confirm
|
||||||
|
|
||||||
|
// Reject
|
||||||
|
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||||
|
const handleCloseRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rejectData = useCallback((url, rowID, values) => {
|
||||||
|
Notifications(directionApp, t)
|
||||||
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Reject
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
||||||
<Tooltip title={t("ConfirmDialog.confirm")}>
|
<Tooltip title={t("ConfirmDialog.confirm")}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleOpenConfirmDialog(row);
|
setOpenConfirmDialog(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThumbUpAltIcon/>
|
<ThumbUpAltIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openConfirmDialog && (
|
<ConfirmForm
|
||||||
<ConfirmForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openConfirmDialog}
|
||||||
open={openConfirmDialog}
|
handleClose={handleCloseConfirmDialog}
|
||||||
handleClose={handleCloseConfirmDialog}
|
confirmData={confirmData}
|
||||||
confirmData={confirmData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Tooltip title={t("RejectDialog.reject")}>
|
<Tooltip title={t("RejectDialog.reject")}>
|
||||||
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
|
<IconButton color="primary" onClick={() => setOpenRejectDialog(true)}>
|
||||||
<ThumbDownIcon/>
|
<ThumbDownIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openRejectDialog && (
|
<RejectForm
|
||||||
<RejectForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openRejectDialog}
|
||||||
open={openRejectDialog}
|
handleClose={handleCloseRejectDialog}
|
||||||
handleClose={handleCloseRejectDialog}
|
rejectData={rejectData}
|
||||||
rejectData={rejectData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import DataTableStructure from "@/core/components/DatatableStructure";
|
|
||||||
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
||||||
import {Box, IconButton, Typography} from "@mui/material";
|
import {Box, IconButton, Typography} from "@mui/material";
|
||||||
import ClearIcon from "@mui/icons-material/Clear";
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
// import TableToolbar from "./TableTollbar";
|
|
||||||
import {GET_PROVINCE_MANAGER} from "@/core/data/apiRoutes";
|
import {GET_PROVINCE_MANAGER} from "@/core/data/apiRoutes";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import TableRowActions from "./TableRowActions";
|
import TableRowActions from "./TableRowActions";
|
||||||
@@ -11,6 +9,7 @@ import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
|||||||
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
import {faIR} from "@mui/x-date-pickers/locales";
|
import {faIR} from "@mui/x-date-pickers/locales";
|
||||||
|
import DataTable from "@/core/components/DataTable";
|
||||||
|
|
||||||
function DashboardProvinceManagerComponent() {
|
function DashboardProvinceManagerComponent() {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
@@ -24,7 +23,6 @@ function DashboardProvinceManagerComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -95,7 +93,6 @@ function DashboardProvinceManagerComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "date",
|
datatype: "date",
|
||||||
filterFn: "lessThan",
|
filterFn: "lessThan",
|
||||||
minSize: 200,
|
|
||||||
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
||||||
Cell: ({renderedCellValue}) => {
|
Cell: ({renderedCellValue}) => {
|
||||||
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
return <Typography variant="body2">{renderedCellValue}</Typography>;
|
||||||
@@ -171,7 +168,6 @@ function DashboardProvinceManagerComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -202,7 +198,6 @@ function DashboardProvinceManagerComponent() {
|
|||||||
header: t("ProvinceManager.state_name"),
|
header: t("ProvinceManager.state_name"),
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
minSize: 300,
|
|
||||||
// filterFn: "equals",
|
// filterFn: "equals",
|
||||||
// filterSelectOptions: [
|
// filterSelectOptions: [
|
||||||
// ],
|
// ],
|
||||||
@@ -217,22 +212,22 @@ function DashboardProvinceManagerComponent() {
|
|||||||
return (
|
return (
|
||||||
<DashboardLayouts>
|
<DashboardLayouts>
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTableStructure
|
<DataTable
|
||||||
tableUrl={GET_PROVINCE_MANAGER}
|
tableUrl={GET_PROVINCE_MANAGER}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
enableCustomToolbar={true}
|
enableCustomToolbar={true}
|
||||||
// CustomToolbar={<TableToolbar />}
|
|
||||||
enableLastUpdate={true}
|
enableLastUpdate={true}
|
||||||
enablePinning={true}
|
enablePinning={true}
|
||||||
enableDensityToggle={true}
|
enableDensityToggle={false}
|
||||||
|
initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large)
|
||||||
enableColumnFilters={true}
|
enableColumnFilters={true}
|
||||||
enableHiding={true}
|
enableHiding={true}
|
||||||
enableFullScreenToggle={false}
|
enableFullScreenToggle={false}
|
||||||
enableGlobalFilter={false}
|
enableGlobalFilter={false}
|
||||||
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
||||||
enableRowActions={true}
|
enableRowActions={true}
|
||||||
renderRowActions={({row}) => <TableRowActions row={row}/>}
|
TableRowAction={TableRowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</DashboardLayouts>
|
</DashboardLayouts>
|
||||||
|
|||||||
@@ -1,59 +1,92 @@
|
|||||||
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
|
||||||
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
|
||||||
import {Box, IconButton, Tooltip} from "@mui/material";
|
import {Box, IconButton, Tooltip} from "@mui/material";
|
||||||
import {useContext} from "react";
|
import {useCallback, useState} from "react";
|
||||||
import ConfirmForm from "./Form/ConfirmForm";
|
import ConfirmForm from "./Form/ConfirmForm";
|
||||||
import RejectForm from "./Form/RejectForm";
|
import RejectForm from "./Form/RejectForm";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {DataTableContext} from "@/lib/app/contexts/DatatableContext";
|
import Notifications from "@/core/components/notifications";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import useDirection from "@/lib/app/hooks/useDirection";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
const TableRowActions = ({row}) => {
|
const TableRowActions = ({row, mutate, fetchUrl}) => {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
const {token} = useUser();
|
||||||
|
const {directionApp} = useDirection();
|
||||||
|
|
||||||
|
// Confirm
|
||||||
|
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
||||||
|
const handleCloseConfirmDialog = () => {
|
||||||
|
setOpenConfirmDialog(false);
|
||||||
|
};
|
||||||
|
const confirmData = useCallback((url, rowID, values) => {
|
||||||
|
Notifications(directionApp, t, undefined)
|
||||||
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Confirm
|
||||||
|
|
||||||
|
// Reject
|
||||||
|
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
||||||
|
const handleCloseRejectDialog = () => {
|
||||||
|
setOpenRejectDialog(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rejectData = useCallback((url, rowID, values) => {
|
||||||
|
Notifications(directionApp, t)
|
||||||
|
axios
|
||||||
|
.post(`${url}/${rowID}`, values, {
|
||||||
|
headers: {authorization: `Bearer ${token}`},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
Notifications(directionApp, t, response);
|
||||||
|
mutate(fetchUrl)
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Notifications(directionApp, t, error.response);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
// End Reject
|
||||||
|
|
||||||
const {
|
|
||||||
openConfirmDialog,
|
|
||||||
openRejectDialog,
|
|
||||||
handleOpenConfirmDialog,
|
|
||||||
handleOpenRejectDialog,
|
|
||||||
handleCloseConfirmDialog,
|
|
||||||
handleCloseRejectDialog,
|
|
||||||
rowId,
|
|
||||||
confirmData,
|
|
||||||
rejectData,
|
|
||||||
} = useContext(DataTableContext);
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
<Box sx={{display: "flex", flexWrap: "nowrap", gap: "8px"}}>
|
||||||
<Tooltip title={t("ConfirmDialog.confirm")}>
|
<Tooltip title={t("ConfirmDialog.confirm")}>
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleOpenConfirmDialog(row);
|
setOpenConfirmDialog(true)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ThumbUpAltIcon/>
|
<ThumbUpAltIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openConfirmDialog && (
|
<ConfirmForm
|
||||||
<ConfirmForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openConfirmDialog}
|
||||||
open={openConfirmDialog}
|
handleClose={handleCloseConfirmDialog}
|
||||||
handleClose={handleCloseConfirmDialog}
|
confirmData={confirmData}
|
||||||
confirmData={confirmData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<Tooltip title={t("RejectDialog.reject")}>
|
<Tooltip title={t("RejectDialog.reject")}>
|
||||||
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
|
<IconButton color="primary" onClick={() => setOpenRejectDialog(true)}>
|
||||||
<ThumbDownIcon/>
|
<ThumbDownIcon/>
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
{openRejectDialog && (
|
<RejectForm
|
||||||
<RejectForm
|
rowId={row.getValue("id")}
|
||||||
rowId={rowId}
|
open={openRejectDialog}
|
||||||
open={openRejectDialog}
|
handleClose={handleCloseRejectDialog}
|
||||||
handleClose={handleCloseRejectDialog}
|
rejectData={rejectData}
|
||||||
rejectData={rejectData}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import DataTableStructure from "@/core/components/DatatableStructure";
|
|
||||||
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
import DashboardLayouts from "@/layouts/dashboardLayouts";
|
||||||
import {Box, IconButton, Typography} from "@mui/material";
|
import {Box, IconButton, Typography} from "@mui/material";
|
||||||
import ClearIcon from "@mui/icons-material/Clear";
|
import ClearIcon from "@mui/icons-material/Clear";
|
||||||
import {useMemo} from "react";
|
import {useMemo} from "react";
|
||||||
// import TableToolbar from "./TableTollbar";
|
|
||||||
import {GET_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes";
|
import {GET_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import TableRowActions from "./TableRowActions";
|
import TableRowActions from "./TableRowActions";
|
||||||
@@ -11,6 +9,7 @@ import {LocalizationProvider, MobileDateTimePicker,} from "@mui/x-date-pickers";
|
|||||||
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
import {AdapterDateFnsJalali} from "@mui/x-date-pickers/AdapterDateFnsJalali";
|
||||||
import {faIR} from "@mui/x-date-pickers/locales";
|
import {faIR} from "@mui/x-date-pickers/locales";
|
||||||
import moment from "jalali-moment";
|
import moment from "jalali-moment";
|
||||||
|
import DataTable from "@/core/components/DataTable";
|
||||||
|
|
||||||
function DashboardTransportationAssistanceComponent() {
|
function DashboardTransportationAssistanceComponent() {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
@@ -23,7 +22,6 @@ function DashboardTransportationAssistanceComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -94,7 +92,6 @@ function DashboardTransportationAssistanceComponent() {
|
|||||||
header: t("TransportationAssistance.created_at"),
|
header: t("TransportationAssistance.created_at"),
|
||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "date",
|
datatype: "date",
|
||||||
minSize: 200,
|
|
||||||
filterFn: "lessThan",
|
filterFn: "lessThan",
|
||||||
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
columnFilterModeOptions: ["lessThan", "greaterThan"],
|
||||||
Cell: ({renderedCellValue}) => (
|
Cell: ({renderedCellValue}) => (
|
||||||
@@ -171,7 +168,6 @@ function DashboardTransportationAssistanceComponent() {
|
|||||||
enableColumnFilter: true,
|
enableColumnFilter: true,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
maxSize: 100,
|
|
||||||
columnFilterModeOptions: [
|
columnFilterModeOptions: [
|
||||||
"equals",
|
"equals",
|
||||||
"notEquals",
|
"notEquals",
|
||||||
@@ -202,7 +198,6 @@ function DashboardTransportationAssistanceComponent() {
|
|||||||
header: t("TransportationAssistance.state_name"),
|
header: t("TransportationAssistance.state_name"),
|
||||||
enableColumnFilter: false,
|
enableColumnFilter: false,
|
||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
minSize: 300,
|
|
||||||
// filterFn: "equals",
|
// filterFn: "equals",
|
||||||
// filterSelectOptions: [
|
// filterSelectOptions: [
|
||||||
// ],
|
// ],
|
||||||
@@ -217,22 +212,22 @@ function DashboardTransportationAssistanceComponent() {
|
|||||||
return (
|
return (
|
||||||
<DashboardLayouts>
|
<DashboardLayouts>
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTableStructure
|
<DataTable
|
||||||
tableUrl={GET_TRANSPORTATION_ASSISTANCE}
|
tableUrl={GET_TRANSPORTATION_ASSISTANCE}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
enableCustomToolbar={true}
|
enableCustomToolbar={true}
|
||||||
// CustomToolbar={<TableToolbar />}
|
|
||||||
enableLastUpdate={true}
|
enableLastUpdate={true}
|
||||||
enablePinning={true}
|
enablePinning={true}
|
||||||
enableDensityToggle={true}
|
enableDensityToggle={false}
|
||||||
|
initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large)
|
||||||
enableColumnFilters={true}
|
enableColumnFilters={true}
|
||||||
enableHiding={true}
|
enableHiding={true}
|
||||||
enableFullScreenToggle={false}
|
enableFullScreenToggle={false}
|
||||||
enableGlobalFilter={false}
|
enableGlobalFilter={false}
|
||||||
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions
|
||||||
enableRowActions={true}
|
enableRowActions={true}
|
||||||
renderRowActions={({row}) => <TableRowActions row={row}/>}
|
TableRowAction={TableRowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</DashboardLayouts>
|
</DashboardLayouts>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ const LoginComponent = () => {
|
|||||||
<Box
|
<Box
|
||||||
sx={{position: "relative", width: "100%", height: 200}}
|
sx={{position: "relative", width: "100%", height: 200}}
|
||||||
>
|
>
|
||||||
<Image fill src="/images/login.svg" alt={t("app_name")} priority/>
|
<Image fill src="/images/login.svg" alt={t("app_name")}/>
|
||||||
</Box>
|
</Box>
|
||||||
<Typography margin={2} variant="h4" textAlign="center">
|
<Typography margin={2} variant="h4" textAlign="center">
|
||||||
{t("login_expert")}
|
{t("login_expert")}
|
||||||
|
|||||||
@@ -1,23 +1,21 @@
|
|||||||
import {ReloadDataTableContext} from "@/lib/app/contexts/ReloadDatatableContext";
|
|
||||||
import useLanguage from "@/lib/app/hooks/useLanguage";
|
|
||||||
import {Typography} from "@mui/material";
|
|
||||||
import axios from "axios";
|
|
||||||
import MaterialReactTable from "material-react-table";
|
|
||||||
import moment from "moment-jalaali";
|
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {useContext, useEffect, useMemo, useState} from "react";
|
import useLanguage from "@/lib/app/hooks/useLanguage";
|
||||||
|
import {useEffect, useMemo, useState} from "react";
|
||||||
|
import moment from "moment-jalaali";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import {Typography} from "@mui/material";
|
||||||
|
import MaterialReactTable from "material-react-table";
|
||||||
|
import axios from "axios";
|
||||||
|
import useUser from "@/lib/app/hooks/useUser";
|
||||||
|
import {css} from "@emotion/react";
|
||||||
|
|
||||||
const DataTable = (props) => {
|
function DataTable(props) {
|
||||||
const {reloadDataTable, setReloadDataTable} = useContext(
|
const {token} = useUser();
|
||||||
ReloadDataTableContext
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetcher = (...args) => {
|
const fetcher = (...args) => {
|
||||||
return axios
|
return axios
|
||||||
.get(args, {
|
.get(args, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${props.token}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -28,6 +26,9 @@ const DataTable = (props) => {
|
|||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const {languageApp, languageList} = useLanguage();
|
const {languageApp, languageList} = useLanguage();
|
||||||
const [columnFilters, setColumnFilters] = useState([]);
|
const [columnFilters, setColumnFilters] = useState([]);
|
||||||
|
const [sorting, setSorting] = useState([]);
|
||||||
|
const [pagination, setPagination] = useState({pageIndex: 0, pageSize: 10});
|
||||||
|
const [rowCount, setRowCount] = useState(0);
|
||||||
const [columnFilterFns, setColumnFilterFns] = useState(() => {
|
const [columnFilterFns, setColumnFilterFns] = useState(() => {
|
||||||
let output = {};
|
let output = {};
|
||||||
const list = props.columns.map((item) =>
|
const list = props.columns.map((item) =>
|
||||||
@@ -41,9 +42,7 @@ const DataTable = (props) => {
|
|||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
});
|
});
|
||||||
const [sorting, setSorting] = useState([]);
|
|
||||||
const [pagination, setPagination] = useState({pageIndex: 0, pageSize: 10});
|
|
||||||
const [rowCount, setRowCount] = useState(0);
|
|
||||||
const [updateTime, setupdateTime] = useState(
|
const [updateTime, setupdateTime] = useState(
|
||||||
moment().format("HH:mm | jYYYY/jM/jD")
|
moment().format("HH:mm | jYYYY/jM/jD")
|
||||||
);
|
);
|
||||||
@@ -55,7 +54,7 @@ const DataTable = (props) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const fetchUrl = useMemo(() => {
|
const fetchUrl = useMemo(() => {
|
||||||
const url = new URL(props.tableUrl /* send your api */);
|
const url = new URL(props.tableUrl);
|
||||||
url.searchParams.set(
|
url.searchParams.set(
|
||||||
"start",
|
"start",
|
||||||
`${pagination.pageIndex * pagination.pageSize}`
|
`${pagination.pageIndex * pagination.pageSize}`
|
||||||
@@ -85,18 +84,11 @@ const DataTable = (props) => {
|
|||||||
sorting,
|
sorting,
|
||||||
props.columns,
|
props.columns,
|
||||||
]);
|
]);
|
||||||
const {data, isLoading, isValidating, mutate} = useSWR(fetchUrl, fetcher, {
|
|
||||||
|
const {data, isValidating, mutate} = useSWR(fetchUrl, fetcher, {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (reloadDataTable) {
|
|
||||||
mutate(fetchUrl).then(() => {
|
|
||||||
setReloadDataTable(false); // Set reloadDataTable to false after mutation is complete
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [reloadDataTable, setReloadDataTable]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setupdateTime(moment().format("HH:mm | jYYYY/jM/jD"));
|
setupdateTime(moment().format("HH:mm | jYYYY/jM/jD"));
|
||||||
}, [isValidating, languageApp]);
|
}, [isValidating, languageApp]);
|
||||||
@@ -104,7 +96,6 @@ const DataTable = (props) => {
|
|||||||
return (
|
return (
|
||||||
<MaterialReactTable
|
<MaterialReactTable
|
||||||
localization={tableLocalization}
|
localization={tableLocalization}
|
||||||
columns={props.columns} /* columns you send */
|
|
||||||
data={data ?? []}
|
data={data ?? []}
|
||||||
manualFiltering
|
manualFiltering
|
||||||
manualPagination
|
manualPagination
|
||||||
@@ -112,16 +103,28 @@ const DataTable = (props) => {
|
|||||||
enableRowSelection={props.selectableRow} /* send condition */
|
enableRowSelection={props.selectableRow} /* send condition */
|
||||||
enablePinning={props.enablePinning} /* send condition */
|
enablePinning={props.enablePinning} /* send condition */
|
||||||
enableColumnFilters={props.enableColumnFilters} /* send condition */
|
enableColumnFilters={props.enableColumnFilters} /* send condition */
|
||||||
enableDensityToggle={props.enableDensityToggle} /* send condition */
|
enableDensityToggle={props.enableDensityToggle}
|
||||||
enableHiding={props.enableHiding} /* send condition */
|
enableHiding={props.enableHiding} /* send condition */
|
||||||
enableFullScreenToggle={props.enableFullScreenToggle} /* send condition */
|
enableFullScreenToggle={props.enableFullScreenToggle} /* send condition */
|
||||||
enableColumnResizing={props.enableColumnResizing}
|
enableColumnResizing={props.enableColumnResizing}
|
||||||
muiTableHeadCellProps={{
|
muiTableHeadCellProps={{
|
||||||
sx: {
|
sx: {
|
||||||
color: "primary.main",
|
color: "primary.main",
|
||||||
|
borderLeft: "1px solid #e1e1e1",
|
||||||
|
"&:first-of-type": {
|
||||||
|
borderLeft: "unset"
|
||||||
|
},
|
||||||
"& .Mui-TableHeadCell-Content": {justifyContent: "space-between"},
|
"& .Mui-TableHeadCell-Content": {justifyContent: "space-between"},
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
|
muiTableBodyCellProps={{
|
||||||
|
sx: {
|
||||||
|
borderLeft: "1px solid #e1e1e1",
|
||||||
|
"&:first-of-type": {
|
||||||
|
borderLeft: "unset"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}}
|
||||||
enableColumnFilterModes
|
enableColumnFilterModes
|
||||||
muiTablePaperProps={{elevation: 0}}
|
muiTablePaperProps={{elevation: 0}}
|
||||||
rowCount={rowCount}
|
rowCount={rowCount}
|
||||||
@@ -158,7 +161,7 @@ const DataTable = (props) => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
state={{
|
state={{
|
||||||
isLoading,
|
isLoading: isValidating,
|
||||||
columnFilters,
|
columnFilters,
|
||||||
columnFilterFns,
|
columnFilterFns,
|
||||||
pagination,
|
pagination,
|
||||||
@@ -166,9 +169,10 @@ const DataTable = (props) => {
|
|||||||
}}
|
}}
|
||||||
positionActionsColumn={"last"}
|
positionActionsColumn={"last"}
|
||||||
enableRowActions={props.enableRowActions}
|
enableRowActions={props.enableRowActions}
|
||||||
|
renderRowActions={({row}) => <props.TableRowAction fetchUrl={fetchUrl} mutate={mutate} row={row}/>}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default DataTable;
|
export default DataTable;
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import {DataTableProvider} from "@/lib/app/contexts/DatatableContext";
|
|
||||||
import DataTable from "./Datatable";
|
|
||||||
import {ReloadDataTableProvider} from "@/lib/app/contexts/ReloadDatatableContext";
|
|
||||||
|
|
||||||
function DataTableStructure(props) {
|
|
||||||
return (
|
|
||||||
<ReloadDataTableProvider>
|
|
||||||
<DataTableProvider>
|
|
||||||
<DataTable {...props} token={localStorage.getItem("_token")}/>
|
|
||||||
</DataTableProvider>
|
|
||||||
</ReloadDataTableProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default DataTableStructure;
|
|
||||||
@@ -2,7 +2,7 @@ import DangerousIcon from "@mui/icons-material/Dangerous";
|
|||||||
import {Box, Typography} from "@mui/material";
|
import {Box, Typography} from "@mui/material";
|
||||||
import {toast} from "react-toastify";
|
import {toast} from "react-toastify";
|
||||||
|
|
||||||
const ErrorNotification = (directionApp, status, t, message) => {
|
const ErrorNotification = (directionApp, t, status, message) => {
|
||||||
toast(
|
toast(
|
||||||
() => (
|
() => (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import BeenhereIcon from "@mui/icons-material/Beenhere";
|
|||||||
import {Box, Typography} from "@mui/material";
|
import {Box, Typography} from "@mui/material";
|
||||||
import {toast} from "react-toastify";
|
import {toast} from "react-toastify";
|
||||||
|
|
||||||
const SuccessNotification = (directionApp, status, t) => {
|
const SuccessNotification = (directionApp, t, status) => {
|
||||||
toast(
|
toast(
|
||||||
() => (
|
() => (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import ReportIcon from "@mui/icons-material/Report";
|
|||||||
import {Box, Typography} from "@mui/material";
|
import {Box, Typography} from "@mui/material";
|
||||||
import {toast} from "react-toastify";
|
import {toast} from "react-toastify";
|
||||||
|
|
||||||
const WarningNotification = (directionApp, status, t) => {
|
const WarningNotification = (directionApp, t, status) => {
|
||||||
toast(
|
toast(
|
||||||
() => (
|
() => (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,39 +1,55 @@
|
|||||||
|
import {toast} from "react-toastify";
|
||||||
import ErrorNotification from "./ErrorNotification";
|
import ErrorNotification from "./ErrorNotification";
|
||||||
import WarningNotification from "./WarningNotification";
|
import WarningNotification from "./WarningNotification";
|
||||||
import SuccessNotification from "./SuccessNotification";
|
import SuccessNotification from "./SuccessNotification";
|
||||||
|
|
||||||
const Notifications = async (directionApp, response, t) => {
|
const Notifications = async (directionApp, t, response) => {
|
||||||
const {status, data} = response;
|
const {status, data} = response != undefined ? response : ""
|
||||||
|
toast.dismiss();
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case 200:
|
case 200:
|
||||||
SuccessNotification(directionApp, status, t);
|
SuccessNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
case 400:
|
case 400:
|
||||||
ErrorNotification(directionApp, status, t);
|
ErrorNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
case 401:
|
case 401:
|
||||||
ErrorNotification(directionApp, status, t);
|
ErrorNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
case 403:
|
case 403:
|
||||||
ErrorNotification(directionApp, status, t);
|
ErrorNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
case 422:
|
case 422:
|
||||||
ErrorNotification(directionApp, status, t, data.message);
|
ErrorNotification(directionApp, t, status, data.message);
|
||||||
break;
|
break;
|
||||||
case 500:
|
case 500:
|
||||||
WarningNotification(directionApp, status, t);
|
WarningNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
case 503:
|
case 503:
|
||||||
WarningNotification(directionApp, status, t);
|
WarningNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
case 504:
|
case 504:
|
||||||
WarningNotification(directionApp, status, t);
|
WarningNotification(directionApp, t, status);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Handle other cases if needed
|
toast(t("notifications.pending"), {
|
||||||
|
position: directionApp === "ltr" ? "top-left" : "top-right",
|
||||||
|
autoClose: false,
|
||||||
|
closeOnClick: false,
|
||||||
|
draggable: false,
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Notifications;
|
export default Notifications;
|
||||||
|
|
||||||
|
/*
|
||||||
|
usage document
|
||||||
|
|
||||||
|
** for pending use ( Notifications(directionApp, t, undefined) ) this before your request.
|
||||||
|
** for success use ( Notifications(directionApp, t, response) ) this inside .then() of your request.
|
||||||
|
** for Error and Warning use ( Notifications(directionApp, t, error.response) ) this inside .catche() of your request.
|
||||||
|
|
||||||
|
end usage document
|
||||||
|
*/
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ const MuiLayout = ({children, isBot}) => {
|
|||||||
height: "8px",
|
height: "8px",
|
||||||
},
|
},
|
||||||
"*::-webkit-scrollbar-thumb": {
|
"*::-webkit-scrollbar-thumb": {
|
||||||
background: "#e1e1e1",
|
background: `${theme.palette.primary.light}80`,
|
||||||
borderRadius: "3px",
|
|
||||||
},
|
},
|
||||||
"*:not(.MuiTableContainer-root)": {
|
"*:not(.MuiTableContainer-root)": {
|
||||||
scrollbarWidth: "thin",
|
scrollbarWidth: "thin",
|
||||||
@@ -44,7 +43,7 @@ const MuiLayout = ({children, isBot}) => {
|
|||||||
},
|
},
|
||||||
|
|
||||||
"*::-moz-scrollbar-thumb": {
|
"*::-moz-scrollbar-thumb": {
|
||||||
backgroundColor: "#e1e1e1",
|
backgroundColor: `${theme.palette.primary.light}80`,
|
||||||
},
|
},
|
||||||
[`@media (max-width: ${theme.breakpoints.values.sm}px)`]: {
|
[`@media (max-width: ${theme.breakpoints.values.sm}px)`]: {
|
||||||
"*::-webkit-scrollbar": {
|
"*::-webkit-scrollbar": {
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
import {createContext} from "react";
|
|
||||||
import useDataTable from "../hooks/useDatatable";
|
|
||||||
|
|
||||||
export const DataTableContext = createContext();
|
|
||||||
|
|
||||||
export const DataTableProvider = (props) => {
|
|
||||||
const contextValue = useDataTable();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DataTableContext.Provider value={contextValue}>
|
|
||||||
{props.children}
|
|
||||||
</DataTableContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import {createContext, useState} from "react";
|
|
||||||
|
|
||||||
export const ReloadDataTableContext = createContext();
|
|
||||||
|
|
||||||
export const ReloadDataTableProvider = ({children}) => {
|
|
||||||
const [reloadDataTable, setReloadDataTable] = useState(false);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ReloadDataTableContext.Provider
|
|
||||||
value={{reloadDataTable, setReloadDataTable}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</ReloadDataTableContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import {useCallback, useContext, useReducer, useState} from "react";
|
|
||||||
import {ReloadDataTableContext} from "../contexts/ReloadDatatableContext";
|
|
||||||
import useUser from "./useUser";
|
|
||||||
import Notifications from "@/core/components/notifications";
|
|
||||||
import useDirection from "./useDirection";
|
|
||||||
import {useTranslations} from "next-intl";
|
|
||||||
|
|
||||||
const initialValues = {
|
|
||||||
url: "",
|
|
||||||
rowID: "",
|
|
||||||
values: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
|
||||||
switch (action.type) {
|
|
||||||
case "CONFIRM_DATA":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
url: action.url,
|
|
||||||
rowID: action.rowID,
|
|
||||||
};
|
|
||||||
case "REJECT_DATA":
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
url: action.url,
|
|
||||||
rowID: action.rowID,
|
|
||||||
values: {},
|
|
||||||
};
|
|
||||||
default:
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const useDataTable = () => {
|
|
||||||
const {setReloadDataTable} = useContext(ReloadDataTableContext);
|
|
||||||
const [state, dispatch] = useReducer(reducer, initialValues);
|
|
||||||
const [openConfirmDialog, setOpenConfirmDialog] = useState(false);
|
|
||||||
const [openRejectDialog, setOpenRejectDialog] = useState(false);
|
|
||||||
const [rowId, setRowId] = useState(null);
|
|
||||||
const {directionApp} = useDirection();
|
|
||||||
const t = useTranslations();
|
|
||||||
|
|
||||||
const {token} = useUser();
|
|
||||||
|
|
||||||
const confirmData = useCallback(async (url, rowID, values) => {
|
|
||||||
dispatch({type: "CONFIRM_DATA", url: url, rowID: rowID, values: values});
|
|
||||||
axios
|
|
||||||
.post(`${url}/${rowID}`, values, {
|
|
||||||
headers: {authorization: `Bearer ${token}`},
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
setReloadDataTable(true);
|
|
||||||
Notifications(directionApp, response, t);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
Notifications(directionApp, error.response, t);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const rejectData = useCallback(async (url, rowID, values) => {
|
|
||||||
dispatch({type: "REJECT_DATA", url: url, rowID: rowID, values: values});
|
|
||||||
axios
|
|
||||||
.post(`${url}/${rowID}`, values, {
|
|
||||||
headers: {authorization: `Bearer ${token}`},
|
|
||||||
})
|
|
||||||
.then((response) => {
|
|
||||||
setReloadDataTable(true);
|
|
||||||
Notifications(directionApp, response, t);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log(error);
|
|
||||||
Notifications(directionApp, error.response, t);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
//Confirm Data
|
|
||||||
const handleOpenConfirmDialog = (row) => {
|
|
||||||
setRowId(row.getValue("id"));
|
|
||||||
setOpenConfirmDialog(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCloseConfirmDialog = () => {
|
|
||||||
setOpenConfirmDialog(false);
|
|
||||||
};
|
|
||||||
//End Confirm Data
|
|
||||||
|
|
||||||
// Reject Data
|
|
||||||
const handleOpenRejectDialog = (row) => {
|
|
||||||
setRowId(row.getValue("id"));
|
|
||||||
setOpenRejectDialog(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCloseRejectDialog = () => {
|
|
||||||
setOpenRejectDialog(false);
|
|
||||||
};
|
|
||||||
// End Reject Data
|
|
||||||
|
|
||||||
const contextValue = {
|
|
||||||
handleOpenConfirmDialog,
|
|
||||||
handleCloseConfirmDialog,
|
|
||||||
handleOpenRejectDialog,
|
|
||||||
handleCloseRejectDialog,
|
|
||||||
rowId,
|
|
||||||
openConfirmDialog,
|
|
||||||
openRejectDialog,
|
|
||||||
rejectData,
|
|
||||||
confirmData,
|
|
||||||
};
|
|
||||||
return contextValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useDataTable;
|
|
||||||
Reference in New Issue
Block a user