Files
myeasycms-v2/apps/web/app/admin/accounts/page.tsx
giancarlo 936adc271c Add Super Admin layout and update subscription functionalities
The key changes made in this code include the addition of a Super Admin layout. Also, subscription functionalities are updated and optimized. This ensures read, write permissions are specific to the relevant user and a helper function has been implemented to check if an account has an active subscription. Furthermore, UI enhancements have been made to the accounts table in the administration section. The seed data has also been modified.
2024-04-24 19:00:55 +07:00

76 lines
1.7 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';
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 (
<>
<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>
</>
);
}
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);