diff --git a/src/components/loan_charges/BillingsCom.jsx b/src/components/loan_charges/BillingsCom.jsx index b8d86c8..125da3e 100644 --- a/src/components/loan_charges/BillingsCom.jsx +++ b/src/components/loan_charges/BillingsCom.jsx @@ -1,10 +1,12 @@ import { useEffect, useState } from 'react' +import { useQuery } from '@tanstack/react-query' +import queryKeys from '../../services/queryKeys' import BreadcrumbCom from '../breadcrumb/BreadcrumbCom' import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper' import Icons from '../Icons' import { getBillings } from '../../services/siteServices' -import getDateFromDateString from '../../helpers/GetDateFromDateString'; +import getDateTimeFromDateString from '../../helpers/getDateTimeFromDateString'; import formatNumber from '../../helpers/formatNumber' import Avatar from '../../assets/user_avatar.jpg' @@ -12,10 +14,9 @@ import Avatar from '../../assets/user_avatar.jpg' export default function BillingsCom() { const [page, setPage] = useState(1) - const [allBillings, setAllBillings] = useState({loading:true, error:'', data:{}}) - - const [willFilter, setWillFilter] = useState(false) const [filter, setFilter] = useState({type: '', id: ''}) + const [willFilter, setWillFilter] = useState(false) + const handleFilter = ({target:{name, value}}) => { setFilter(prev => ({...prev, [name]:value})) } @@ -33,25 +34,20 @@ export default function BillingsCom() { } } - const billings = allBillings?.data?.loan_charges // LOAN CHARGES LIST - const pagination = allBillings?.data?.pagination - const isFetching = allBillings?.loading - const isError = allBillings?.error - - useEffect(()=>{ - setAllBillings(prev => ({...prev, loading:true})) - const payload = filter?.type ? {[filter?.type]: filter.id} : {} - getBillings({...payload, page}).then(res => { - if(res?.status != 200){ - setAllBillings(prev => ({...prev, error:'Opps, an error occurred', loading:false})) - return + const {data, isFetching, isError, error} = useQuery({ + queryKey: [...queryKeys.billings, page, willFilter], + queryFn: () => { + const filterData = filter?.type ? {[filter?.type]: filter.id} : {} + const reqData = { + page, + ...filterData } - setAllBillings({loading:false, error:'', data:res?.data}) - }).catch(err => { - setAllBillings({loading:false, error:'error occurred', data:{}}) - console.log('ERR', err) - }) - },[page, willFilter]) + return getBillings(reqData) + }, + staleTime: 0 //0 mins + }) + const billingData = data?.data?.payments // BILLINGS LIST + const pagination = data?.data?.pagination return (
{allBillings?.error}
+{error?.message}
: <> {/* filter section */} @@ -79,26 +75,26 @@ export default function BillingsCom() {| - Name + Added + | ++ Option Name + | ++ Product ID | - {/*- Loan - | */}Amount | - Added - | -- Action + Status |
|---|---|---|---|---|---|---|
|
-
-
{item?.transaction_id || ''}
- {item?.code}
+ {getDateTimeFromDateString(item?.added)}
|
+
+
+ {item?.option_name}
+ |
+
+
+
+ {item?.product_id}
+ |
+
- {/*
{formatNumber(item?.initial_loan_amount)} */}
- {formatNumber(item?.amount)}
+ {item?.amount}
+ {/* {item?.external_url} */}
|
-
{getDateFromDateString(item?.created_at)}
+ {item?.status}
|
-
-
-
-
-
- |
| - Request + Added | - Account + Product | - Activity + URL | - Action + Status | |
|---|---|---|---|---|
|
-
-
{item?.transaction_id}
- {getDateFromDateString(item?.created_at)} {getTimeFromDateString(item?.created_at)}
+ {getDateTimeFromDateString(item?.added)}
|
-
+ {item?.account_id}
- {item?.type}
+ {item?.product_id}
+ |
+
+
+
{item?.internal_url}
+ {item?.external_url}
|
-
- 50%
-
-
-
+
+
{item?.status}
|
-
-
-
-
-
-
- |