Merge branch 'feature/province_manager' into 'develop'

Feature/province manager

See merge request witel3/loan-facilities-expert!40
This commit is contained in:
yasaman aliakbari
2023-07-19 10:04:53 +00:00
15 changed files with 556 additions and 25 deletions

View File

@@ -23,7 +23,7 @@
"machinary-office": "ماشین آلات",
"passenger-boss": "رئیس مسافر (کارگروه استانی)",
"transportation-assistance": "معاونت حمل و نقل",
"manager": "مدیر کل",
"province-manager": "مدیر کل استانی",
"change-password": "تغییر رمز عبور",
"edit-profile": "ویرایش پروفایل"
},
@@ -47,8 +47,9 @@
},
"Dashboard": {
"dashboard_page": "داشبورد",
"passenger_boss": "رئیس مسافر",
"passenger_boss_page": "رئیس مسافر",
"change_password": "تغییر رمز عبور",
"province_manager_page": "مدیر کل استانی",
"passenger_office_page": "اداره مسافر",
"machinary_office_page": "ماشین آلات",
"edit_profile": "ویرایش پروفایل"
@@ -103,6 +104,17 @@
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست"
},
"ProvinceManager": {
"name": "نام",
"id": "کد یکتا",
"national_id": "کد ملی",
"phone_number": "موبایل",
"created_at": "تاریخ درخواست",
"updated_at": "تاریخ بروزرسانی",
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست"
},
"PassengerBoss": {
"name": "نام",
"id": "کد یکتا",

View File

@@ -24,6 +24,7 @@ function DashboardMachinaryOfficeComponent() {
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",
@@ -94,13 +95,10 @@ function DashboardMachinaryOfficeComponent() {
enableColumnFilter: true,
datatype: "date",
filterFn: "lessThan",
minSize: 200,
columnFilterModeOptions: ["lessThan", "greaterThan"],
Cell: ({ renderedCellValue }) => {
return (
<Typography variant="body2" style={{ minWidth: "200px" }}>
{renderedCellValue}
</Typography>
);
return <Typography variant="body2">{renderedCellValue}</Typography>;
},
Header: ({ column }) => <em>{column.columnDef.header}</em>,
Filter: ({ column }) => {
@@ -147,6 +145,7 @@ function DashboardMachinaryOfficeComponent() {
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",

View File

@@ -26,6 +26,7 @@ function DashboardPassengerOfficeComponent() {
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",
@@ -96,13 +97,10 @@ function DashboardPassengerOfficeComponent() {
enableColumnFilter: true,
datatype: "date",
filterFn: "lessThan",
minSize: 200,
columnFilterModeOptions: ["lessThan", "greaterThan"],
Cell: ({ renderedCellValue }) => {
return (
<Typography variant="body2" style={{ minWidth: "200px" }}>
{renderedCellValue}
</Typography>
);
return <Typography variant="body2">{renderedCellValue}</Typography>;
},
Header: ({ column }) => <em>{column.columnDef.header}</em>,
Filter: ({ column }) => {
@@ -149,6 +147,7 @@ function DashboardPassengerOfficeComponent() {
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",

View File

@@ -25,6 +25,7 @@ function DashboardPassengerOfficeComponent() {
header: t("PassengerOffice.id"),
enableColumnFilter: true,
datatype: "numeric",
maxSize: 100,
filterFn: "equals",
columnFilterModeOptions: [
"equals",
@@ -96,13 +97,10 @@ function DashboardPassengerOfficeComponent() {
enableColumnFilter: true,
datatype: "date",
filterFn: "lessThan",
minSize: 200,
columnFilterModeOptions: ["lessThan", "greaterThan"],
Cell: ({ renderedCellValue }) => {
return (
<Typography variant="body2" style={{ minWidth: "200px" }}>
{renderedCellValue}
</Typography>
);
return <Typography variant="body2">{renderedCellValue}</Typography>;
},
Header: ({ column }) => <em>{column.columnDef.header}</em>,
Filter: ({ column }) => {
@@ -148,6 +146,7 @@ function DashboardPassengerOfficeComponent() {
header: t("PassengerOffice.navgan_id"),
enableColumnFilter: true,
datatype: "numeric",
maxSize: 100,
filterFn: "equals",
columnFilterModeOptions: [
"equals",

View File

@@ -0,0 +1,128 @@
import { CONFIRM_PROVINCE_MANAGER } from "@/core/data/apiRoutes";
import {
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
Button,
TextField,
FormHelperText,
} from "@mui/material";
import { useFormik } from "formik";
import { useTranslations } from "next-intl";
import { useRef, useState } from "react";
const MAX_FILE_SIZE_IN_BYTES = 2 * 1024 * 1024;
const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => {
const t = useTranslations();
const [description, setDescription] = useState("");
const [fileData, setFileData] = useState(null);
const inputRef = useRef(null);
const formik = useFormik({
initialValues: {
description: "",
fileData: null,
},
onSubmit: () => {
const formData = new FormData();
if (description !== "")
formData.append("expert_description", description);
if (fileData !== null) formData.append("file", fileData);
handleClose();
confirmData(CONFIRM_PROVINCE_MANAGER, rowId, formData);
},
});
const handleUploadClick = () => {
// 👇 We redirect the click event onto the hidden input element
inputRef.current?.click();
};
const handleDescriptionChange = (event) => {
setDescription(event.target.value);
formik.handleChange(event);
};
const handleFileChange = (e) => {
const selectedFile = e.target.files[0];
if (selectedFile) {
const fileSizeInBytes = selectedFile.size;
if (fileSizeInBytes > MAX_FILE_SIZE_IN_BYTES) {
formik.setFieldError(
"fileData",
`File size exceeds the limit (${MAX_FILE_SIZE_IN_BYTES / 1000000} MB)`
);
e.target.value = null;
} else {
setFileData(selectedFile);
formik.setFieldValue("fileData", selectedFile);
formik.setFieldError("fileData", "");
}
}
};
return (
<Dialog open={open} onClose={handleClose}>
<DialogTitle>{t("ConfirmDialog.confirm")}</DialogTitle>
<DialogContent>
<DialogContentText>{t("ConfirmDialog.context")}</DialogContentText>
<TextField
name="description"
multiline
rows={8}
placeholder={t("ConfirmDialog.description")}
value={description}
onChange={handleDescriptionChange}
onBlur={formik.handleBlur("description")}
fullWidth
variant="outlined"
sx={{ mt: 1 }}
/>
<div>
<label htmlFor="fileData">
<Button
variant="outlined"
color="primary"
onClick={handleUploadClick}
component="span"
sx={{ mt: 1, width: "100%" }}
>
{fileData ? (
<>
Name : {fileData.name}
<br />
Size : {fileData.size}
</>
) : (
<>{t("ConfirmDialog.choose_file")}</>
)}
</Button>
</label>
<input
id="fileData"
name="fileData"
type="file"
accept=".pdf, image/*"
ref={inputRef}
onChange={handleFileChange}
style={{ display: "none" }}
/>
</div>
<FormHelperText error={Boolean(formik.errors.fileData)}>
{formik.errors.fileData && formik.errors.fileData}
</FormHelperText>
</DialogContent>
<DialogActions>
<Button onClick={formik.handleSubmit} color="primary">
{t("ConfirmDialog.button-confirm")}
</Button>
<Button onClick={handleClose} color="secondary" autoFocus>
{t("ConfirmDialog.button-cancel")}
</Button>
</DialogActions>
</Dialog>
);
};
export default ConfirmForm;

View File

@@ -0,0 +1,76 @@
import { REJECT_PROVINCE_MANAGER } from "@/core/data/apiRoutes";
import {
Dialog,
DialogTitle,
DialogContent,
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, rowId, rejectData }) => {
const t = useTranslations();
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_PROVINCE_MANAGER, rowId, formData);
},
});
const handleDescriptionChange = (event) => {
setDescription(event.target.value);
formik.handleChange(event);
};
return (
<Dialog open={open} onClose={handleClose}>
<DialogTitle>{t("RejectDialog.reject")}</DialogTitle>
<DialogContent>
<DialogContentText>{t("RejectDialog.context")}</DialogContentText>
<TextField
name="description"
multiline
rows={8}
placeholder={t("RejectDialog.description")}
value={description}
onChange={handleDescriptionChange}
onBlur={formik.handleBlur("description")}
error={
formik.touched.description && Boolean(formik.errors.description)
}
helperText={formik.touched.description && formik.errors.description}
fullWidth
variant="outlined"
sx={{ mt: 1 }}
/>
</DialogContent>
<DialogActions>
<Button onClick={formik.handleSubmit} color="primary">
{t("RejectDialog.button-reject")}
</Button>
<Button onClick={handleClose} color="secondary" autoFocus>
{t("RejectDialog.button-cancel")}
</Button>
</DialogActions>
</Dialog>
);
};
export default RejectForm;

View File

@@ -0,0 +1,54 @@
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
import ThumbDownIcon from "@mui/icons-material/ThumbDown";
import { Box, IconButton } from "@mui/material";
import { useContext } from "react";
import { DataTableContext } from "@/lib/app/contexts/DataTableContext";
import ConfirmForm from "./Form/ConfirmForm";
import RejectForm from "./Form/RejectForm";
const TableRowActions = ({ row }) => {
const {
openConfirmDialog,
openRejectDialog,
handleOpenConfirmDialog,
handleOpenRejectDialog,
handleCloseConfirmDialog,
handleCloseRejectDialog,
rowId,
confirmData,
rejectData,
} = useContext(DataTableContext);
return (
<Box sx={{ display: "flex", flexWrap: "nowrap", gap: "8px" }}>
<IconButton
color="primary"
onClick={() => {
handleOpenConfirmDialog(row);
}}
>
<ThumbUpAltIcon />
</IconButton>
{openConfirmDialog && (
<ConfirmForm
rowId={rowId}
open={openConfirmDialog}
handleClose={handleCloseConfirmDialog}
confirmData={confirmData}
/>
)}
<IconButton color="primary" onClick={() => handleOpenRejectDialog(row)}>
<ThumbDownIcon />
</IconButton>
{openRejectDialog && (
<RejectForm
rowId={rowId}
open={openRejectDialog}
handleClose={handleCloseRejectDialog}
rejectData={rejectData}
/>
)}
</Box>
);
};
export default TableRowActions;

View File

@@ -0,0 +1,13 @@
import { Stack, Tooltip } from "@mui/material";
import { useTranslations } from "next-intl";
function TableToolbar() {
const t = useTranslations();
return (
<Stack direction={"row"} spacing={2}>
<Tooltip title={t("add")} arrow placement="right"></Tooltip>
</Stack>
);
}
export default TableToolbar;

View File

@@ -0,0 +1,217 @@
import DataTableStructure from "@/core/components/DatatableStructure";
import DashboardLayouts from "@/layouts/dashboardLayouts";
import { Box, Typography } from "@mui/material";
import { useMemo } from "react";
// import TableToolbar from "./TableTollbar";
import { GET_PROVINCE_MANAGER } from "@/core/data/apiRoutes";
import { useTranslations } from "next-intl";
import TableRowActions from "./TableRowActions";
import { format } from "date-fns-jalali";
import {
LocalizationProvider,
MobileDateTimePicker,
} from "@mui/x-date-pickers";
import { AdapterDateFnsJalali } from "@mui/x-date-pickers/AdapterDateFnsJalali";
import moment from "moment";
function DashboardProvinceManagerComponent() {
const t = useTranslations();
const columns = useMemo(
() => [
{
accessorFn: (row) => row.id,
id: "id",
header: t("ProvinceManager.id"),
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",
"contains",
"lessThan",
"greaterThan",
"between",
],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.name,
id: "name",
header: t("ProvinceManager.name"),
enableColumnFilter: true,
datatype: "text",
filterFn: "contains",
columnFilterModeOptions: ["contains", "equals", "notEquals"],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.national_id,
id: "national_id",
header: t("ProvinceManager.national_id"),
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
columnFilterModeOptions: [
"equals",
"notEquals",
"contains",
"lessThan",
"greaterThan",
"between",
],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.phone_number,
id: "phone_number",
header: t("ProvinceManager.phone_number"),
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
columnFilterModeOptions: [
"equals",
"notEquals",
"contains",
"lessThan",
"greaterThan",
"between",
],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) =>
format(new Date(row.created_at), "HH:mm | yyyy/mm/dd"),
id: "created_at",
header: t("ProvinceManager.created_at"),
enableColumnFilter: true,
datatype: "date",
filterFn: "lessThan",
minSize: 200,
columnFilterModeOptions: ["lessThan", "greaterThan"],
Cell: ({ renderedCellValue }) => {
return <Typography variant="body2">{renderedCellValue}</Typography>;
},
Header: ({ column }) => <em>{column.columnDef.header}</em>,
Filter: ({ column }) => {
return (
<LocalizationProvider dateAdapter={AdapterDateFnsJalali}>
<MobileDateTimePicker
onChange={(newValue) => {
const date = new Date(newValue);
const formattedDate = moment(date)
.locale("en")
.format("YYYY-MM-DD HH:mm");
column.setFilterValue(formattedDate);
}}
slotProps={{
textField: {
helperText: `Filter Mode: ${column.columnDef._filterFn}`,
sx: { minWidth: "120px" },
variant: "standard",
},
}}
value={moment(column.getFilterValue())
.locale("fa")
.format("yyyy/mm/dd HH:mm")}
/>
</LocalizationProvider>
);
},
},
{
accessorFn: (row) =>
format(new Date(row.updated_at), "HH:mm | yyyy/mm/dd"),
id: "updated_at",
header: t("ProvinceManager.updated_at"),
enableColumnFilter: false,
datatype: "numeric",
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.navgan_id,
id: "navgan_id",
header: t("ProvinceManager.navgan_id"),
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",
"contains",
"lessThan",
"greaterThan",
"between",
],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.vehicle_type,
id: "vehicle_type",
header: t("ProvinceManager.vehicle_type"),
enableColumnFilter: true,
datatype: "text",
filterFn: "contains",
columnFilterModeOptions: ["contains", "equals", "notEquals"],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.state_name,
id: "state_id",
header: t("ProvinceManager.state_name"),
enableColumnFilter: false,
datatype: "numeric",
// filterFn: "equals",
// filterSelectOptions: [
// ],
// filterVariant: "select",
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
],
[]
);
return (
<DashboardLayouts>
<Box sx={{ px: 3 }}>
<DataTableStructure
tableUrl={GET_PROVINCE_MANAGER}
columns={columns}
selectableRow={false}
enableCustomToolbar={true}
// CustomToolbar={<TableToolbar />}
enableLastUpdate={true}
enablePinning={true}
enableDensityToggle={true}
enableColumnFilters={true}
enableHiding={true}
enableFullScreenToggle={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
enableRowActions={true}
renderRowActions={({ row }) => <TableRowActions row={row} />}
/>
</Box>
</DashboardLayouts>
);
}
export default DashboardProvinceManagerComponent;

View File

@@ -24,6 +24,7 @@ function DashboardTransportationAssistanceComponent() {
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",
@@ -94,12 +95,11 @@ function DashboardTransportationAssistanceComponent() {
header: t("TransportationAssistance.created_at"),
enableColumnFilter: true,
datatype: "date",
minSize: 200,
filterFn: "lessThan",
columnFilterModeOptions: ["lessThan", "greaterThan"],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2" style={{ minWidth: "200px" }}>
{renderedCellValue}
</Typography>
<Typography variant="body2">{renderedCellValue}</Typography>
),
Header: ({ column }) => <em>{column.columnDef.header}</em>,
Filter: ({ column }) => {
@@ -146,6 +146,7 @@ function DashboardTransportationAssistanceComponent() {
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
maxSize: 100,
columnFilterModeOptions: [
"equals",
"notEquals",

View File

@@ -44,7 +44,6 @@ const DataTable = (props) => {
const [sorting, setSorting] = useState([]);
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
const [rowCount, setRowCount] = useState(0);
console.log(moment());
const [updateTime, setupdateTime] = useState(
moment().format("HH:mm | jYYYY/jM/jD")
);

View File

@@ -55,3 +55,14 @@ export const CONFIRM_MACHINARY_OFFICE =
export const REJECT_MACHINARY_OFFICE =
BASE_URL + "/dashboard/machinery_expert/reject";
//passenger office
//province manager
export const GET_PROVINCE_MANAGER =
BASE_URL + "/dashboard/province_manager/show";
export const CONFIRM_PROVINCE_MANAGER =
BASE_URL + "/dashboard/province_manager/confirm";
export const REJECT_PROVINCE_MANAGER =
BASE_URL + "/dashboard/province_manager/reject";
//province manager

View File

@@ -47,12 +47,12 @@ const sidebarMenu = [
role: "transportation-assistance",
},
{
key: "sidebar.manager",
key: "sidebar.province-manager",
type: "page",
route: "/dashboard/manager",
route: "/dashboard/province-manager",
icon: <DesktopWindowsIcon />,
selected: false,
role: "manager",
role: "province-manager",
},
],
];

View File

@@ -6,7 +6,7 @@ import { parse } from "next-useragent";
export default function PassengerBoss() {
return (
<WithAuthMiddleware>
<TitlePage text="Dashboard.passenger_boss" />
<TitlePage text="Dashboard.passenger_boss_page" />
<DashboardPassengerBossComponent />
</WithAuthMiddleware>
);

View File

@@ -0,0 +1,23 @@
import DashboardProvinceManagerComponent from "@/components/dashboard/province-manager";
import TitlePage from "@/core/components/TitlePage";
import WithAuthMiddleware from "@/middlewares/WithAuth";
import { parse } from "next-useragent";
export default function PassengerOffice() {
return (
<WithAuthMiddleware>
<TitlePage text="Dashboard.province_manager_page" />
<DashboardProvinceManagerComponent />
</WithAuthMiddleware>
);
}
export async function getServerSideProps({ req, locale }) {
const { isBot } = parse(req.headers["user-agent"]);
return {
props: {
messages: (await import(`&/locales/${locale}/app.json`)).default,
isBot,
},
};
}