website refactor
This commit is contained in:
@@ -2,6 +2,7 @@ import { notFound } from 'next/navigation';
|
||||
import { LeagueDetailPageQuery } from '@/lib/page-queries/LeagueDetailPageQuery';
|
||||
import { LeagueDetailTemplate } from '@/templates/LeagueDetailTemplate';
|
||||
import { LeagueDetailViewDataBuilder } from '@/lib/builders/view-data/LeagueDetailViewDataBuilder';
|
||||
import { DriverService } from '@/lib/services/drivers/DriverService';
|
||||
import { Text } from '@/ui/Text';
|
||||
|
||||
export default async function LeagueLayout({
|
||||
@@ -14,7 +15,10 @@ export default async function LeagueLayout({
|
||||
const { id: leagueId } = await params;
|
||||
|
||||
// Execute PageQuery to get league data
|
||||
const result = await LeagueDetailPageQuery.execute(leagueId);
|
||||
const [result, currentDriver] = await Promise.all([
|
||||
LeagueDetailPageQuery.execute(leagueId),
|
||||
new DriverService().getCurrentDriver(),
|
||||
]);
|
||||
|
||||
if (result.isErr()) {
|
||||
const error = result.getError();
|
||||
@@ -34,6 +38,7 @@ export default async function LeagueLayout({
|
||||
ownerSummary: null,
|
||||
adminSummaries: [],
|
||||
stewardSummaries: [],
|
||||
memberSummaries: [],
|
||||
sponsorInsights: null
|
||||
}}
|
||||
tabs={[]}
|
||||
@@ -47,11 +52,11 @@ export default async function LeagueLayout({
|
||||
|
||||
const viewData = LeagueDetailViewDataBuilder.build({
|
||||
league: data.league,
|
||||
owner: null,
|
||||
scoringConfig: null,
|
||||
memberships: { members: [] },
|
||||
races: [],
|
||||
sponsors: [],
|
||||
owner: data.owner,
|
||||
scoringConfig: data.scoringConfig,
|
||||
memberships: data.memberships,
|
||||
races: data.races,
|
||||
sponsors: data.sponsors,
|
||||
});
|
||||
|
||||
// Define tab configuration
|
||||
@@ -59,19 +64,23 @@ export default async function LeagueLayout({
|
||||
{ label: 'Overview', href: `/leagues/${leagueId}`, exact: true },
|
||||
{ label: 'Schedule', href: `/leagues/${leagueId}/schedule`, exact: false },
|
||||
{ label: 'Standings', href: `/leagues/${leagueId}/standings`, exact: false },
|
||||
{ label: 'Roster', href: `/leagues/${leagueId}/roster`, exact: false },
|
||||
{ label: 'Rulebook', href: `/leagues/${leagueId}/rulebook`, exact: false },
|
||||
];
|
||||
|
||||
const adminTabs = [
|
||||
// Check if user is admin or owner
|
||||
const isOwner = currentDriver && data.league.ownerId === currentDriver.id;
|
||||
const isAdmin = currentDriver && data.memberships.members?.some(m => m.driverId === currentDriver.id && m.role === 'admin');
|
||||
const hasAdminAccess = isOwner || isAdmin;
|
||||
|
||||
const adminTabs = hasAdminAccess ? [
|
||||
{ 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 (
|
||||
|
||||
Reference in New Issue
Block a user