From b154160a37c7eaf5af9bb2dfc4e8d6bea97b12ec Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Mon, 20 Nov 2023 16:42:38 +0330 Subject: [PATCH 1/5] LFFE-29 first demo of loan history --- package.json | 1 + public/locales/fa/app.json | 9 +- .../Form/HistoryForm/HistoryContent.jsx | 190 ++++++++++++++++++ .../loan-history/Form/HistoryForm/index.jsx | 31 +++ .../loan-history/TableRowActions.jsx | 16 ++ .../dashboard/loan-history/index.jsx | 187 +++++++++++++++++ src/core/data/sidebarMenu.jsx | 10 + src/pages/dashboard/loan-history/index.jsx | 21 ++ 8 files changed, 463 insertions(+), 2 deletions(-) create mode 100644 src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx create mode 100644 src/components/dashboard/loan-history/Form/HistoryForm/index.jsx create mode 100644 src/components/dashboard/loan-history/TableRowActions.jsx create mode 100644 src/components/dashboard/loan-history/index.jsx create mode 100644 src/pages/dashboard/loan-history/index.jsx diff --git a/package.json b/package.json index 4583a4c..c03278c 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@emotion/styled": "^11.10.6", "@mui/icons-material": "^5.11.16", "@mui/material": "^5.12.0", + "@mui/x-data-grid": "^6.18.1", "@mui/x-date-pickers": "^6.9.2", "apexcharts": "^3.44.0", "axios": "^1.4.0", diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index b9b8070..9b1e9f4 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -57,7 +57,8 @@ "expert-management": "مدیریت کارشناسان", "user-management": "مدیریت کاربر", "role-management": "مدیریت نقش ها", - "edit-profile": "ویرایش پروفایل" + "edit-profile": "ویرایش پروفایل", + "loan-history": "تاریخچه وام ها" }, "secondary": { "passenger-office": "توزیع درخواست", @@ -115,7 +116,8 @@ "role_management_page": "مدیریت نقش ها", "edit_profile": "ویرایش پروفایل", "expert_management": "مدیریت کارشناسان", - "user_management_page": "مدیریت کاربر" + "user_management_page": "مدیریت کاربر", + "loan_history": "تاریخچهِ وام ها" }, "MuiDatePicker": { "date_picker_birthday": "تاریخ" @@ -533,5 +535,8 @@ "excel_export": "خروجی به اکسل", "export": "دریافت", "update_again": "بروزرسانی مجدد" + }, + "LoanHistory": { + "history": "تاریخچه" } } diff --git a/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx b/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx new file mode 100644 index 0000000..d2c23d0 --- /dev/null +++ b/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx @@ -0,0 +1,190 @@ +import { + Button, + CircularProgress, + DialogActions, + DialogContent, + Paper, + Table, + TableBody, + TableCell, + TableContainer, + TableHead, + TableRow +} from "@mui/material" +import {useTranslations} from "next-intl"; +import {useFormik} from "formik"; +import {EXPORT_MACHINARY_OFFICE} from "@/core/data/apiRoutes"; +import moment from "jalali-moment"; +import DescriptionIcon from "@mui/icons-material/Description"; +import {useState} from "react"; + +const fakeData = [ + { + date: "1401/08/28", + name: "امین قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "امیر قاسم پور", + place: "اداره راه و شهرسازی مشهد", + toDo: "ارجاع به معاونت حمل و نقل" + }, + { + date: "1401/08/28", + name: "محمد جلالی", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "احمد قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "اکبر قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "اصغر قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "نیما قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, + { + date: "1401/08/28", + name: "مهدی قاسم پور", + place: "اداره راه و شهرسازی تهران", + toDo: "ارجاع به کارشناس" + }, +] +const HistoryContent = ({mutate, setOpenConfirmDialog, rowId}) => { + const t = useTranslations(); + const [loading, setLoading] = useState(false) + const clickHandler = () => { + setLoading(true) + requestServer(`${EXPORT_MACHINARY_OFFICE}?${filterParams}`, 'get', { + auth: true, + notification: false, + requestOptions: {responseType: 'blob'} + }).then((response) => { + const filename = `گزارش ماشین آلات تاریخ_${moment().format('jYYYY_jMM_jDD')}.xlsx`; + FileSaver.saveAs(response.data, filename); + }).catch(() => { + }).finally(() => { + setLoading(false) + }) + } + const formik = useFormik({}); + + return ( + <> + + + + + + نام + تاریخ + سازمان + وضعیت + فایل ضمیمه + + + + {fakeData.map((singleData) => ( + + + {singleData.name} + + {singleData.date} + {singleData.place} + {singleData.toDo} + + + + + ))} + +
+
+
+ + + + + ) + +} +export default HistoryContent \ No newline at end of file diff --git a/src/components/dashboard/loan-history/Form/HistoryForm/index.jsx b/src/components/dashboard/loan-history/Form/HistoryForm/index.jsx new file mode 100644 index 0000000..de20f60 --- /dev/null +++ b/src/components/dashboard/loan-history/Form/HistoryForm/index.jsx @@ -0,0 +1,31 @@ +import {Dialog, DialogTitle, IconButton, Tooltip} from "@mui/material"; +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import HistoryIcon from '@mui/icons-material/History'; +import HistoryContent from "@/components/dashboard/loan-history/Form/HistoryForm/HistoryContent"; + +const History = ({rowId, mutate}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("LoanHistory.history")} + + + + ) + +} +export default History; \ No newline at end of file diff --git a/src/components/dashboard/loan-history/TableRowActions.jsx b/src/components/dashboard/loan-history/TableRowActions.jsx new file mode 100644 index 0000000..d0a967f --- /dev/null +++ b/src/components/dashboard/loan-history/TableRowActions.jsx @@ -0,0 +1,16 @@ +import {Box} from "@mui/material"; +import History from "@/components/dashboard/loan-history/Form/HistoryForm"; + +const TableRow = ({row, mutate}) => { + return ( + + + + ); +}; + +export default TableRow; diff --git a/src/components/dashboard/loan-history/index.jsx b/src/components/dashboard/loan-history/index.jsx new file mode 100644 index 0000000..0f0a261 --- /dev/null +++ b/src/components/dashboard/loan-history/index.jsx @@ -0,0 +1,187 @@ +import {Box, Typography} from "@mui/material"; +import {useMemo} from "react"; +import {GET_MACHINARY_OFFICE} from "@/core/data/apiRoutes"; +import {useTranslations} from "next-intl"; +import TableRowActions from "./TableRowActions"; +import moment from "jalali-moment"; +import DataTable from "@/core/components/DataTable"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; + +function DashboardLoanHistoryComponent() { + const t = useTranslations(); + const columns = useMemo( + () => [ + { + accessorFn: (row) => row.id, + id: "id", + header: t("PassengerOffice.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("MachinaryOffice.name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.national_id, + id: "national_id", + header: t("MachinaryOffice.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("MachinaryOffice.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("MachinaryOffice.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("MachinaryOffice.updated_at"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.navgan_id, + id: "navgan_id", + header: t("MachinaryOffice.navgan_id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.vehicle_type, + id: "vehicle_type", + header: t("MachinaryOffice.vehicle_type"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.state_name, + id: "state_id", + header: t("MachinaryOffice.state_name"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + ], + [] + ); + const data = [{ + id: 1 + }] + return ( + + + + ); +} + +export default DashboardLoanHistoryComponent; diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 029ca26..f858852 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -14,6 +14,7 @@ import ManageAccountsIcon from '@mui/icons-material/ManageAccounts'; import PersonIcon from '@mui/icons-material/Person'; import AccessibilityIcon from '@mui/icons-material/Accessibility'; import AssessmentIcon from '@mui/icons-material/Assessment'; +import AccessTimeIcon from '@mui/icons-material/AccessTime'; const sidebarMenu = [ [ @@ -176,6 +177,15 @@ const sidebarMenu = [ selected: false, permission: "manage_roles", }, + { + key: "sidebar.loan-history", + name: "loan-history", + type: "page", + route: "/dashboard/loan-history", + icon: , + selected: false, + permission: "manage_navgan_loan", + }, ], ]; diff --git a/src/pages/dashboard/loan-history/index.jsx b/src/pages/dashboard/loan-history/index.jsx new file mode 100644 index 0000000..d84d43e --- /dev/null +++ b/src/pages/dashboard/loan-history/index.jsx @@ -0,0 +1,21 @@ +import {parse} from "next-useragent"; +import DashboardLoanHistoryComponent from "@/components/dashboard/loan-history"; + +export default function LoanHistory() { + 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_history", + isBot, + locale, + layout: {name: 'DashboardLayout', props: {permissions: ["manage_navgan_loan"]}} + }, + }; +} From d8eb780a32437959a009d23991725be5ae7175b1 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Tue, 21 Nov 2023 10:59:51 +0330 Subject: [PATCH 2/5] LFFE-29 table content structured --- .../Form/HistoryForm/HistoryContent.jsx | 172 +------------- .../Form/HistoryForm/TableContent.jsx | 210 ++++++++++++++++++ 2 files changed, 214 insertions(+), 168 deletions(-) create mode 100644 src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx diff --git a/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx b/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx index d2c23d0..040aef8 100644 --- a/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx +++ b/src/components/dashboard/loan-history/Form/HistoryForm/HistoryContent.jsx @@ -1,181 +1,17 @@ -import { - Button, - CircularProgress, - DialogActions, - DialogContent, - Paper, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow -} from "@mui/material" +import {Button, DialogActions, DialogContent,} from "@mui/material" import {useTranslations} from "next-intl"; import {useFormik} from "formik"; -import {EXPORT_MACHINARY_OFFICE} from "@/core/data/apiRoutes"; -import moment from "jalali-moment"; -import DescriptionIcon from "@mui/icons-material/Description"; -import {useState} from "react"; +import TableContent from "@/components/dashboard/loan-history/Form/HistoryForm/TableContent"; -const fakeData = [ - { - date: "1401/08/28", - name: "امین قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "امیر قاسم پور", - place: "اداره راه و شهرسازی مشهد", - toDo: "ارجاع به معاونت حمل و نقل" - }, - { - date: "1401/08/28", - name: "محمد جلالی", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "احمد قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "اکبر قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "اصغر قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "نیما قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, -] const HistoryContent = ({mutate, setOpenConfirmDialog, rowId}) => { const t = useTranslations(); - const [loading, setLoading] = useState(false) - const clickHandler = () => { - setLoading(true) - requestServer(`${EXPORT_MACHINARY_OFFICE}?${filterParams}`, 'get', { - auth: true, - notification: false, - requestOptions: {responseType: 'blob'} - }).then((response) => { - const filename = `گزارش ماشین آلات تاریخ_${moment().format('jYYYY_jMM_jDD')}.xlsx`; - FileSaver.saveAs(response.data, filename); - }).catch(() => { - }).finally(() => { - setLoading(false) - }) - } + const formik = useFormik({}); return ( <> - - - - - نام - تاریخ - سازمان - وضعیت - فایل ضمیمه - - - - {fakeData.map((singleData) => ( - - - {singleData.name} - - {singleData.date} - {singleData.place} - {singleData.toDo} - - - - - ))} - -
-
+
+ ) +} + +export default PrintHistory \ No newline at end of file diff --git a/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx b/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx index 3a6603d..cd0569b 100644 --- a/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx +++ b/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx @@ -1,210 +1,88 @@ import { - Button, - CircularProgress, + Box, + LinearProgress, Paper, Table, TableBody, TableCell, TableContainer, TableHead, - TableRow + TableRow, + Typography } from "@mui/material"; -import DescriptionIcon from "@mui/icons-material/Description"; -import {useState} from "react"; import {useTranslations} from "next-intl"; +import useHistory from "@/lib/app/hooks/useHistory"; +import {GET_HISTORY_DETAIL} from "@/core/data/apiRoutes"; +import moment from "jalali-moment"; +import PrintHistory from "@/components/dashboard/loan-history/Form/HistoryForm/PrintHistory"; -const fakeData = [ - { - date: "1401/08/28", - name: "امین قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "امیر قاسم پور", - place: "اداره راه و شهرسازی مشهد", - toDo: "ارجاع به معاونت حمل و نقل" - }, - { - date: "1401/08/28", - name: "محمد جلالی", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "احمد قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "اکبر قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "اصغر قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "نیما قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, - { - date: "1401/08/28", - name: "مهدی قاسم پور", - place: "اداره راه و شهرسازی تهران", - toDo: "ارجاع به کارشناس" - }, -] -const TableContent = () => { +const TableContent = ({rowId}) => { const t = useTranslations(); - const [loading, setLoading] = useState(false) - - const clickHandler = () => { - } + const {history_details, isLoading, error} = useHistory(`${GET_HISTORY_DETAIL}/${rowId}`) return ( - + {error ? ({t("LoanHistory.Table_history_error")}) : + (isLoading ? () : ( + history_details.latest_histories.length === 0 ? ( + {t("LoanHistory.empty_history_detail")} + ) : ( + + + + + + {t("LoanHistory.Table_head_name")} + {t("LoanHistory.Table_head_date")} + {t("LoanHistory.Table_head_position")} + {t("LoanHistory.Table_head_action")} + {t("LoanHistory.Table_head_file")} + + + + { + history_details.latest_histories.map((latest_history, index) => { + return ( + + + {latest_history.expert.name} + + {moment(latest_history.created_at).locale("fa").format("HH:mm | yyyy/MM/DD")} + {latest_history.expert.position} + {latest_history.previous_state_name} + + {latest_history.attachment ? ( + + ) : null} + + + ) + }) + } + +
+
+
+ ) + )) } - }}> - - - - - نام - تاریخ - سمت - عملیات - فایل پیوست - - - - {fakeData.map((singleData, index) => { - return ( - - - {singleData.name} - - {singleData.date} - {singleData.place} - {singleData.toDo} - - - - - ) - })} - -
-
-
+ + ) } export default TableContent \ No newline at end of file diff --git a/src/components/dashboard/loan-history/index.jsx b/src/components/dashboard/loan-history/index.jsx index 0f0a261..c2bb293 100644 --- a/src/components/dashboard/loan-history/index.jsx +++ b/src/components/dashboard/loan-history/index.jsx @@ -1,6 +1,6 @@ import {Box, Typography} from "@mui/material"; import {useMemo} from "react"; -import {GET_MACHINARY_OFFICE} from "@/core/data/apiRoutes"; +import {GET_LOAN_HISTORY} from "@/core/data/apiRoutes"; import {useTranslations} from "next-intl"; import TableRowActions from "./TableRowActions"; import moment from "jalali-moment"; @@ -154,14 +154,10 @@ function DashboardLoanHistoryComponent() { ], [] ); - const data = [{ - id: 1 - }] return ( { + + 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, isLoading, error} = useSWR(url, fetcher) + const history_details = data + //swr config + + // render data + return {history_details, isLoading, error} +} +export default useHistory \ No newline at end of file From 1b56aff3a625f95db48c2e241684856705628edd Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Tue, 28 Nov 2023 16:36:58 +0330 Subject: [PATCH 4/5] LFFE-29 structured table of data --- .../loan-history/Form/HistoryForm/TableContent.jsx | 14 ++++++++++++-- src/core/data/sidebarMenu.jsx | 4 ++-- src/lib/app/hooks/useHistory.jsx | 6 +++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx b/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx index cd0569b..2459b47 100644 --- a/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx +++ b/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx @@ -22,11 +22,21 @@ const TableContent = ({rowId}) => { return ( - {error ? ({t("LoanHistory.Table_history_error")}) : + {error ? ({t("LoanHistory.Table_history_error")}) : (isLoading ? () : ( history_details.latest_histories.length === 0 ? ( {t("LoanHistory.empty_history_detail")} ) : ( , + icon: , selected: false, permission: "manage_navgan_loan", }, diff --git a/src/lib/app/hooks/useHistory.jsx b/src/lib/app/hooks/useHistory.jsx index 86d4d09..10aa3fc 100644 --- a/src/lib/app/hooks/useHistory.jsx +++ b/src/lib/app/hooks/useHistory.jsx @@ -13,7 +13,11 @@ const useHistory = (url) => { }) }; - const {data, isLoading, error} = useSWR(url, fetcher) + const {data, isLoading, error} = useSWR(url, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false + }) const history_details = data //swr config From a398de7bd36b4cb76fe2e01b16ce1a3e9a0c7638 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Wed, 29 Nov 2023 11:45:39 +0330 Subject: [PATCH 5/5] LFFE-29 debug history part and remove useHistory hook --- .../Form/HistoryForm/TableContent.jsx | 21 ++++++++++++--- src/lib/app/hooks/useHistory.jsx | 27 ------------------- 2 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 src/lib/app/hooks/useHistory.jsx diff --git a/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx b/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx index 2459b47..34b1529 100644 --- a/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx +++ b/src/components/dashboard/loan-history/Form/HistoryForm/TableContent.jsx @@ -11,14 +11,27 @@ import { Typography } from "@mui/material"; import {useTranslations} from "next-intl"; -import useHistory from "@/lib/app/hooks/useHistory"; import {GET_HISTORY_DETAIL} from "@/core/data/apiRoutes"; import moment from "jalali-moment"; import PrintHistory from "@/components/dashboard/loan-history/Form/HistoryForm/PrintHistory"; +import useRequest from "@/lib/app/hooks/useRequest"; +import {useEffect, useState} from "react"; const TableContent = ({rowId}) => { const t = useTranslations(); - const {history_details, isLoading, error} = useHistory(`${GET_HISTORY_DETAIL}/${rowId}`) + const requestServer = useRequest({auth: true, notification: false}) + const [historyDetails, setHistoryDetails] = useState([]); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(false); + + useEffect(() => { + requestServer(`${GET_HISTORY_DETAIL}/${rowId}`, 'get').then((response) => { + setIsLoading(false); + setHistoryDetails(response.data.data); + }).catch(() => { + setError(true); + }) + }, []); return ( @@ -29,7 +42,7 @@ const TableContent = ({rowId}) => { justifyContent: "center" }}>{t("LoanHistory.Table_history_error")}) : (isLoading ? () : ( - history_details.latest_histories.length === 0 ? ( + historyDetails.latest_histories.length === 0 ? ( { { - history_details.latest_histories.map((latest_history, index) => { + historyDetails.latest_histories.map((latest_history, index) => { return ( { - - 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, isLoading, error} = useSWR(url, fetcher, { - revalidateIfStale: false, - revalidateOnFocus: false, - revalidateOnReconnect: false - }) - const history_details = data - //swr config - - // render data - return {history_details, isLoading, error} -} -export default useHistory \ No newline at end of file