Added accounts table page in Admin

This commit is contained in:
giancarlo
2024-04-08 16:32:22 +08:00
parent 45417fe2c5
commit 767e2f21b5
11 changed files with 1481 additions and 220 deletions

View File

@@ -1,13 +1,70 @@
import { ServerDataLoader } from '@makerkit/data-loader-supabase-nextjs';
import { AccountsTable } from '@kit/admin/components/accounts-table';
import { AdminGuard } from '@kit/admin/components/admin-guard';
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
import { PageBody, PageHeader } from '@kit/ui/page';
function AccountsPage() {
interface SearchParams {
page?: string;
account_type?: 'all' | 'team' | 'personal';
}
function AccountsPage({ searchParams }: { searchParams: SearchParams }) {
const client = getSupabaseServerComponentClient({
admin: true,
});
const page = searchParams.page ? parseInt(searchParams.page) : 1;
const filters = getFilters(searchParams);
return (
<>
<PageHeader title={'Accounts'} />
<PageBody></PageBody>;
<PageHeader
title={'Accounts'}
description={`Manage your accounts, view their details, and more.`}
/>
<PageBody>
<ServerDataLoader
table={'accounts'}
client={client}
page={page}
where={filters}
>
{({ data, page, pageSize, pageCount }) => {
return (
<AccountsTable
page={page}
pageSize={pageSize}
pageCount={pageCount}
data={data}
filters={{
type: searchParams.account_type ?? 'all',
}}
/>
);
}}
</ServerDataLoader>
</PageBody>
</>
);
}
function getFilters(params: SearchParams) {
const filters: {
[key: string]: {
eq: boolean;
};
} = {};
if (params.account_type && params.account_type !== 'all') {
filters.is_personal_account = {
eq: params.account_type === 'personal',
};
}
return filters;
}
export default AdminGuard(AccountsPage);