Files
myeasycms-v2/apps/web/app/admin/accounts/page.tsx
Giancarlo Buomprisco 5b9285a575 Next.js 15 Update (#26)
* Update Next.js and React versions in all packages
* Replace onRedirect function with next/link in BillingSessionStatus, since it's no longer cached by default
* Remove unused revalidatePath import in billing return page, since it's no longer cached by default
* Add Turbopack module aliases to improve development server speed
* Converted new Dynamic APIs to be Promise-based
* Adjust mobile layout
* Use ENABLE_REACT_COMPILER to enable the React Compiler in Next.js 15
* Report Errors using the new onRequestError hook
2024-10-22 14:39:21 +08:00

87 lines
2.0 KiB
TypeScript

import { ServerDataLoader } from '@makerkit/data-loader-supabase-nextjs';
import { AdminAccountsTable } from '@kit/admin/components/admin-accounts-table';
import { AdminGuard } from '@kit/admin/components/admin-guard';
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
import { PageBody, PageHeader } from '@kit/ui/page';
interface SearchParams {
page?: string;
account_type?: 'all' | 'team' | 'personal';
query?: string;
}
interface AdminAccountsPageProps {
searchParams: Promise<SearchParams>;
}
export const metadata = {
title: `Accounts`,
};
async function AccountsPage(props: AdminAccountsPageProps) {
const client = getSupabaseServerAdminClient();
const searchParams = await props.searchParams;
const page = searchParams.page ? parseInt(searchParams.page) : 1;
const filters = getFilters(searchParams);
return (
<>
<PageHeader
title={'Accounts'}
description={`Below is the list of all the accounts in your application.`}
/>
<PageBody>
<ServerDataLoader
table={'accounts'}
client={client}
page={page}
where={filters}
>
{({ data, page, pageSize, pageCount }) => {
return (
<AdminAccountsTable
page={page}
pageSize={pageSize}
pageCount={pageCount}
data={data}
filters={{
type: searchParams.account_type ?? 'all',
}}
/>
);
}}
</ServerDataLoader>
</PageBody>
</>
);
}
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);