From d85d5ffdc0d2e825dacca502f88db7255ec2c6da Mon Sep 17 00:00:00 2001 From: lemintare Date: Sun, 19 Jul 2026 01:07:48 +0300 Subject: [PATCH] Refactor navigation item handling in App component to conditionally include admin link based on user role, improving access control and code clarity. --- frontend/src/App.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index caad2c9..e81ef92 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -46,13 +46,12 @@ const routeTree = rootRoute.addChildren([loginRoute, protectedRoute.addChildren( const router = createRouter({ routeTree, context: { session: null } }) declare module '@tanstack/react-router' { interface Register { router: typeof router } } -const navItems = [ +const mainNavItems = [ { to: '/events', label: 'Events', icon: CalendarDays }, ...(demoMode ? [ { to: '/series/$seriesId' as const, params: { seriesId: 'series-1' }, label: 'Live', icon: Radio }, { to: '/bracket/$eventId' as const, params: { eventId: 'bracket-1' }, label: 'Bracket', icon: Trophy }, ] : []), - { to: '/admin', label: 'Admin', icon: Shield }, ] function Brand() { @@ -70,6 +69,9 @@ function AppShell() { }, }) const initials = session.data?.account.displayName.slice(0, 2).toUpperCase() ?? 'MM' + const navItems = session.data?.account.role === 'admin' + ? [...mainNavItems, { to: '/admin' as const, label: 'Admin', icon: Shield }] + : mainNavItems return
@@ -189,7 +191,7 @@ function AdminPage() { useEffect(() => { if (!selectedId && events.data?.[0]) setSelectedId(events.data[0].id) }, [events.data, selectedId]) if (events.isLoading) return if (events.isError) return void events.refetch()} /> - return
} />
{(['events', 'participants', 'balance'] as AdminTab[]).map((item) => )}
{tab === 'events' && { setCreateMode(false); setSelectedId(event.id) }} />}{tab === 'participants' && selected && }{tab === 'balance' && selected && }
+ return
{events.data && events.data.length > 0 && }} />
{(['events', 'participants', 'balance'] as AdminTab[]).map((item) => )}
{tab === 'events' && { setCreateMode(false); setSelectedId(event.id) }} />}{tab === 'participants' && selected && }{tab === 'balance' && selected && }
} function toLocalInput(value: string) {