Merge branch 'feature/passenger_boss_design' into 'develop'

Feature/passenger boss design

See merge request witel3/loan-facilities-expert!39
This commit is contained in:
yasaman aliakbari
2023-07-18 13:14:16 +00:00
9 changed files with 521 additions and 8 deletions

View File

@@ -19,9 +19,9 @@
},
"sidebar": {
"dashboard": "داشبورد",
"passenger-office": "اداره مسافر",
"passenger-office": "اداره مسافر (توزیع درخواست)",
"machinary-office": "ماشین آلات",
"passenger-boss": "رئیس مسافر",
"passenger-boss": "رئیس مسافر (کارگروه استانی)",
"transportation-assistance": "معاونت حمل و نقل",
"manager": "مدیر کل",
"change-password": "تغییر رمز عبور",
@@ -47,9 +47,10 @@
},
"Dashboard": {
"dashboard_page": "داشبورد",
"passenger_boss": "رئیس مسافر",
"change_password": "تغییر رمز عبور",
"passenger_office_page": "اداره مسافر",
"machinary_office_page": "ماشین آلات",
"change_password": "تغییر رمز عبور",
"edit_profile": "ویرایش پروفایل"
},
"MuiDatePicker": {
@@ -102,6 +103,17 @@
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست"
},
"PassengerBoss": {
"name": "نام",
"id": "کد یکتا",
"national_id": "کد ملی",
"phone_number": "موبایل",
"created_at": "تاریخ درخواست",
"updated_at": "تاریخ بروزرسانی",
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست"
},
"TransportationAssistance": {
"name": "نام",
"id": "کد یکتا",
@@ -122,8 +134,7 @@
"updated_at": "تاریخ بروزرسانی",
"navgan_id": "کد ناوگان",
"vehicle_type": "نوع ماشین",
"state_name": "وضعیت درخواست",
"proposed_amount": "مقدار پیشنهادی"
"state_name": "وضعیت درخواست"
},
"ConfirmDialog": {
"confirm": "تایید",
@@ -133,7 +144,10 @@
"amount_error": "وارد کردن مقدار پیشنهادی الزامیست",
"description_error": "وارد کردن توضیحات الزامی است!",
"description": "توضیحات",
"choose_file": "انتخاب فایل"
"choose_file": "انتخاب فایل",
"approved_amount": "مبلغ تصویب شده",
"approved_amount_error": "وارد کردن مبلغ تصویب شده الزامیست",
"proposed_amount": "مقدار پیشنهادی"
},
"RejectDialog": {
"reject": "عدم تایید",

View File

@@ -56,7 +56,7 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => {
name="description"
multiline
rows={8}
placeholder={t("RejectDialog.description")}
placeholder={t("ConfirmDialog.description")}
value={description}
onChange={handleDescriptionChange}
fullWidth
@@ -65,7 +65,7 @@ const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => {
/>
<TextField
name="proposed_amount"
label={t("MachinaryOffice.proposed_amount")}
label={t("ConfirmDialog.proposed_amount")}
type="number"
inputProps={{
min: 0,

View File

@@ -0,0 +1,103 @@
import { CONFIRM_PASSENGER_BOSS } from "@/core/data/apiRoutes";
import {
Dialog,
DialogTitle,
DialogContent,
DialogContentText,
DialogActions,
Button,
TextField,
} from "@mui/material";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { useFormik } from "formik";
import * as Yup from "yup";
const ConfirmForm = ({ open, handleClose, rowId, confirmData }) => {
const t = useTranslations();
const [proposedAmount, setProposedAmount] = useState("");
const [description, setDescription] = useState("");
//formik
const validationSchema = Yup.object().shape({
proposed_amount: Yup.string().required(
t("ConfirmDialog.approved_amount_error")
),
});
const formik = useFormik({
initialValues: {
proposed_amount: "",
description: "",
},
validationSchema,
onSubmit: () => {
const formData = new FormData();
formData.append("approved_amount", proposedAmount);
if (description != "") formData.append("expert_description", description);
handleClose();
confirmData(CONFIRM_PASSENGER_BOSS, rowId, formData);
},
});
const handleDescriptionChange = (event) => {
setDescription(event.target.value);
};
const handleAmountChange = (event) => {
if (/^\d*$/.test(event.target.value)) {
setProposedAmount(event.target.value);
}
formik.handleChange(event);
};
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}
fullWidth
variant="outlined"
sx={{ mt: 1 }}
/>
<TextField
name="proposed_amount"
label={t("ConfirmDialog.approved_amount")}
type="number"
inputProps={{
min: 0,
inputMode: "numeric",
pattern: "[0-9]*",
}}
variant="outlined"
value={proposedAmount}
onChange={handleAmountChange}
onBlur={formik.handleBlur("proposed_amount")}
error={
formik.touched.proposed_amount &&
Boolean(formik.errors.proposed_amount)
}
helperText={
formik.touched.proposed_amount && formik.errors.proposed_amount
}
sx={{ mt: 1 }}
fullWidth
/>
</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_PASSENGER_BOSS } 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_PASSENGER_BOSS, 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,218 @@
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_PASSENGER_BOSS } 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 DashboardPassengerOfficeComponent() {
const t = useTranslations();
const columns = useMemo(
() => [
{
accessorFn: (row) => row.id,
id: "id",
header: t("PassengerBoss.id"),
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
columnFilterModeOptions: [
"equals",
"notEquals",
"contains",
"lessThan",
"greaterThan",
"between",
],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.name,
id: "name",
header: t("PassengerBoss.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("PassengerBoss.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("PassengerBoss.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("PassengerBoss.created_at"),
enableColumnFilter: true,
datatype: "date",
filterFn: "lessThan",
columnFilterModeOptions: ["lessThan", "greaterThan"],
Cell: ({ renderedCellValue }) => {
return (
<Typography variant="body2" style={{ minWidth: "200px" }}>
{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("PassengerBoss.updated_at"),
enableColumnFilter: false,
datatype: "numeric",
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.navgan_id,
id: "navgan_id",
header: t("PassengerBoss.navgan_id"),
enableColumnFilter: true,
datatype: "numeric",
filterFn: "equals",
columnFilterModeOptions: [
"equals",
"notEquals",
"contains",
"lessThan",
"greaterThan",
"between",
],
Cell: ({ renderedCellValue }) => (
<Typography variant="body2">{renderedCellValue}</Typography>
),
},
{
accessorFn: (row) => row.vehicle_type,
id: "vehicle_type",
header: t("PassengerBoss.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("PassengerBoss.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_PASSENGER_BOSS}
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 DashboardPassengerOfficeComponent;

View File

@@ -23,6 +23,17 @@ export const REJECT_PASSENGER_OFFICE =
BASE_URL + "/dashboard/passenger_office_chief/reject";
//passenger office
//passenger boss
export const GET_PASSENGER_BOSS =
BASE_URL + "/dashboard/province_working_group/show";
export const CONFIRM_PASSENGER_BOSS =
BASE_URL + "/dashboard/province_working_group/confirm";
export const REJECT_PASSENGER_BOSS =
BASE_URL + "/dashboard/province_working_group/reject";
//passenger boss
//transportation assistance
export const GET_TRANSPORTATION_ASSISTANCE =
BASE_URL + "/dashboard/transportation_assistant/show";
@@ -33,6 +44,7 @@ export const CONFIRM_TRANSPORTATION_ASSISTANCE =
export const REJECT_TRANSPORTATION_ASSISTANCE =
BASE_URL + "/dashboard/transportation_assistant/reject";
//transportation assistance
//machinary office
export const GET_MACHINARY_OFFICE =
BASE_URL + "/dashboard/machinery_expert/show";

View File

@@ -0,0 +1,23 @@
import DashboardPassengerBossComponent from "@/components/dashboard/passenger-boss";
import TitlePage from "@/core/components/TitlePage";
import WithAuthMiddleware from "@/middlewares/WithAuth";
import { parse } from "next-useragent";
export default function PassengerBoss() {
return (
<WithAuthMiddleware>
<TitlePage text="Dashboard.passenger_boss" />
<DashboardPassengerBossComponent />
</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,
},
};
}