Files
gridpilot.gg/apps/website/app/leagues/[id]/layout.tsx
2026-01-14 10:51:05 +01:00

68 lines
2.1 KiB
TypeScript

import { notFound } from 'next/navigation';
import { LeagueDetailPageQuery } from '@/lib/page-queries/page-queries/LeagueDetailPageQuery';
import { LeagueDetailTemplate } from '@/templates/LeagueDetailTemplate';
export default async function LeagueLayout({
children,
params,
}: {
children: React.ReactNode;
params: { id: string };
}) {
const leagueId = params.id;
// Execute PageQuery to get league data
const result = await LeagueDetailPageQuery.execute(leagueId);
if (result.isErr()) {
const error = result.getError();
if (error === 'notFound' || error === 'redirect') {
notFound();
}
// Return error state
return (
<LeagueDetailTemplate
leagueId={leagueId}
leagueName="Error"
leagueDescription="Failed to load league"
tabs={[]}
>
<div className="text-center text-gray-400">Failed to load league</div>
</LeagueDetailTemplate>
);
}
const data = result.unwrap();
const league = data.league;
// Define tab configuration
const baseTabs = [
{ label: 'Overview', href: `/leagues/${leagueId}`, exact: true },
{ label: 'Schedule', href: `/leagues/${leagueId}/schedule`, exact: false },
{ label: 'Standings', href: `/leagues/${leagueId}/standings`, exact: false },
{ label: 'Rulebook', href: `/leagues/${leagueId}/rulebook`, exact: false },
];
const adminTabs = [
{ label: 'Schedule Admin', href: `/leagues/${leagueId}/schedule/admin`, exact: false },
{ label: 'Sponsorships', href: `/leagues/${leagueId}/sponsorships`, exact: false },
{ label: 'Stewarding', href: `/leagues/${leagueId}/stewarding`, exact: false },
{ label: 'Wallet', href: `/leagues/${leagueId}/wallet`, exact: false },
{ label: 'Settings', href: `/leagues/${leagueId}/settings`, exact: false },
];
// TODO: Admin check needs to be implemented properly
// For now, show admin tabs if user is logged in
const tabs = [...baseTabs, ...adminTabs];
return (
<LeagueDetailTemplate
leagueId={leagueId}
leagueName={league.name}
leagueDescription={league.description}
tabs={tabs}
>
{children}
</LeagueDetailTemplate>
);
}