From e1f87576cebd1cdfed10b25fa8442525d8c1c848 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 29 Aug 2023 14:26:35 +0330 Subject: [PATCH 1/3] TF-87 loan management refahi --- public/locales/fa/app.json | 15 +- .../Form/UpdateForm.jsx | 150 +++++++++++++++++ .../TableRowActions.jsx | 17 ++ .../refahi-loan-management/index.jsx | 157 ++++++++++++++++++ src/core/data/apiRoutes.js | 8 + src/core/data/sidebarMenu.jsx | 11 ++ .../hooks/LoanStateRefahi.jsx | 25 +++ .../refahi-loan-management/index.jsx | 26 +++ 8 files changed, 408 insertions(+), 1 deletion(-) create mode 100644 src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx create mode 100644 src/components/dashboard/refahi-loan-management/TableRowActions.jsx create mode 100644 src/components/dashboard/refahi-loan-management/index.jsx create mode 100644 src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx create mode 100644 src/pages/dashboard/refahi-loan-management/index.jsx 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, + }, + }; +} From c91525d6cce51b4ebf627379aa0587f9e705157e Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 29 Aug 2023 14:36:12 +0330 Subject: [PATCH 2/3] TF-87 loan management refahi delete log --- src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx b/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx index 7df1a74..0aca505 100644 --- a/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx +++ b/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx @@ -13,7 +13,6 @@ export const LoanStateRefahiProvider = ({children}) => { }).catch(() => { }) }, []); - console.log(detail) return ( Date: Tue, 29 Aug 2023 15:24:33 +0330 Subject: [PATCH 3/3] TF-87 loan management refahi use SWR --- .../Form/UpdateForm.jsx | 10 ++--- .../refahi-loan-management/index.jsx | 39 +++++++++---------- .../hooks/LoanStateRefahi.jsx | 24 ------------ .../hooks/useLoanStateRefahi.jsx | 27 +++++++++++++ 4 files changed, 50 insertions(+), 50 deletions(-) delete mode 100644 src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx create mode 100644 src/lib/prefetchDataTable/hooks/useLoanStateRefahi.jsx diff --git a/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx b/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx index 1d2dd72..d4bf165 100644 --- a/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx +++ b/src/components/dashboard/refahi-loan-management/Form/UpdateForm.jsx @@ -1,5 +1,5 @@ import {useTranslations} from "next-intl"; -import {useContext, useState} from "react"; +import {useState} from "react"; import { Button, Dialog, @@ -22,12 +22,12 @@ 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"; +import useLoanStateRefahi from "@/lib/prefetchDataTable/hooks/useLoanStateRefahi"; const Update = ({rowId, fetchUrl, mutate}) => { const t = useTranslations(); - const detail = useContext(LoanStateRefahiContext); + const {loan_state_refahi} = useLoanStateRefahi() const [openConfirmDialog, setOpenConfirmDialog] = useState(false); const requestServer = useRequest({auth: true}) const {update_notification} = useNotification() @@ -120,11 +120,11 @@ const Update = ({rowId, fetchUrl, mutate}) => { formik.touched.next_state_id && formik.errors.next_state_id } > - {detail.map((item) => { + {loan_state_refahi ? (loan_state_refahi.map((item) => { return ( {item.name} ) - })} + })) : null} {formik.touched.next_state_id && formik.errors.next_state_id} diff --git a/src/components/dashboard/refahi-loan-management/index.jsx b/src/components/dashboard/refahi-loan-management/index.jsx index 8a571cc..4f0b3e1 100644 --- a/src/components/dashboard/refahi-loan-management/index.jsx +++ b/src/components/dashboard/refahi-loan-management/index.jsx @@ -7,7 +7,6 @@ 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(); @@ -129,26 +128,24 @@ function DashboardRefahiLoanManagementComponent() { 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} - /> - + } + 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} + /> ); diff --git a/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx b/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx deleted file mode 100644 index 0aca505..0000000 --- a/src/lib/prefetchDataTable/hooks/LoanStateRefahi.jsx +++ /dev/null @@ -1,24 +0,0 @@ -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(() => { - }) - }, []); - - return ( - - {children} - - ); -} \ No newline at end of file diff --git a/src/lib/prefetchDataTable/hooks/useLoanStateRefahi.jsx b/src/lib/prefetchDataTable/hooks/useLoanStateRefahi.jsx new file mode 100644 index 0000000..598ac72 --- /dev/null +++ b/src/lib/prefetchDataTable/hooks/useLoanStateRefahi.jsx @@ -0,0 +1,27 @@ +import useSWR from 'swr' +import {GET_LOAN_STATE_REFAHI} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; + +const useLoanStateRefahi = () => { + const requestServer = useRequest({auth: true, notification: false}) + + //swr config + const fetcher = (...args) => { + return requestServer(args, 'get').then((response) => { + return response.data.data; + }).catch(() => { + }) + }; + + const {data} = useSWR(GET_LOAN_STATE_REFAHI, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false + }) + const loan_state_refahi = data + //swr config + + // render data + return {loan_state_refahi} +} +export default useLoanStateRefahi \ No newline at end of file