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