import React from 'react'; import { createBrowserRouter, Outlet, Navigate, useLocation } from 'react-router-dom'; import { useAuth } from './auth/context'; import { ADMIN_BASE_PATH, ADMIN_DEFAULT_AFTER_LOGIN_PATH, ADMIN_EVENTS_PATH, ADMIN_LOGIN_START_PATH, ADMIN_PUBLIC_LANDING_PATH, } from './constants'; const LoginPage = React.lazy(() => import('./pages/LoginPage')); const DashboardPage = React.lazy(() => import('./pages/DashboardPage')); const EventsPage = React.lazy(() => import('./pages/EventsPage')); const SettingsPage = React.lazy(() => import('./pages/SettingsPage')); const EventFormPage = React.lazy(() => import('./pages/EventFormPage')); const EventPhotosPage = React.lazy(() => import('./pages/EventPhotosPage')); const EventDetailPage = React.lazy(() => import('./pages/EventDetailPage')); const EventMembersPage = React.lazy(() => import('./pages/EventMembersPage')); const EventTasksPage = React.lazy(() => import('./pages/EventTasksPage')); const EventToolkitPage = React.lazy(() => import('./pages/EventToolkitPage')); const EventInvitesPage = React.lazy(() => import('./pages/EventInvitesPage')); const EventPhotoboothPage = React.lazy(() => import('./pages/EventPhotoboothPage')); const EngagementPage = React.lazy(() => import('./pages/EngagementPage')); const BillingPage = React.lazy(() => import('./pages/BillingPage')); const TasksPage = React.lazy(() => import('./pages/TasksPage')); const TaskCollectionsPage = React.lazy(() => import('./pages/TaskCollectionsPage')); const EmotionsPage = React.lazy(() => import('./pages/EmotionsPage')); const FaqPage = React.lazy(() => import('./pages/FaqPage')); const AuthCallbackPage = React.lazy(() => import('./pages/AuthCallbackPage')); const WelcomeTeaserPage = React.lazy(() => import('./pages/WelcomeTeaserPage')); const LoginStartPage = React.lazy(() => import('./pages/LoginStartPage')); const ProfilePage = React.lazy(() => import('./pages/ProfilePage')); const LogoutPage = React.lazy(() => import('./pages/LogoutPage')); const LiveRedirectPage = React.lazy(() => import('./pages/LiveRedirectPage')); function RequireAuth() { const { status } = useAuth(); const location = useLocation(); if (status === 'loading') { return (
Bitte warten ...
); } if (status === 'unauthenticated') { return ; } return ; } function LandingGate() { const { status, user } = useAuth(); if (status === 'loading') { return (
Bitte warten ...
); } if (status === 'authenticated') { const target = user?.role === 'member' ? ADMIN_EVENTS_PATH : ADMIN_DEFAULT_AFTER_LOGIN_PATH; return ; } return ; } function RequireAdminAccess({ children }: { children: React.ReactNode }) { const { user } = useAuth(); if (user?.role === 'member') { return ; } return <>{children}; } export const router = createBrowserRouter([ { path: ADMIN_BASE_PATH, element: , children: [ { index: true, element: }, { path: 'login', element: }, { path: 'start', element: }, { path: 'logout', element: }, { path: 'auth/callback', element: }, { element: , children: [ { path: 'dashboard', element: }, { path: 'live', element: }, { path: 'events', element: }, { path: 'events/new', element: }, { path: 'events/:slug', element: }, { path: 'events/:slug/recap', element: }, { path: 'events/:slug/edit', element: }, { path: 'events/:slug/photos', element: }, { path: 'events/:slug/members', element: }, { path: 'events/:slug/tasks', element: }, { path: 'events/:slug/invites', element: }, { path: 'events/:slug/photobooth', element: }, { path: 'events/:slug/toolkit', element: }, { path: 'engagement', element: }, { path: 'tasks', element: }, { path: 'task-collections', element: }, { path: 'emotions', element: }, { path: 'billing', element: }, { path: 'settings', element: }, { path: 'faq', element: }, { path: 'settings/profile', element: }, ], }, ], }, { path: '*', element: , }, ]);