diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 41f327b..9160674 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -35,6 +35,7 @@ "transportation-assistant": "معاونت حمل و نقل", "navgan-province-manager": "مدیر کل استانی", "refahi-province-manager": "مدیر کل استانی", + "refahi-loan-management": "مدیریت وام", "commercial-chief": "رئیس اداره بازرگانی", "inspector-expert": "بازدید کارشناس", "province-head-expert": "کارشناس ستادی", @@ -46,6 +47,7 @@ "passenger-office": "توزیع درخواست", "passenger-boss": "کارگروه استانی", "refahi-province-manager": "رفاهی", + "refahi-loan-management": "رفاهی", "navgan-province-manager": "ناوگان" }, "Authorization": { @@ -86,6 +88,7 @@ "province_manager_page": "مدیر کل استانی", "province_head_expert": "کارشناس ستادی", "passenger_office_page": "اداره مسافر", + "loan_management_page": "مدیریت وام", "machinary_office_page": "ماشین آلات", "development_assistant_page": "معاون توسعه", "inspector_expert_page": "بازدید کارشناس", @@ -186,7 +189,7 @@ "vehicle_type": "نوع ماشین", "state_name": "وضعیت درخواست" }, - "DevelopmentAssistant": { + "RefahiLoanManagement": { "name": "نام", "id": "کد یکتا", "national_id": "کد ملی", @@ -288,6 +291,16 @@ "optional": " (اختیاری)", "description_error": "وارد کردن توضیحات الزامی است!" }, + "UpdateDialog": { + "update": "تغییر وضعیت درخواست", + "update-tooltip": "بروزرسانی", + "button-cancel": "بستن", + "button-update": "بروزرسانی", + "description": "توضیحات خود را وارد نمائید", + "description_error": "وارد کردن توضیحات الزامی است!", + "next-state-id": "وضعیت بعدی", + "next-state-id-error": "وارد کردن وضعیت بعدی الزامی است!" + }, "UploadSystem": { "upload_file": "فایل خود را بارگذاری کنید", "optional": " (اختیاری)", diff --git a/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx b/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx new file mode 100644 index 0000000..1d2dd72 --- /dev/null +++ b/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx @@ -0,0 +1,150 @@ +import {useTranslations} from "next-intl"; +import {useContext, useState} from "react"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + FormControl, + FormHelperText, + IconButton, + InputLabel, + MenuItem, + Select, + Stack, + TextField, + Tooltip +} from "@mui/material"; +import {useFormik} from "formik"; +import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; +import {UPDATE_LOAN_MANAGEMENT_REFAHI} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useNotification from "@/lib/app/hooks/useNotification"; +import * as Yup from "yup"; +import {LoanStateRefahiContext} from "@/lib/prefetchDataTable/hooks/LoanStateRefahi"; + + +const Update = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const detail = useContext(LoanStateRefahiContext); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + + const validationSchema = Yup.object().shape({ + description: Yup.string().required(t("UpdateDialog.description_error")), + next_state_id: Yup.number().required(t("UpdateDialog.next-state-id-error")) + }); + + const formik = useFormik({ + initialValues: { + description: "", + next_state_id: "" + }, + validationSchema, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("description", values.description); + formData.append("next_state_id", values.next_state_id); + + requestServer(`${UPDATE_LOAN_MANAGEMENT_REFAHI}/${rowId}`, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + const handleDescriptionChange = (event) => { + formik.setFieldValue("description", event.target.value) + }; + const handleNextStateIDChange = (event) => { + formik.setFieldValue("next_state_id", event.target.value) + }; + + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("UpdateDialog.update")} + + + + + + + + {t("UpdateDialog.next-state-id")} + + + {formik.touched.next_state_id && formik.errors.next_state_id} + + + + + + + + + + + + ); +}; +export default Update; \ No newline at end of file diff --git a/src/components/dashboard/refahi-loan-management/TableRowActions.jsx b/src/components/dashboard/refahi-loan-management/TableRowActions.jsx new file mode 100644 index 0000000..fd599f9 --- /dev/null +++ b/src/components/dashboard/refahi-loan-management/TableRowActions.jsx @@ -0,0 +1,17 @@ +import {Box} from "@mui/material"; +import Update from "./Form/UpdateForm" + +const TableRowActions = ({row, mutate, fetchUrl}) => { + + return ( + + + + ); +}; + +export default TableRowActions; diff --git a/src/components/dashboard/refahi-loan-management/index.jsx b/src/components/dashboard/refahi-loan-management/index.jsx new file mode 100644 index 0000000..8a571cc --- /dev/null +++ b/src/components/dashboard/refahi-loan-management/index.jsx @@ -0,0 +1,157 @@ +import DashboardLayouts from "@/layouts/dashboardLayouts"; +import {Box, Typography} from "@mui/material"; +import {useMemo} from "react"; +import {GET_LOAN_MANAGEMENT_REFAHI} from "@/core/data/apiRoutes"; +import {useTranslations} from "next-intl"; +import TableRowActions from "./TableRowActions"; +import DataTable from "@/core/components/DataTable"; +import moment from "jalali-moment"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import {LoanStateRefahiProvider} from "@/lib/prefetchDataTable/hooks/LoanStateRefahi"; + +function DashboardRefahiLoanManagementComponent() { + const t = useTranslations(); + + const columns = useMemo( + () => [ + { + accessorFn: (row) => row.id, + id: "id", + header: t("RefahiLoanManagement.id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.name, + id: "name", + header: t("RefahiLoanManagement.name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.national_id, + id: "national_id", + header: t("RefahiLoanManagement.national_id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.phone_number, + id: "phone_number", + header: t("RefahiLoanManagement.phone_number"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => + moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "created_at", + header: t("RefahiLoanManagement.created_at"), + enableColumnFilter: true, + datatype: "date", + filterFn: "lessThan", + columnFilterModeOptions: ["lessThan", "greaterThan"], + Cell: ({renderedCellValue}) => { + return {renderedCellValue}; + }, + Header: ({column}) => <>{column.columnDef.header}, + Filter: ({column}) => { + return ( + + ); + }, + }, + { + accessorFn: (row) => + moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "updated_at", + header: t("RefahiLoanManagement.updated_at"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.state_name, + id: "state_id", + header: t("RefahiLoanManagement.state_name"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + ], + [] + ); + return ( + + + + } + enableLastUpdate={true} + enablePinning={true} + enableDensityToggle={false} + initialState={{density: 'compact'}} //compact (small) //comfortable (medium) //spacious (large) + enableColumnFilters={true} + enableHiding={true} + enableFullScreenToggle={false} + enableGlobalFilter={false} + enableColumnResizing={false} // if you want true this you should change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions + enableRowActions={true} + TableRowAction={TableRowActions} + /> + + + + ); +} + +export default DashboardRefahiLoanManagementComponent; diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index e430c68..e08e29e 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -133,3 +133,11 @@ export const GET_SIDEBAR_NOTIFICATION = BASE_URL + "/dashboard/notification" //sidebar notification +//loan management refahi +export const GET_LOAN_MANAGEMENT_REFAHI = + BASE_URL + "/dashboard/refahi_loans" +export const UPDATE_LOAN_MANAGEMENT_REFAHI = + BASE_URL + "/dashboard/refahi_loans/update" +export const GET_LOAN_STATE_REFAHI = + BASE_URL + "/dashboard/loan_states/refahi" +//loan management refahi diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index c2dc246..7e31aaf 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -9,6 +9,7 @@ import BusinessCenterIcon from '@mui/icons-material/BusinessCenter'; import GradingIcon from '@mui/icons-material/Grading'; import SupervisedUserCircleIcon from '@mui/icons-material/SupervisedUserCircle'; import Diversity3Icon from '@mui/icons-material/Diversity3'; +import PaidIcon from '@mui/icons-material/Paid'; const sidebarMenu = [ [ @@ -115,6 +116,16 @@ const sidebarMenu = [ selected: false, permission: "manage_province_affairs_refahi", }, + { + key: "sidebar.refahi-loan-management", + secondary: "secondary.refahi-loan-management", + name: "refahi_loan_management", + type: "page", + route: "/dashboard/refahi-loan-management", + icon: , + selected: false, + permission: "manage_refahi_loan", + }, ], ]; diff --git a/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx b/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx new file mode 100644 index 0000000..7df1a74 --- /dev/null +++ b/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx @@ -0,0 +1,25 @@ +import {createContext, useEffect, useState} from "react"; +import {GET_LOAN_STATE_REFAHI} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; + +export const LoanStateRefahiContext = createContext(); +export const LoanStateRefahiProvider = ({children}) => { + const [detail, setDetail] = useState([]) + const requestServer = useRequest({auth: true, notification: false}) + + useEffect(() => { + requestServer(GET_LOAN_STATE_REFAHI, "get").then((response) => { + setDetail(response.data.data) + }).catch(() => { + }) + }, []); + console.log(detail) + + return ( + + {children} + + ); +} \ No newline at end of file diff --git a/src/pages/dashboard/refahi-loan-management/index.jsx b/src/pages/dashboard/refahi-loan-management/index.jsx new file mode 100644 index 0000000..e513af3 --- /dev/null +++ b/src/pages/dashboard/refahi-loan-management/index.jsx @@ -0,0 +1,26 @@ +import RolePermissionMiddleware from "@/middlewares/RolePermission"; +import WithAuthMiddleware from "@/middlewares/WithAuth"; +import {parse} from "next-useragent"; +import DashboardRefahiLoanManagementComponent from "@/components/dashboard/refahi-loan-management"; + +const requiredPermissions = ["manage_refahi_loan"]; +export default function RefahiLoanManagement() { + return ( + + + + + + ); +} + +export async function getServerSideProps({req, locale}) { + const {isBot} = parse(req.headers["user-agent"]); + return { + props: { + messages: (await import(`&/locales/${locale}/app.json`)).default, + title: "Dashboard.loan_management_page", + isBot, + }, + }; +}