'use client'; import { ReadonlyLeagueInfo } from '@/components/leagues/ReadonlyLeagueInfo'; import LeagueOwnershipTransfer from '@/components/leagues/LeagueOwnershipTransfer'; import Card from '@/components/ui/Card'; import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId'; import { LeagueRoleUtility } from '@/lib/utilities/LeagueRoleUtility'; import { useServices } from '@/lib/services/ServiceProvider'; import { LeagueSettingsViewModel } from '@/lib/view-models/LeagueSettingsViewModel'; import { AlertTriangle, Settings } from 'lucide-react'; import { useParams, useRouter } from 'next/navigation'; // Shared state components import { useDataFetching } from '@/components/shared/hooks/useDataFetching'; import { StateContainer } from '@/components/shared/state/StateContainer'; import { LoadingWrapper } from '@/components/shared/state/LoadingWrapper'; export default function LeagueSettingsPage() { const params = useParams(); const leagueId = params.id as string; const currentDriverId = useEffectiveDriverId(); const { leagueMembershipService, leagueSettingsService } = useServices(); const router = useRouter(); // Check admin status const { data: isAdmin, isLoading: adminLoading } = useDataFetching({ queryKey: ['leagueMembership', leagueId, currentDriverId], queryFn: async () => { const membership = leagueMembershipService.getMembership(leagueId, currentDriverId); return membership ? LeagueRoleUtility.isLeagueAdminOrHigherRole(membership.role) : false; }, }); // Load settings (only if admin) const { data: settings, isLoading: settingsLoading, error, retry } = useDataFetching({ queryKey: ['leagueSettings', leagueId], queryFn: () => leagueSettingsService.getLeagueSettings(leagueId), enabled: !!isAdmin, }); const handleTransferOwnership = async (newOwnerId: string) => { try { await leagueSettingsService.transferOwnership(leagueId, currentDriverId, newOwnerId); router.refresh(); } catch (err) { throw err; // Let the component handle the error } }; // Show loading for admin check if (adminLoading) { return ; } // Show access denied if not admin if (!isAdmin) { return ( Admin Access Required Only league admins can access settings. ); } return ( {(settingsData) => ( {/* Header */} League Settings Manage your league configuration {/* READONLY INFORMATION SECTION - Compact */} )} ); }
Only league admins can access settings.
Manage your league configuration