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
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^4.1.3",
|
||||
"@tanstack/react-query": "5.69.0",
|
||||
"@tanstack/react-query": "5.69.2",
|
||||
"lucide-react": "^0.484.0",
|
||||
"next": "15.2.4",
|
||||
"nodemailer": "^6.10.0",
|
||||
|
||||
@@ -88,7 +88,8 @@ test.describe('Admin', () => {
|
||||
// based on your URL structure
|
||||
await page.goto(`/admin/accounts`);
|
||||
|
||||
const filterText = testUserEmail.split('@')[0]!;
|
||||
// use the email as the filter text
|
||||
const filterText = testUserEmail;
|
||||
|
||||
await filterAccounts(page, filterText);
|
||||
await selectAccount(page, filterText);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -50,12 +50,12 @@
|
||||
"@kit/supabase": "workspace:*",
|
||||
"@kit/team-accounts": "workspace:*",
|
||||
"@kit/ui": "workspace:*",
|
||||
"@makerkit/data-loader-supabase-core": "^0.0.8",
|
||||
"@makerkit/data-loader-supabase-nextjs": "^1.2.3",
|
||||
"@makerkit/data-loader-supabase-core": "^0.0.10",
|
||||
"@makerkit/data-loader-supabase-nextjs": "^1.2.5",
|
||||
"@marsidev/react-turnstile": "^1.1.0",
|
||||
"@radix-ui/react-icons": "^1.3.2",
|
||||
"@supabase/supabase-js": "2.49.3",
|
||||
"@tanstack/react-query": "5.69.0",
|
||||
"@tanstack/react-query": "5.69.2",
|
||||
"@tanstack/react-table": "^8.21.2",
|
||||
"date-fns": "^4.1.0",
|
||||
"lucide-react": "^0.484.0",
|
||||
|
||||
Reference in New Issue
Block a user