LFFE-29 debug history part and remove useHistory hook

This commit is contained in:
2023-11-29 11:45:39 +03:30
parent 1b56aff3a6
commit a398de7bd3
2 changed files with 17 additions and 31 deletions

View File

@@ -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 (
<Box>
@@ -29,7 +42,7 @@ const TableContent = ({rowId}) => {
justifyContent: "center"
}}>{t("LoanHistory.Table_history_error")}</Typography>) :
(isLoading ? (<LinearProgress sx={{width: "100%"}}/>) : (
history_details.latest_histories.length === 0 ? (
historyDetails.latest_histories.length === 0 ? (
<Typography
sx={{
padding: 2,
@@ -61,7 +74,7 @@ const TableContent = ({rowId}) => {
</TableHead>
<TableBody>
{
history_details.latest_histories.map((latest_history, index) => {
historyDetails.latest_histories.map((latest_history, index) => {
return (
<TableRow
key={index}

View File

@@ -1,27 +0,0 @@
import useSWR from 'swr'
import useRequest from "@/lib/app/hooks/useRequest";
const useHistory = (url) => {
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