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'; import RouteErrorElement from '@/components/RouteErrorElement'; 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 EventRecapPage = React.lazy(() => import('./pages/EventRecapPage')); 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 EventBrandingPage = React.lazy(() => import('./pages/EventBrandingPage')); const MobileEventsPage = React.lazy(() => import('./mobile/EventsPage')); const MobileEventDetailPage = React.lazy(() => import('./mobile/EventDetailPage')); const MobileBrandingPage = React.lazy(() => import('./mobile/BrandingPage')); const MobileEventFormPage = React.lazy(() => import('./mobile/EventFormPage')); const MobileQrPrintPage = React.lazy(() => import('./mobile/QrPrintPage')); const MobileEventPhotosPage = React.lazy(() => import('./mobile/EventPhotosPage')); const MobileEventMembersPage = React.lazy(() => import('./mobile/EventMembersPage')); const MobileEventTasksPage = React.lazy(() => import('./mobile/EventTasksPage')); const MobileNotificationsPage = React.lazy(() => import('./mobile/NotificationsPage')); const MobileProfilePage = React.lazy(() => import('./mobile/ProfilePage')); const MobileBillingPage = React.lazy(() => import('./mobile/BillingPage')); const MobileSettingsPage = React.lazy(() => import('./mobile/SettingsPage')); const MobileLoginPage = React.lazy(() => import('./mobile/LoginPage')); const MobileDashboardPage = React.lazy(() => import('./mobile/DashboardPage')); const MobileTasksTabPage = React.lazy(() => import('./mobile/TasksTabPage')); const MobileUploadsTabPage = React.lazy(() => import('./mobile/UploadsTabPage')); 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: , errorElement: , children: [ { index: true, element: }, { path: 'login', element: }, { path: 'mobile/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/branding', element: }, { path: 'events/:slug/photobooth', element: }, { path: 'events/:slug/toolkit', element: }, { path: 'mobile/events', element: }, { path: 'mobile/events/:slug', element: }, { path: 'mobile/events/:slug/branding', element: }, { path: 'mobile/events/new', element: }, { path: 'mobile/events/:slug/edit', element: }, { path: 'mobile/events/:slug/qr', element: }, { path: 'mobile/events/:slug/photos', element: }, { path: 'mobile/events/:slug/members', element: }, { path: 'mobile/events/:slug/tasks', element: }, { path: 'mobile/notifications', element: }, { path: 'mobile/profile', element: }, { path: 'mobile/billing', element: }, { path: 'mobile/settings', element: }, { path: 'mobile/dashboard', element: }, { path: 'mobile/tasks', element: }, { path: 'mobile/uploads', 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: , errorElement: , }, ]);