updated filter section #31

Merged
ameye merged 1 commits from filter-update into master 2025-05-26 17:38:35 +00:00
2 changed files with 19 additions and 22 deletions
@@ -17,7 +17,7 @@ export default function TablePaginatedWrapper({
const handleNext = () => {
setPage(prev => prev + 1)
};
console.log('isFetching', isFetching)
return (
<div className="relative w-full">
<div className="flex flex-col">
+18 -21
View File
@@ -16,14 +16,22 @@ export default function TransactionsCom() {
const [allTransactions, setAllTransaction] = useState({loading:true, error:'', data:{}})
const [willFilter, setWillFilter] = useState(false)
const [filter, setFilter] = useState({transaction_id: '', account_id: ''})
const [filter, setFilter] = useState({type: '', id: ''})
const handleFilter = ({target:{name, value}}) => {
setFilter(prev => ({...prev, [name]:value}))
}
const handleFilterByParams = () => {
setPage(1)
setWillFilter(prev => !prev)
if(filter.type && !filter.id){
return
}else if(!filter.type){
setPage(1)
setWillFilter(prev => !prev)
setFilter({type: '', id: ''})
}else{
setPage(1)
setWillFilter(prev => !prev)
}
}
const transactions = allTransactions?.data?.transactions // TRANSACTIONS LIST
@@ -33,7 +41,8 @@ export default function TransactionsCom() {
useEffect(()=>{
setAllTransaction(prev => ({...prev, loading:true}))
getTransactions({...filter, page}).then(res => {
const payload = filter?.type ? {[filter?.type]: filter.id} : {}
getTransactions({...payload, page}).then(res => {
if(res?.status != 200){
setAllTransaction(prev => ({...prev, loading:false}))
return
@@ -58,28 +67,16 @@ export default function TransactionsCom() {
<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' />
<div className='w-full sm:max-w-48'>
<p>Transaction ID</p>
<select name='transaction_id' value={filter?.transaction_id} 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' onChange={handleFilter}>
<option value=''>All</option>
<>
{transactions?.map((item, index) => (
<option key={index} value={item?.transaction_id}>{item?.transaction_id}</option>
))}
</>
<option value='transaction_id'>Transaction ID</option>
<option value='account_id'>Account ID</option>
</select>
</div>
<div className='w-full sm:max-w-48'>
<p>Account ID</p>
<select name='account_id' value={filter?.account_id} className='h-10 w-full p-2 rounded-md' onChange={handleFilter}>
<option value=''>All</option>
<>
{transactions?.map((item, index) => (
<option key={index} value={item?.account_id}>{item?.account_id}</option>
))}
</>
</select>
<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} className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end`}>Submit</button>
<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 */}