This commit updates diverse packages such as "@makerkit/data-loader-supabase-core" and "@makerkit/data-loader-supabase-nextjs" to the new versions in the package.json files. Also, several refactorings were done in logging within services and loaders by progressing 'server-only' imports and improving context handling. Additionally, type annotations have been added to several exported functions for better code readability and maintainability.
84 lines
2.0 KiB
TypeScript
84 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: 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);
|