Reformat cod e
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import { useState } from 'react'
|
import {useState} from 'react'
|
||||||
import { useQuery } from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
import queryKeys from '../../services/queryKeys'
|
import queryKeys from '../../services/queryKeys'
|
||||||
|
|
||||||
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 { getProducts } from '../../services/siteServices'
|
import {getProducts} from '../../services/siteServices'
|
||||||
import getDateTimeFromDateString from '../../helpers/getDateTimeFromDateString'
|
import getDateTimeFromDateString from '../../helpers/getDateTimeFromDateString'
|
||||||
// import formatNumber from '../../helpers/formatNumber'
|
// import formatNumber from '../../helpers/formatNumber'
|
||||||
// import getDateTimeFromDateString from '../../helpers/getDateTimeFromDateString';
|
// import getDateTimeFromDateString from '../../helpers/getDateTimeFromDateString';
|
||||||
@@ -19,18 +19,18 @@ export default function ProductsCom() {
|
|||||||
const [filter, setFilter] = useState({type: '', id: ''})
|
const [filter, setFilter] = useState({type: '', id: ''})
|
||||||
const [willFilter, setWillFilter] = useState(false)
|
const [willFilter, setWillFilter] = useState(false)
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
@@ -54,99 +54,108 @@ export default function ProductsCom() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full flex flex-col gap-8'>
|
<div className='w-full flex flex-col gap-8'>
|
||||||
<BreadcrumbCom title='Products' paths={['Dashboard', 'Products']} />
|
<BreadcrumbCom title='Products' paths={['Dashboard', 'Products']}/>
|
||||||
|
|
||||||
<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'>{error?.message}</p>
|
<p className='text-red-500'>{error?.message}</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='name'>Name</option>
|
<option value=''>All</option>
|
||||||
</select>
|
<option value='name'>Name</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={productsData} isFetching={isFetching} setPage={setPage} itemsPerPage={pagination?.limit} pagination={pagination}>
|
<TablePaginatedWrapper data={productsData} 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>
|
||||||
Added
|
<th scope="col" className="px-2 py-2">
|
||||||
</th>
|
Added
|
||||||
<th scope="col" className="px-2">
|
</th>
|
||||||
Name
|
<th scope="col" className="px-2">
|
||||||
</th>
|
Name
|
||||||
<th scope="col" className="px-2">
|
</th>
|
||||||
Product ID
|
<th scope="col" className="px-2">
|
||||||
</th>
|
Product ID
|
||||||
<th scope="col" className="px-2 text-right">
|
</th>
|
||||||
Status
|
<th scope="col" className="px-2 text-right">
|
||||||
</th>
|
Status
|
||||||
<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'>
|
|
||||||
<div className="text-left">
|
|
||||||
<div className="text-base font-semibold">{getDateTimeFromDateString(item?.added)}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td className="px-2">
|
|
||||||
<div className="text-left">
|
|
||||||
<div className="text-base font-semibold">{item?.name}</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td className="px-2">
|
|
||||||
<div className="text-left">
|
|
||||||
<div className="text-base font-semibold">{item?.product_id}</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td className="px-2">
|
|
||||||
<div className="text-right">
|
|
||||||
<div className="text-base font-semibold">{item?.status}</div>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td className="px-2">
|
|
||||||
<div className="text-right">
|
|
||||||
<div className="text-base font-semibold">[---]</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>
|
<div className="text-left">
|
||||||
</tr>
|
<div
|
||||||
}
|
className="text-base font-semibold">{getDateTimeFromDateString(item?.added)}</div>
|
||||||
</tbody>
|
</div>
|
||||||
</table>
|
</div>
|
||||||
</>
|
</td>
|
||||||
)}
|
<td className="px-2">
|
||||||
</TablePaginatedWrapper>
|
<div className="text-left">
|
||||||
</>
|
<div className="text-base font-semibold">{item?.name}</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-2">
|
||||||
|
<div className="text-left">
|
||||||
|
<div
|
||||||
|
className="text-base font-semibold">{item?.product_id}</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-2">
|
||||||
|
<div className="text-right">
|
||||||
|
<div className="text-base font-semibold">{item?.status}</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-2">
|
||||||
|
<div className="text-right">
|
||||||
|
<div className="text-base font-semibold">[---]</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user