Refined both admin and marketing layouts for a clearer design. Newly added components for the admin page include admin-account-page, admin-members-table and admin-memberships-table. Also included in this update are route renaming, minor text edits and corrections in the code.
83 lines
2.0 KiB
TypeScript
83 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 { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
|
|
|
interface SearchParams {
|
|
page?: string;
|
|
account_type?: 'all' | 'team' | 'personal';
|
|
query?: string;
|
|
}
|
|
|
|
export const metadata = {
|
|
title: `Accounts`,
|
|
};
|
|
|
|
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'}
|
|
description={`Manage your accounts, view their details, and more.`}
|
|
/>
|
|
|
|
<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: {
|
|
[key: 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);
|