import React, { Suspense, lazy } from 'react'; import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom'; import { QueryClientProvider } from '@tanstack/react-query'; import { queryClient } from './lib/queryClient'; import { AuthProvider, ProtectedRoute, TenantAdminProtectedRoute } from './auth/AuthProvider'; import { ClaimProtectedRoute, TenantManagementProtectedRoute, useRbac } from './auth/rbac'; import { ToastProvider } from './components/ui/Toast'; import { AppLayout } from './components/layout/AppLayout'; const LandingPage = lazy(() => import('./pages/LandingPage').then(m => ({ default: m.LandingPage }))); const ExecutiveDashboard = lazy(() => import('./pages/ExecutiveDashboard').then(m => ({ default: m.ExecutiveDashboard }))); const GovernancePage = lazy(() => import('./pages/GovernancePage').then(m => ({ default: m.GovernancePage }))); const ProjectsPage = lazy(() => import('./pages/ProjectsPage').then(m => ({ default: m.ProjectsPage }))); const BeneficiariesPage = lazy(() => import('./pages/BeneficiariesPage').then(m => ({ default: m.BeneficiariesPage }))); const ChangeManagementPage = lazy(() => import('./pages/ChangeManagementPage').then(m => ({ default: m.ChangeManagementPage }))); const SiteVisitsPage = lazy(() => import('./pages/SiteVisitsPage').then(m => ({ default: m.SiteVisitsPage }))); const GrantsPage = lazy(() => import('./pages/GrantsPage').then(m => ({ default: m.GrantsPage }))); const MonitoringPage = lazy(() => import('./pages/MonitoringPage').then(m => ({ default: m.MonitoringPage }))); const TenantManagementPage = lazy(() => import('./pages/TenantManagementPage').then(m => ({ default: m.TenantManagementPage }))); const SettingsPage = lazy(() => import('./pages/SettingsPage').then(m => ({ default: m.SettingsPage }))); const RouteLoading = () => (
Loading module...
); const DefaultRouteRedirect = () => { const { canView } = useRbac(); if (canView('dashboard')) return ; if (canView('projects_milestones')) return ; if (canView('grant_financials')) return ; if (canView('evidence_risks')) return ; if (canView('governance')) return ; if (canView('beneficiaries')) return ; if (canView('settings_users') || canView('settings_invites')) return ; return ; }; export default function App() { return ( }> {/* Public OIDC Login / Landing Page */} } /> } /> {/* Protected Backoffice Application Shell */} } > } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Fallback Redirect */} } /> ); }