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 (
)
- })}
+ })) : 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