Loan details updates

This commit is contained in:
CHIEFSOFT\ameye
2025-11-02 21:23:21 -05:00
parent 53092d1ad7
commit 2b22d7132a
8 changed files with 479 additions and 423 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

+115 -102
View File
@@ -1,33 +1,33 @@
import { useEffect, useState } from 'react' import {useEffect, useState} from 'react'
import BreadcrumbCom from '../breadcrumb/BreadcrumbCom' import BreadcrumbCom from '../breadcrumb/BreadcrumbCom'
import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper' import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper'
import Icons from '../Icons' import Icons from '../Icons'
import { getLoanCharges } from '../../services/siteServices' import {getLoanCharges} from '../../services/siteServices'
import getDateFromDateString from '../../helpers/GetDateFromDateString'; import getDateFromDateString from '../../helpers/GetDateFromDateString';
import formatNumber from '../../helpers/formatNumber' import formatNumber from '../../helpers/formatNumber'
import Avatar from '../../assets/user_avatar.jpg' import Avatar from '../../assets/repay.png'
export default function LoansChargesCom() { export default function LoansChargesCom() {
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [allLoanCharges, setAllLoanCharges] = useState({loading:true, error:'', data:{}}) const [allLoanCharges, setAllLoanCharges] = useState({loading: true, error: '', data: {}})
const [willFilter, setWillFilter] = useState(false) const [willFilter, setWillFilter] = useState(false)
const [filter, setFilter] = useState({type: '', id: ''}) const [filter, setFilter] = useState({type: '', id: ''})
const handleFilter = ({target:{name, value}}) => { const handleFilter = ({target: {name, value}}) => {
setFilter(prev => ({...prev, [name]:value})) setFilter(prev => ({...prev, [name]: value}))
} }
const handleFilterByParams = () => { const handleFilterByParams = () => {
if(filter.type && !filter.id){ if (filter.type && !filter.id) {
return return
}else if(!filter.type){ } else if (!filter.type) {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
setFilter({type: '', id: ''}) setFilter({type: '', id: ''})
}else{ } else {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
} }
@@ -38,117 +38,130 @@ export default function LoansChargesCom() {
const isFetching = allLoanCharges?.loading const isFetching = allLoanCharges?.loading
const isError = allLoanCharges?.error const isError = allLoanCharges?.error
useEffect(()=>{ useEffect(() => {
setAllLoanCharges(prev => ({...prev, loading:true})) setAllLoanCharges(prev => ({...prev, loading: true}))
const payload = filter?.type ? {[filter?.type]: filter.id} : {} const payload = filter?.type ? {[filter?.type]: filter.id} : {}
getLoanCharges({...payload, page}).then(res => { getLoanCharges({...payload, page}).then(res => {
if(res?.status != 200){ if (res?.status != 200) {
setAllLoanCharges(prev => ({...prev, loading:false})) setAllLoanCharges(prev => ({...prev, loading: false}))
return return
} }
setAllLoanCharges({loading:false, error:'', data:res?.data}) setAllLoanCharges({loading: false, error: '', data: res?.data})
}).catch(err => { }).catch(err => {
setAllLoanCharges({loading:false, error:'error occurred', data:{}}) setAllLoanCharges({loading: false, error: 'error occurred', data: {}})
console.log('ERR', err) console.log('ERR', err)
}) })
},[page, willFilter]) }, [page, willFilter])
return ( return (
<div className='w-full flex flex-col gap-8'> <div className='w-full flex flex-col gap-8'>
<BreadcrumbCom title='Transactions' paths={['Dashboard', 'Transactions']} /> <BreadcrumbCom title='Charges' paths={['Dashboard', 'Charges']}/>
<div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'> <div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'>
{ isError ? {isError ?
<p className='text-red-500'>{allLoanCharges?.error}</p> <p className='text-red-500'>{allLoanCharges?.error}</p>
: :
<> <>
{/* filter section */} {/* filter section */}
<div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'> <div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'>
<Icons name='filter' className='text-3xl' /> <Icons name='filter' className='text-3xl'/>
<div className='w-full sm:max-w-48'> <div className='w-full sm:max-w-48'>
<select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md' onChange={handleFilter}> <select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md'
<option value=''>All</option> onChange={handleFilter}>
<option value='transaction_id'>Transaction ID</option> <option value=''>All</option>
<option value='account_id'>Account ID</option> <option value='transaction_id'>Transaction ID</option>
</select> <option value='account_id'>Account ID</option>
</select>
</div>
<div className='w-full sm:max-w-48'>
<input name='id' value={filter?.id} disabled={!filter.type}
className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`}
onChange={handleFilter}/>
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id}
className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit
</button>
</div> </div>
<div className='w-full sm:max-w-48'> {/* end of filter section */}
<input name='id' value={filter?.id} disabled={!filter.type} className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`} onChange={handleFilter} />
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id} className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit</button>
</div>
{/* end of filter section */}
<TablePaginatedWrapper data={loanCharges} isFetching={isFetching} setPage={setPage} itemsPerPage={pagination?.limit} pagination={pagination}> <TablePaginatedWrapper data={loanCharges} isFetching={isFetching} setPage={setPage}
{({ data }) => ( itemsPerPage={pagination?.limit} pagination={pagination}>
<> {({data}) => (
<table className="py-2 w-full text-sm"> <>
<thead className="py-2 text-sm text-slate-500 text-left"> <table className="py-2 w-full text-sm">
<tr> <thead className="py-2 text-sm text-slate-500 text-left">
<th scope="col" className="px-2 py-2"> <tr>
Name <th scope="col" className="px-2 py-2">
</th> TransactionID/Fee Type
{/* <th scope="col" className="px-2"> </th>
{/* <th scope="col" className="px-2">
Loan Loan
</th> */} </th> */}
<th scope="col" className="px-2 text-right"> <th scope="col" className="px-2 text-right">
Amount Amount
</th> </th>
<th scope="col" className="px-2 text-right"> <th scope="col" className="px-2 text-right">
Added Added
</th> </th>
<th scope="col" className="px-2 text-right"> <th scope="col" className="px-2 text-right">
Action Action
</th> </th>
</tr>
</thead>
<tbody>
{(data && data.length > 0) ? data?.map((item, index) => (
<tr key={index} className="py-2 border-t border-dashed border-slate-300">
<td className="px-2 py-2">
<div className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
<img className="w-10 h-10 rounded-md" src={Avatar} alt="Jese image" />
<div className="text-left">
<div className="text-base font-semibold">{item?.transaction_id || ''}</div>
<div className="font-normal text-gray-500 line-clamp-1">{item?.code}</div>
</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
{/* <div className="text-base font-semibold">{formatNumber(item?.initial_loan_amount)}</div> */}
<div className="font-normal text-gray-500">{formatNumber(item?.amount)}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)}</div>
</div>
</td>
<td className="px-2 text-right">
<div className='flex items-center justify-end gap-3 md:gap-4'>
<div className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Icons name='eye' />
</div>
</div>
</td>
</tr> </tr>
)) </thead>
: <tbody>
<tr className="py-2 border-t border-dashed border-slate-300"> {(data && data.length > 0) ? data?.map((item, index) => (
<td className="px-3 py-2" colSpan={4}> <tr key={index} className="py-2 border-t border-dashed border-slate-300">
<div className="flex justify-center items-center"> <td className="px-2 py-2">
No Record Found <div
</div> className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
</td> <img className="w-10 h-10 rounded-md" src={Avatar}
</tr> alt="Jese image"/>
} <div className="text-left">
</tbody> <div
</table> className="text-base font-semibold">{item?.transaction_id || ''}</div>
</> <div
)} className="font-normal text-gray-500 line-clamp-1">{item?.code}</div>
</TablePaginatedWrapper> </div>
</> </div>
</td>
<td className="px-2">
<div className="text-right">
{/* <div className="text-base font-semibold">{formatNumber(item?.initial_loan_amount)}</div> */}
<div
className="font-semibold text-green-500">#{formatNumber(item?.amount)}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div
className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)}</div>
</div>
</td>
<td className="px-2 text-right">
<div className='flex items-center justify-end gap-3 md:gap-4'>
<div
className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Icons name='eye'/>
</div>
</div>
</td>
</tr>
))
:
<tr className="py-2 border-t border-dashed border-slate-300">
<td className="px-3 py-2" colSpan={4}>
<div className="flex justify-center items-center">
No Record Found
</div>
</td>
</tr>
}
</tbody>
</table>
</>
)}
</TablePaginatedWrapper>
</>
} }
</div> </div>
</div> </div>
+139 -121
View File
@@ -1,34 +1,34 @@
import { useEffect, useState } from 'react' import {useEffect, useState} from 'react'
import {Link} from 'react-router-dom' import {Link} from 'react-router-dom'
import BreadcrumbCom from '../breadcrumb/BreadcrumbCom' import BreadcrumbCom from '../breadcrumb/BreadcrumbCom'
import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper' import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper'
import Icons from '../Icons' import Icons from '../Icons'
import { getLoans } from '../../services/siteServices' import {getLoans} from '../../services/siteServices'
import getDateFromDateString from '../../helpers/GetDateFromDateString'; import getDateFromDateString from '../../helpers/GetDateFromDateString';
import Avatar from '../../assets/user_avatar.jpg' import Avatar from '../../assets/loans.png'
import RouteLinks from '../../RouteLinks'; import RouteLinks from '../../RouteLinks';
import formatNumber from '../../helpers/formatNumber' import formatNumber from '../../helpers/formatNumber'
export default function LoansCom() { export default function LoansCom() {
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [allLoans, setAllLoans] = useState({loading:true, error:'', data:{}}) const [allLoans, setAllLoans] = useState({loading: true, error: '', data: {}})
const [willFilter, setWillFilter] = useState(false) const [willFilter, setWillFilter] = useState(false)
const [filter, setFilter] = useState({type: '', id: ''}) const [filter, setFilter] = useState({type: '', id: ''})
const handleFilter = ({target:{name, value}}) => { const handleFilter = ({target: {name, value}}) => {
setFilter(prev => ({...prev, [name]:value})) setFilter(prev => ({...prev, [name]: value}))
} }
const handleFilterByParams = () => { const handleFilterByParams = () => {
if(filter.type && !filter.id){ if (filter.type && !filter.id) {
return return
}else if(!filter.type){ } else if (!filter.type) {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
setFilter({type: '', id: ''}) setFilter({type: '', id: ''})
}else{ } else {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
} }
@@ -39,134 +39,152 @@ export default function LoansCom() {
const isFetching = allLoans?.loading const isFetching = allLoans?.loading
const isError = allLoans?.error const isError = allLoans?.error
useEffect(()=>{ useEffect(() => {
setAllLoans(prev => ({...prev, loading:true})) setAllLoans(prev => ({...prev, loading: true}))
const payload = filter?.type ? {[filter?.type]: filter.id} : {} const payload = filter?.type ? {[filter?.type]: filter.id} : {}
getLoans({...payload, page}).then(res => { getLoans({...payload, page}).then(res => {
if(res?.status != 200){ if (res?.status != 200) {
setAllLoans(prev => ({...prev, loading:false})) setAllLoans(prev => ({...prev, loading: false}))
return return
} }
setAllLoans({loading:false, error:'', data:res?.data}) setAllLoans({loading: false, error: '', data: res?.data})
}).catch(err => { }).catch(err => {
setAllLoans({loading:false, error:'error occurred', data:{}}) setAllLoans({loading: false, error: 'error occurred', data: {}})
console.log('ERR', err) console.log('ERR', err)
}) })
},[page, willFilter]) }, [page, willFilter])
return ( return (
<div className='w-full flex flex-col gap-8'> <div className='w-full flex flex-col gap-8'>
<BreadcrumbCom title='Transactions' paths={['Dashboard', 'Transactions']} /> <BreadcrumbCom title='Loans' paths={['Dashboard', 'Loans']}/>
<div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'> <div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'>
{ isError ? {isError ?
<p className='text-red-500'>{allLoans?.error}</p> <p className='text-red-500'>{allLoans?.error}</p>
: :
<> <>
{/* filter section */} {/* filter section */}
<div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'> <div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'>
<Icons name='filter' className='text-3xl' /> <Icons name='filter' className='text-3xl'/>
<div className='w-full sm:max-w-48'> <div className='w-full sm:max-w-48'>
<select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md' onChange={handleFilter}> <select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md'
<option value=''>All</option> onChange={handleFilter}>
<option value='transaction_id'>Transaction ID</option> <option value=''>All</option>
<option value='account_id'>Account ID</option> <option value='transaction_id'>Transaction ID</option>
</select> <option value='account_id'>Account ID</option>
</select>
</div>
<div className='w-full sm:max-w-48'>
<input name='id' value={filter?.id} disabled={!filter.type}
className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`}
onChange={handleFilter}/>
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id}
className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit
</button>
</div> </div>
<div className='w-full sm:max-w-48'> {/* end of filter section */}
<input name='id' value={filter?.id} disabled={!filter.type} className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`} onChange={handleFilter} />
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id} className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit</button>
</div>
{/* end of filter section */}
<TablePaginatedWrapper data={loans} isFetching={isFetching} setPage={setPage} itemsPerPage={pagination?.limit} pagination={pagination}> <TablePaginatedWrapper data={loans} isFetching={isFetching} setPage={setPage}
{({ data }) => ( itemsPerPage={pagination?.limit} pagination={pagination}>
<> {({data}) => (
<table className="table-auto py-2 w-full text-sm"> <>
<thead className="py-2 text-sm text-slate-500 text-left"> <table className="table-auto py-2 w-full text-sm">
<tr> <thead className="py-2 text-sm text-slate-500 text-left">
<th scope="col" className="px-2 py-2"> <tr>
Name <th scope="col" className="px-2 py-2">
</th> Name
<th scope="col" className="px-2 text-right"> </th>
Loan Amount <th scope="col" className="px-2 text-right">
</th> Loan Amount
<th scope="col" className="px-2 text-right"> </th>
Product/Tenor <th scope="col" className="px-2 text-right">
</th> Product/Tenor
<th scope="col" className="px-2 text-right"> </th>
Repay/Install Amount <th scope="col" className="px-2 text-right">
</th> Repay/Install Amount
<th scope="col" className="px-2 text-right"> </th>
Added <th scope="col" className="px-2 text-right">
</th> Added
<th scope="col" className="px-2 text-right"> </th>
Action <th scope="col" className="px-2 text-right">
</th> Action
</tr> </th>
</thead>
<tbody>
{(data && data.length > 0) ? data?.map((item, index) => (
<tr key={index} className="py-2 border-t border-dashed border-slate-300">
<td className="px-2 py-2">
<div className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
<img className="w-10 h-10 rounded-md" src={Avatar} alt="Jese image" />
<div className="text-left">
<div className="text-base font-semibold">{item?.account_id || ''}</div>
<div className="font-normal text-gray-500">{item?.id} : {item?.transaction_id}</div>
</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
{/* <div className="text-base font-semibold">{formatNumber(item?.initial_loan_amount)}</div> */}
<div className="font-normal text-gray-500">{formatNumber(item?.initial_loan_amount)}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="font-normal text-gray-500">{formatNumber(item?.product_id)}</div>
<div className="font-normal text-gray-500">{item?.tenor} days</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="font-normal text-gray-500">{formatNumber(item?.repayment_amount)}</div>
<div className="font-normal text-gray-500">{formatNumber(item?.installment_amount)}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)}</div>
</div>
</td>
<td className="px-2 text-right">
<div className='flex items-center justify-end gap-3 md:gap-4'>
<div className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Link to={RouteLinks.transaction_details_page} state={{transactionID: item?.transaction_id}}>
<Icons name='eye' />
</Link>
</div>
</div>
</td>
</tr> </tr>
)) </thead>
: <tbody>
<tr className="py-2 border-t border-dashed border-slate-300"> {(data && data.length > 0) ? data?.map((item, index) => (
<td className="px-3 py-2" colSpan={6}> <tr key={index} className="py-2 border-t border-dashed border-slate-300">
<div className="flex justify-center items-center"> <td className="px-2 py-2">
No Record Found <div
</div> className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
</td> <img className="w-10 h-10 rounded-md" src={Avatar}
</tr> alt="Jese image"/>
} <div className="text-left">
</tbody> <div
</table> className="text-base font-semibold">{item?.account_id || ''}</div>
</> <div
)} className="font-normal text-gray-500">{item?.id} : {item?.transaction_id}</div>
</TablePaginatedWrapper> </div>
</> </div>
</td>
<td className="px-2">
<div className="text-right">
{/* <div className="text-base font-semibold">{formatNumber(item?.initial_loan_amount)}</div> */}
<div
className="font-semibold text-green-500">#{formatNumber(item?.initial_loan_amount)}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div
className="font-normal text-gray-500">{formatNumber(item?.product_id)}</div>
<div className="font-normal text-red-500">{item?.tenor} days
</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div
className="font-normal text-gray-500">{formatNumber(item?.repayment_amount)}</div>
<div
className="font-normal text-gray-500">{formatNumber(item?.installment_amount)}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div
className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)}</div>
</div>
</td>
<td className="px-2 text-right">
<div className='flex items-center justify-end gap-3 md:gap-4'>
<div
className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Link to={RouteLinks.transaction_details_page}
state={{transactionID: item?.transaction_id}}>
<Icons name='eye'/>
</Link>
</div>
</div>
</td>
</tr>
))
:
<tr className="py-2 border-t border-dashed border-slate-300">
<td className="px-3 py-2" colSpan={6}>
<div className="flex justify-center items-center">
No Record Found
</div>
</td>
</tr>
}
</tbody>
</table>
</>
)}
</TablePaginatedWrapper>
</>
} }
</div> </div>
</div> </div>
+107 -94
View File
@@ -1,32 +1,32 @@
import { useEffect, useState } from 'react' import {useEffect, useState} from 'react'
import BreadcrumbCom from '../breadcrumb/BreadcrumbCom' import BreadcrumbCom from '../breadcrumb/BreadcrumbCom'
import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper' import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper'
import Icons from '../Icons' import Icons from '../Icons'
import { getRepayments } from '../../services/siteServices' import {getRepayments} from '../../services/siteServices'
import getDateFromDateString from '../../helpers/GetDateFromDateString'; import getDateFromDateString from '../../helpers/GetDateFromDateString';
import Avatar from '../../assets/user_avatar.jpg' import Avatar from '../../assets/loans2.png';
export default function RepaymentsCom() { export default function RepaymentsCom() {
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [allRepayments, setAllRepayments] = useState({loading:true, error:'', data:{}}) const [allRepayments, setAllRepayments] = useState({loading: true, error: '', data: {}})
const [willFilter, setWillFilter] = useState(false) const [willFilter, setWillFilter] = useState(false)
const [filter, setFilter] = useState({type: '', id: ''}) const [filter, setFilter] = useState({type: '', id: ''})
const handleFilter = ({target:{name, value}}) => { const handleFilter = ({target: {name, value}}) => {
setFilter(prev => ({...prev, [name]:value})) setFilter(prev => ({...prev, [name]: value}))
} }
const handleFilterByParams = () => { const handleFilterByParams = () => {
if(filter.type && !filter.id){ if (filter.type && !filter.id) {
return return
}else if(!filter.type){ } else if (!filter.type) {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
setFilter({type: '', id: ''}) setFilter({type: '', id: ''})
}else{ } else {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
} }
@@ -37,114 +37,127 @@ export default function RepaymentsCom() {
const isFetching = allRepayments?.loading const isFetching = allRepayments?.loading
const isError = allRepayments?.error const isError = allRepayments?.error
useEffect(()=>{ useEffect(() => {
setAllRepayments(prev => ({...prev, loading:true})) setAllRepayments(prev => ({...prev, loading: true}))
const payload = filter?.type ? {[filter?.type]: filter.id} : {} const payload = filter?.type ? {[filter?.type]: filter.id} : {}
getRepayments({...payload, page}).then(res => { getRepayments({...payload, page}).then(res => {
if(res?.status != 200){ if (res?.status != 200) {
setAllRepayments(prev => ({...prev, loading:false})) setAllRepayments(prev => ({...prev, loading: false}))
return return
} }
setAllRepayments({loading:false, error:'', data:res?.data}) setAllRepayments({loading: false, error: '', data: res?.data})
}).catch(err => { }).catch(err => {
setAllRepayments({loading:false, error:'error occurred', data:{}}) setAllRepayments({loading: false, error: 'error occurred', data: {}})
console.log('ERR', err) console.log('ERR', err)
}) })
},[page, willFilter]) }, [page, willFilter])
return ( return (
<div className='w-full flex flex-col gap-8'> <div className='w-full flex flex-col gap-8'>
<BreadcrumbCom title='Transactions' paths={['Dashboard', 'Transactions']} /> <BreadcrumbCom title='Repayments' paths={['Dashboard', 'Repayments']}/>
<div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'> <div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'>
{ isError ? {isError ?
<p className='text-red-500'>{allRepayments?.error}</p> <p className='text-red-500'>{allRepayments?.error}</p>
: :
<> <>
{/* filter section */} {/* filter section */}
<div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'> <div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'>
<Icons name='filter' className='text-3xl' /> <Icons name='filter' className='text-3xl'/>
<div className='w-full sm:max-w-48'> <div className='w-full sm:max-w-48'>
<select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md' onChange={handleFilter}> <select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md'
<option value=''>All</option> onChange={handleFilter}>
<option value='transaction_id'>Transaction ID</option> <option value=''>All</option>
<option value='account_id'>Account ID</option> <option value='transaction_id'>Transaction ID</option>
</select> <option value='account_id'>Account ID</option>
</select>
</div>
<div className='w-full sm:max-w-48'>
<input name='id' value={filter?.id} disabled={!filter.type}
className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`}
onChange={handleFilter}/>
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id}
className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit
</button>
</div> </div>
<div className='w-full sm:max-w-48'> {/* end of filter section */}
<input name='id' value={filter?.id} disabled={!filter.type} className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`} onChange={handleFilter} />
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id} className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit</button>
</div>
{/* end of filter section */}
<TablePaginatedWrapper data={repayments} isFetching={isFetching} setPage={setPage} itemsPerPage={pagination?.limit} pagination={pagination}> <TablePaginatedWrapper data={repayments} isFetching={isFetching} setPage={setPage}
{({ data }) => ( itemsPerPage={pagination?.limit} pagination={pagination}>
<> {({data}) => (
<table className="py-2 w-full text-sm"> <>
<thead className="py-2 text-sm text-slate-500 text-left"> <table className="py-2 w-full text-sm">
<tr> <thead className="py-2 text-sm text-slate-500 text-left">
<th scope="col" className="px-2 py-2"> <tr>
Name <th scope="col" className="px-2 py-2">
</th> CustomerID / ID:TrxID
{/* <th scope="col" className="px-2"> </th>
{/* <th scope="col" className="px-2">
Loan Loan
</th> */} </th> */}
<th scope="col" className="px-2"> <th scope="col" className="px-2">
Added Added
</th> </th>
<th scope="col" className="px-2 text-right"> <th scope="col" className="px-2 text-right">
Action Action
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{(data && data.length > 0) ? data?.map((item, index) => ( {(data && data.length > 0) ? data?.map((item, index) => (
<tr key={index} className="py-2 border-t border-dashed border-slate-300"> <tr key={index} className="py-2 border-t border-dashed border-slate-300">
<td className="px-2 py-2"> <td className="px-2 py-2">
<div className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'> <div
<img className="w-10 h-10 rounded-md" src={Avatar} alt="Jese image" /> className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
<div className="text-left"> <img className="w-10 h-10 rounded-md" src={Avatar}
<div className="text-base font-semibold">{item?.customer_id || ''}</div> alt="Jese image"/>
<div className="font-normal text-gray-500">{item?.loan_id} : {item?.transaction_id}</div> <div className="text-left">
</div> <div
</div> className="text-base font-semibold">{item?.customer_id || ''}</div>
</td> <div
{/* <td className="px-2"> className="font-normal text-blue-500">{item?.loan_id} :<b> {item?.transaction_id}</b>
</div>
</div>
</div>
</td>
{/* <td className="px-2">
<div className="text-left"> <div className="text-left">
<div className="text-base font-semibold">{item?.loan}</div> <div className="text-base font-semibold">{item?.loan}</div>
<div className="font-normal text-gray-500">{item?.description}</div> <div className="font-normal text-gray-500">{item?.description}</div>
</div> </div>
</td> */} </td> */}
<td className="px-2"> <td className="px-2">
<div className="text-left"> <div className="text-left">
<div className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)}</div> <div
</div> className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)}</div>
</td> </div>
<td className="px-2 text-right"> </td>
<div className='flex items-center justify-end gap-3 md:gap-4'> <td className="px-2 text-right">
<div className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'> <div className='flex items-center justify-end gap-3 md:gap-4'>
<Icons name='eye' /> <div
className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Icons name='eye'/>
</div>
</div>
</td>
</tr>
))
:
<tr className="py-2 border-t border-dashed border-slate-300">
<td className="px-3 py-2" colSpan={3}>
<div className="flex justify-center items-center">
No Record Found
</div> </div>
</div> </td>
</td> </tr>
</tr> }
)) </tbody>
: </table>
<tr className="py-2 border-t border-dashed border-slate-300"> </>
<td className="px-3 py-2" colSpan={3}> )}
<div className="flex justify-center items-center"> </TablePaginatedWrapper>
No Record Found </>
</div>
</td>
</tr>
}
</tbody>
</table>
</>
)}
</TablePaginatedWrapper>
</>
} }
</div> </div>
</div> </div>
@@ -3,7 +3,7 @@ import {useQuery} from "@tanstack/react-query";
import Icons from '../Icons' import Icons from '../Icons'
import Avatar from '../../assets/user_avatar.jpg' import Avatar from '../../assets/loans.png'
import queryKeys from '../../services/queryKeys' import queryKeys from '../../services/queryKeys'
import {getLoans} from '../../services/siteServices' import {getLoans} from '../../services/siteServices'
import getDateFromDateString from '../../helpers/GetDateFromDateString'; import getDateFromDateString from '../../helpers/GetDateFromDateString';
+117 -105
View File
@@ -1,10 +1,10 @@
import { useEffect, useState } from 'react' import {useEffect, useState} from 'react'
import {Link} from 'react-router-dom' import {Link} from 'react-router-dom'
import BreadcrumbCom from '../breadcrumb/BreadcrumbCom' import BreadcrumbCom from '../breadcrumb/BreadcrumbCom'
import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper' import TablePaginatedWrapper from '../tableWrapper/TablePaginatedWrapper'
import Icons from '../Icons' import Icons from '../Icons'
import { getTransactions } from '../../services/siteServices' import {getTransactions} from '../../services/siteServices'
import getDateFromDateString from '../../helpers/GetDateFromDateString'; import getDateFromDateString from '../../helpers/GetDateFromDateString';
import getTimeFromDateString from '../../helpers/GetTimeFromDateString'; import getTimeFromDateString from '../../helpers/GetTimeFromDateString';
import localImgLoader from '../../helpers/localImageLoader'; import localImgLoader from '../../helpers/localImageLoader';
@@ -13,22 +13,22 @@ import RouteLinks from '../../RouteLinks';
export default function TransactionsCom() { export default function TransactionsCom() {
const [page, setPage] = useState(1) const [page, setPage] = useState(1)
const [allTransactions, setAllTransaction] = useState({loading:true, error:'', data:{}}) const [allTransactions, setAllTransaction] = useState({loading: true, error: '', data: {}})
const [willFilter, setWillFilter] = useState(false) const [willFilter, setWillFilter] = useState(false)
const [filter, setFilter] = useState({type: '', id: ''}) const [filter, setFilter] = useState({type: '', id: ''})
const handleFilter = ({target:{name, value}}) => { const handleFilter = ({target: {name, value}}) => {
setFilter(prev => ({...prev, [name]:value})) setFilter(prev => ({...prev, [name]: value}))
} }
const handleFilterByParams = () => { const handleFilterByParams = () => {
if(filter.type && !filter.id){ if (filter.type && !filter.id) {
return return
}else if(!filter.type){ } else if (!filter.type) {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
setFilter({type: '', id: ''}) setFilter({type: '', id: ''})
}else{ } else {
setPage(1) setPage(1)
setWillFilter(prev => !prev) setWillFilter(prev => !prev)
} }
@@ -39,119 +39,131 @@ export default function TransactionsCom() {
const isFetching = allTransactions?.loading const isFetching = allTransactions?.loading
const isError = allTransactions?.error const isError = allTransactions?.error
useEffect(()=>{ useEffect(() => {
setAllTransaction(prev => ({...prev, loading:true})) setAllTransaction(prev => ({...prev, loading: true}))
const payload = filter?.type ? {[filter?.type]: filter.id} : {} const payload = filter?.type ? {[filter?.type]: filter.id} : {}
getTransactions({...payload, page}).then(res => { getTransactions({...payload, page}).then(res => {
if(res?.status != 200){ if (res?.status != 200) {
setAllTransaction(prev => ({...prev, loading:false})) setAllTransaction(prev => ({...prev, loading: false}))
return return
} }
setAllTransaction({loading:false, error:'', data:res?.data}) setAllTransaction({loading: false, error: '', data: res?.data})
}).catch(err => { }).catch(err => {
setAllTransaction({loading:false, error:'error occurred', data:{}}) setAllTransaction({loading: false, error: 'error occurred', data: {}})
console.log('ERR', err) console.log('ERR', err)
}) })
},[page, willFilter]) }, [page, willFilter])
return ( return (
<div className='w-full flex flex-col gap-8'> <div className='w-full flex flex-col gap-8'>
<BreadcrumbCom title='Transactions' paths={['Dashboard', 'Transactions']} /> <BreadcrumbCom title='Transactions' paths={['Dashboard', 'Transactions']}/>
<div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'> <div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'>
{ isError ? {isError ?
<p className='text-red-500'>{allTransactions?.error}</p> <p className='text-red-500'>{allTransactions?.error}</p>
: :
<> <>
{/* filter section */} {/* filter section */}
<div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'> <div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'>
<Icons name='filter' className='text-3xl' /> <Icons name='filter' className='text-3xl'/>
<div className='w-full sm:max-w-48'> <div className='w-full sm:max-w-48'>
<select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md' onChange={handleFilter}> <select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md'
<option value=''>All</option> onChange={handleFilter}>
<option value='transaction_id'>Transaction ID</option> <option value=''>All</option>
<option value='account_id'>Account ID</option> <option value='transaction_id'>Transaction ID</option>
</select> <option value='account_id'>Account ID</option>
</select>
</div>
<div className='w-full sm:max-w-48'>
<input name='id' value={filter?.id} disabled={!filter.type}
className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`}
onChange={handleFilter}/>
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id}
className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit
</button>
</div> </div>
<div className='w-full sm:max-w-48'> {/* end of filter section */}
<input name='id' value={filter?.id} disabled={!filter.type} className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && 'opacity-30'}`} onChange={handleFilter} />
</div>
<button onClick={handleFilterByParams} disabled={filter.type && !filter.id} className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${(filter.type && !filter.id) && 'opacity-50'}`}>Submit</button>
</div>
{/* end of filter section */}
<TablePaginatedWrapper data={transactions} isFetching={isFetching} setPage={setPage} itemsPerPage={pagination?.limit} pagination={pagination}> <TablePaginatedWrapper data={transactions} isFetching={isFetching} setPage={setPage}
{({ data }) => ( itemsPerPage={pagination?.limit} pagination={pagination}>
<> {({data}) => (
<table className="py-2 w-full text-sm"> <>
<thead className="py-2 text-sm text-slate-500 text-left"> <table className="py-2 w-full text-sm">
<tr> <thead className="py-2 text-sm text-slate-500 text-left">
<th scope="col" className="px-2 py-2"> <tr>
Request <th scope="col" className="px-2 py-2">
</th> Request
<th scope="col" className="px-2"> </th>
Account <th scope="col" className="px-2">
</th> Account
<th scope="col" className="px-2"> </th>
Activity <th scope="col" className="px-2">
</th> Customer/ID
<th scope="col" className="px-2 text-right"> </th>
Action <th scope="col" className="px-2 text-right">
</th> Action
</tr> </th>
</thead>
<tbody>
{(data && data.length > 0) ? data?.map((item, index) => (
<tr key={index} className="py-2 border-t border-dashed border-slate-300">
<td className="px-2 py-2">
<div className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
<img className="w-10 h-10 rounded-md" src={localImgLoader(`loan_icons/${item?.type}.png`)} alt="Icon" />
<div className="text-left">
<div className="text-base font-semibold">{item?.transaction_id}</div>
<div className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)} {getTimeFromDateString(item?.created_at)}</div>
</div>
</div>
</td>
<td className="px-2">
<div className="text-left">
<div className="text-base font-semibold">{item?.account_id}</div>
<div className="font-normal text-gray-500">{item?.type}</div>
</div>
</td>
<td className="px-2">
<div className="text-left">
<div className="font-normal text-gray-500">50%</div>
<div className="relative h-[6px] w-full bg-white-body dark:bg-black-body rounded-full overflow-hidden">
<div className={`absolute left-0 h-full w-1/2 bg-emerald-600`}></div>
</div>
</div>
</td>
<td className="px-2 text-right">
<div className='flex items-center justify-end gap-3 md:gap-4'>
<div className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Link to={RouteLinks.transaction_details_page} state={{transactionID: item?.transaction_id}}>
<Icons name='eye' />
</Link>
</div>
</div>
</td>
</tr> </tr>
)) </thead>
: <tbody>
<tr className="py-2 border-t border-dashed border-slate-300"> {(data && data.length > 0) ? data?.map((item, index) => (
<td className="px-3 py-2" colSpan={4}> <tr key={index} className="py-2 border-t border-dashed border-slate-300">
<div className="flex justify-center items-center"> <td className="px-2 py-2">
No Record Found <div
</div> className='w-full min-w-48 flex items-center gap-2 whitespace-nowrap'>
</td> <img className="w-10 h-10 rounded-md"
</tr> src={localImgLoader(`loan_icons/${item?.type}.png`)}
} alt="Icon"/>
</tbody> <div className="text-left">
</table> <div
</> className="text-base font-semibold">{item?.transaction_id}</div>
)} <div
</TablePaginatedWrapper> className="font-normal text-gray-500">{getDateFromDateString(item?.created_at)} {getTimeFromDateString(item?.created_at)}</div>
</> </div>
</div>
</td>
<td className="px-2">
<div className="text-left">
<div
className="text-base font-semibold">{item?.account_id}</div>
<div className="font-normal text-gray-500">{item?.type}</div>
</div>
</td>
<td className="px-2">
<div className="text-left">
<div className="text-base font-semibold">{item?.customer_id}</div>
<div className="font-normal text-red-500"><b>ID:</b>{item?.id}</div>
</div>
</td>
<td className="px-2 text-right">
<div className='flex items-center justify-end gap-3 md:gap-4'>
<div
className='p-2 flex justify-center items-center text-slate-500 bg-white-body dark:text-white-body dark:bg-black-body rounded-md'>
<Link to={RouteLinks.transaction_details_page}
state={{transactionID: item?.transaction_id}}>
<Icons name='eye'/>
</Link>
</div>
</div>
</td>
</tr>
))
:
<tr className="py-2 border-t border-dashed border-slate-300">
<td className="px-3 py-2" colSpan={4}>
<div className="flex justify-center items-center">
No Record Found
</div>
</td>
</tr>
}
</tbody>
</table>
</>
)}
</TablePaginatedWrapper>
</>
} }
</div> </div>
</div> </div>