65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { redirect } from 'next/navigation';
|
|
|
|
import { toTitleCase } from '@/lib/utils';
|
|
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';
|
|
|
|
import { PageBody, PageHeader } from '@kit/ui/page';
|
|
import { Trans } from '@kit/ui/trans';
|
|
import { createUserAnalysesApi } from '@kit/user-analyses/api';
|
|
|
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
|
|
|
import AIBlocks from '../_components/ai/ai-blocks';
|
|
import Dashboard from '../_components/dashboard';
|
|
import DashboardCards from '../_components/dashboard-cards';
|
|
import { loadCurrentUserAccount } from '../_lib/server/load-user-account';
|
|
|
|
export const generateMetadata = async () => {
|
|
const i18n = await createI18nServerInstance();
|
|
const title = i18n.t('account:homePage');
|
|
|
|
return {
|
|
title,
|
|
};
|
|
};
|
|
|
|
async function UserHomePage() {
|
|
const client = getSupabaseServerClient();
|
|
|
|
const { account } = await loadCurrentUserAccount();
|
|
const api = createUserAnalysesApi(client);
|
|
const bmiThresholds = await api.fetchBmiThresholds();
|
|
|
|
if (!account) {
|
|
redirect('/');
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<DashboardCards />
|
|
<PageHeader
|
|
title={
|
|
<>
|
|
<Trans i18nKey={'common:welcome'} />
|
|
{account.name ? `, ${toTitleCase(account.name)}` : ''}
|
|
</>
|
|
}
|
|
description={<Trans i18nKey={'dashboard:recentlyCheckedDescription'} />}
|
|
/>
|
|
<PageBody>
|
|
<Dashboard account={account} bmiThresholds={bmiThresholds} />
|
|
|
|
<h4>
|
|
<Trans i18nKey="dashboard:recommendations.title" />
|
|
</h4>
|
|
<div className="mt-4 grid gap-6 sm:grid-cols-3">
|
|
<AIBlocks account={account} />
|
|
</div>
|
|
</PageBody>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default withI18n(UserHomePage);
|