SSR pages crash with 500 when Supabase queries fail (expired session, network issues). Now catch errors and render with empty data instead of crashing the entire page.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
|
import { createVerbandApi } from '@kit/verbandsverwaltung/api';
|
|
import { VerbandTabNavigation, VerbandDashboard } from '@kit/verbandsverwaltung/components';
|
|
|
|
import { CmsPageShell } from '~/components/cms-page-shell';
|
|
import { AccountNotFound } from '~/components/account-not-found';
|
|
|
|
interface PageProps {
|
|
params: Promise<{ account: string }>;
|
|
}
|
|
|
|
export default async function VerbandPage({ params }: PageProps) {
|
|
const { account } = await params;
|
|
const client = getSupabaseServerClient();
|
|
|
|
const { data: acct } = await client
|
|
.from('accounts')
|
|
.select('id')
|
|
.eq('slug', account)
|
|
.single();
|
|
|
|
if (!acct) return <AccountNotFound />;
|
|
|
|
const api = createVerbandApi(client);
|
|
|
|
let stats = { totalClubs: 0, totalMembers: 0, totalRoles: 0, totalFeeTypes: 0 };
|
|
|
|
try {
|
|
stats = await api.getDashboardStats(acct.id);
|
|
} catch (e) {
|
|
console.error('Failed to load verband dashboard:', e);
|
|
}
|
|
|
|
return (
|
|
<CmsPageShell account={account} title="Verbandsverwaltung">
|
|
<VerbandTabNavigation account={account} activeTab="overview" />
|
|
<VerbandDashboard stats={stats} account={account} />
|
|
</CmsPageShell>
|
|
);
|
|
}
|