recent signup

This commit is contained in:
2026-04-26 20:45:18 -04:00
parent 044b880726
commit fc38378210
+192 -135
View File
@@ -1,146 +1,203 @@
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 { getRecentSignup } from '../../services/siteServices' import { getRecentSignup } from "../../services/siteServices";
import getDateTimeFromDateString from '../../helpers/getDateTimeFromDateString' import getDateTimeFromDateString from "../../helpers/getDateTimeFromDateString";
// import formatNumber from '../../helpers/formatNumber' import {Link} from 'react-router-dom';
// import formatNumber from '../../helpers/formatNumber'
// import Avatar from '../../assets/user_avatar.jpg'
export default function RecentSignup() { export default function RecentSignup() {
const [page, setPage] = useState(1);
const [filter, setFilter] = useState({ type: "", id: "" });
const [willFilter, setWillFilter] = useState(false);
const [page, setPage] = useState(1) const handleFilter = ({ target: { name, value } }) => {
const [filter, setFilter] = useState({type: '', id: ''}) setFilter((prev) => ({ ...prev, [name]: value }));
const [willFilter, setWillFilter] = useState(false) };
const handleFilter = ({target:{name, value}}) => { const handleFilterByParams = () => {
setFilter(prev => ({...prev, [name]:value})) 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 handleFilterByParams = () => { const { data, isFetching, isError, error } = useQuery({
if(filter.type && !filter.id){ queryKey: [...queryKeys.recent_signup, page, willFilter],
return queryFn: () => {
}else if(!filter.type){ const filterData = filter?.type ? { [filter?.type]: filter.id } : {};
setPage(1) const reqData = {
setWillFilter(prev => !prev) page,
setFilter({type: '', id: ''}) ...filterData,
}else{ };
setPage(1) return getRecentSignup(reqData);
setWillFilter(prev => !prev) },
} staleTime: 0, //0 mins
} });
const recentSignupData = data?.data?.members; // BILLINGS LIST
const pagination = data?.data?.pagination;
// console.log('DATA', data?.data)
const {data, isFetching, isError, error} = useQuery({ return (
queryKey: [...queryKeys.recent_signup, page, willFilter], <div className="w-full flex flex-col gap-8">
queryFn: () => { <BreadcrumbCom
const filterData = filter?.type ? {[filter?.type]: filter.id} : {} title="Recent Signup"
const reqData = { paths={["Dashboard", "Recent Acc"]}
page, />
...filterData
}
return getRecentSignup(reqData)
},
staleTime: 0 //0 mins
})
const recentSignupData = data?.data?.payments // BILLINGS LIST
const pagination = data?.data?.pagination
// console.log('DATA', data?.data)
return ( <div className="box bg-white dark:bg-black-box text-black-body dark:text-white-body">
<div className='w-full flex flex-col gap-8'> {isError ? (
<BreadcrumbCom title='Recent Signup' paths={['Dashboard', 'Recent Acc']} /> <p className="text-red-500">{error?.message}</p>
) : (
<div className='box bg-white dark:bg-black-box text-black-body dark:text-white-body'> <>
{ isError ? {/* filter section */}
<p className='text-red-500'>{error?.message}</p> <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">
{/* filter section */} <select
<div className='px-2 py-2 mb-4 flex flex-col sm:flex-row flex-wrap sm:items-center gap-2'> name="type"
<Icons name='filter' className='text-3xl' /> value={filter?.type}
<div className='w-full sm:max-w-48'> className="h-10 w-full p-2 rounded-md"
<select name='type' value={filter?.type} className='h-10 w-full p-2 rounded-md' onChange={handleFilter}> onChange={handleFilter}
<option value=''>All</option> >
<option value='name'>Name</option> <option value="">All</option>
</select> <option value="username">Username</option>
</div> </select>
<div className='w-full sm:max-w-48'> </div>
<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 className="w-full sm:max-w-48">
</div> <input
<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> name="id"
</div> value={filter?.id}
{/* end of filter section */} disabled={!filter.type}
className={`h-10 w-full p-2 rounded-md outline-none border border-black-aside ${!filter.type && "opacity-30"}`}
<TablePaginatedWrapper data={recentSignupData} isFetching={isFetching} setPage={setPage} itemsPerPage={pagination?.limit} pagination={pagination}> onChange={handleFilter}
{({ data }) => ( />
<> </div>
<table className="py-2 w-full text-sm"> <button
<thead className="py-2 text-sm text-slate-500 text-left"> onClick={handleFilterByParams}
<tr> disabled={filter.type && !filter.id}
<th scope="col" className="px-2 py-2"> className={`h-10 bg-primary px-2 py-1 rounded-md text-white font-medium sm:self-end ${filter.type && !filter.id && "opacity-50"}`}
Added >
</th> Submit
<th scope="col" className="px-2"> </button>
Option Name
</th>
<th scope="col" className="px-2 text-right">
Amount
</th>
<th scope="col" className="px-2 text-right">
Status
</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'>
<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?.option_name}</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="text-base font-semibold">${item?.amount}</div>
{/* <div className="font-normal text-gray-500">{item?.external_url}</div> */}
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="text-base font-semibold">{item?.status}</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> {/* end of filter section */}
)
} <TablePaginatedWrapper
data={recentSignupData}
isFetching={isFetching}
setPage={setPage}
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">
<tr>
<th scope="col" className="px-2 py-2">
Added
</th>
<th scope="col" className="px-2">
User Name /Email
</th>
<th scope="col" className="px-2 text-right">
Name
</th>
<th scope="col" className="px-2 text-right">
Country
</th>
<th scope="col" className="px-2 text-right">
Action
</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">
<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?.username}
</div>
<div className="text-base font-semibold">
{item?.email}
</div>
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="text-base font-semibold">
{item?.firstname} {item?.lastname}
</div>
{/* <div className="font-normal text-gray-500">{item?.external_url}</div> */}
</div>
</td>
<td className="px-2">
<div className="text-right">
<div className="text-base font-semibold">
{item?.country}
</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={`/account-view/${item?.member_uid}`}
state={{
customerID: item?.id,
memberUID: item?.member_uid,
}}
>
<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>
);
}