The commit refactors the previous implementation of using cache functions across several modules. They are now explicitly defined as loaders to improve readability and maintain a consistent style. This prevents the cache function calls from getting too nested and difficult to understand, especially in asynchronous cases. Additionally, the user session related hooks are deleted which were not used anymore.
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import { cache } from 'react';
|
|
|
|
import { AdminAccountPage } from '@kit/admin/components/admin-account-page';
|
|
import { AdminGuard } from '@kit/admin/components/admin-guard';
|
|
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
|
import { PageBody } from '@kit/ui/page';
|
|
|
|
interface Params {
|
|
params: {
|
|
id: string;
|
|
};
|
|
}
|
|
|
|
export const generateMetadata = async ({ params }: Params) => {
|
|
const account = await loadAccount(params.id);
|
|
|
|
return {
|
|
title: `Admin | ${account.name}`,
|
|
};
|
|
};
|
|
|
|
async function AccountPage({ params }: Params) {
|
|
const account = await loadAccount(params.id);
|
|
|
|
return (
|
|
<PageBody className={'py-4'}>
|
|
<AdminAccountPage account={account} />
|
|
</PageBody>
|
|
);
|
|
}
|
|
|
|
export default AdminGuard(AccountPage);
|
|
|
|
const loadAccount = cache(accountLoader);
|
|
|
|
async function accountLoader(id: string) {
|
|
const client = getSupabaseServerComponentClient({
|
|
admin: true,
|
|
});
|
|
|
|
const { data, error } = await client
|
|
.from('accounts')
|
|
.select('*, memberships: accounts_memberships (*)')
|
|
.eq('id', id)
|
|
.single();
|
|
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
|
|
return data;
|
|
}
|