New Data Loader + Improvement to accounts filtering in admin
1. Update data loaders (#223) 2. Use new data loader functionality to allow filtering by both name and email in Super Admin 3. Update test to use email filtering
This commit is contained in:
committed by
GitHub
parent
e7f17dd34f
commit
dd5219e445
@@ -23,9 +23,7 @@ export const metadata = {
|
||||
async function AccountsPage(props: AdminAccountsPageProps) {
|
||||
const client = getSupabaseServerClient();
|
||||
const searchParams = await props.searchParams;
|
||||
|
||||
const page = searchParams.page ? parseInt(searchParams.page) : 1;
|
||||
const filters = getFilters(searchParams);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -36,7 +34,19 @@ async function AccountsPage(props: AdminAccountsPageProps) {
|
||||
table={'accounts'}
|
||||
client={client}
|
||||
page={page}
|
||||
where={filters}
|
||||
where={(queryBuilder) => {
|
||||
const { account_type: type, query } = searchParams;
|
||||
|
||||
if (type && type !== 'all') {
|
||||
queryBuilder.eq('is_personal_account', type === 'personal');
|
||||
}
|
||||
|
||||
if (query) {
|
||||
queryBuilder.or(`name.ilike.%${query}%,email.ilike.%${query}%`);
|
||||
}
|
||||
|
||||
return queryBuilder;
|
||||
}}
|
||||
>
|
||||
{({ data, page, pageSize, pageCount }) => {
|
||||
return (
|
||||
@@ -58,28 +68,4 @@ async function AccountsPage(props: AdminAccountsPageProps) {
|
||||
);
|
||||
}
|
||||
|
||||
function getFilters(params: SearchParams) {
|
||||
const filters: Record<
|
||||
string,
|
||||
{
|
||||
eq?: boolean | string;
|
||||
like?: string;
|
||||
}
|
||||
> = {};
|
||||
|
||||
if (params.account_type && params.account_type !== 'all') {
|
||||
filters.is_personal_account = {
|
||||
eq: params.account_type === 'personal',
|
||||
};
|
||||
}
|
||||
|
||||
if (params.query) {
|
||||
filters.name = {
|
||||
like: `%${params.query}%`,
|
||||
};
|
||||
}
|
||||
|
||||
return filters;
|
||||
}
|
||||
|
||||
export default AdminGuard(AccountsPage);
|
||||
|
||||
Reference in New Issue
Block a user