import { Routes, Route, Navigate } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { useAuth } from './context/AuthContext'; import { gdprApi } from './services/api'; import { Shield } from 'lucide-react'; import ScrollToTop from './components/ScrollToTop'; import Layout from './components/layout/Layout'; import Login from './pages/Login'; import Dashboard from './pages/Dashboard'; import CustomerList from './pages/customers/CustomerList'; import CustomerDetail from './pages/customers/CustomerDetail'; import CustomerForm from './pages/customers/CustomerForm'; import ContractList from './pages/contracts/ContractList'; import ContractDetail from './pages/contracts/ContractDetail'; import ContractForm from './pages/contracts/ContractForm'; import ContractCockpit from './pages/contracts/ContractCockpit'; import TaskList from './pages/tasks/TaskList'; import PlatformList from './pages/platforms/PlatformList'; import CancellationPeriodList from './pages/settings/CancellationPeriodList'; import ContractDurationList from './pages/settings/ContractDurationList'; import ProviderList from './pages/settings/ProviderList'; import ContractCategoryList from './pages/settings/ContractCategoryList'; import ViewSettings from './pages/settings/ViewSettings'; import PortalSettings from './pages/settings/PortalSettings'; import DeadlineSettings from './pages/settings/DeadlineSettings'; import EmailProviders from './pages/settings/EmailProviders'; import DatabaseBackup from './pages/settings/DatabaseBackup'; import AuditLogs from './pages/settings/AuditLogs'; import EmailLogPage from './pages/settings/EmailLogs'; import GDPRDashboard from './pages/settings/GDPRDashboard'; import UserList from './pages/users/UserList'; import Settings from './pages/Settings'; import DatabaseStructure from './pages/developer/DatabaseStructure'; import ConsentPage from './pages/public/ConsentPage'; import PrivacyPolicyEditor from './pages/settings/PrivacyPolicyEditor'; import PortalPrivacy from './pages/portal/PortalPrivacy'; import AuthorizationTemplateEditor from './pages/settings/AuthorizationTemplateEditor'; import PortalAuthorizations from './pages/portal/PortalAuthorizations'; import PortalProfile from './pages/portal/PortalProfile'; import PortalMeters from './pages/portal/PortalMeters'; function ProtectedRoute({ children }: { children: React.ReactNode }) { const { isAuthenticated, isLoading } = useAuth(); if (isLoading) { return (
Laden...
); } if (!isAuthenticated) { return ; } return <>{children}; } function PortalConsentGate({ children }: { children: React.ReactNode }) { const { isCustomerPortal } = useAuth(); // Nicht-Portal-Benutzer werden nicht eingeschränkt if (!isCustomerPortal) return <>{children}; // Portal-Kunden: Consent-Check läuft über Layout ConsentBanner + hier return {children}; } function PortalConsentCheck({ children }: { children: React.ReactNode }) { const { data, isLoading, isError } = useQuery({ queryKey: ['my-consent-status'], queryFn: () => gdprApi.getMyConsentStatus(), staleTime: 30_000, retry: 1, }); if (isLoading) return
Laden...
; // Bei Fehler oder fehlender Einwilligung: sperren const hasConsent = (!isError && data?.data?.hasConsent) ?? false; if (!hasConsent) { return (

Datenschutz-Einwilligung erforderlich

Dieser Bereich ist erst verfügbar, wenn Sie unserer Datenschutzerklärung zugestimmt haben.

Jetzt zur Datenschutzerklärung
); } return <>{children}; } function DeveloperRoute({ children }: { children: React.ReactNode }) { const { hasPermission, developerMode } = useAuth(); // Require both developer permission AND developer mode enabled if (!hasPermission('developer:access') || !developerMode) { return ; } return <>{children}; } function App() { const { isAuthenticated, isLoading } = useAuth(); if (isLoading) { return (
Laden...
); } return ( <> {/* Öffentliche Routes (OHNE Authentifizierung) */} } /> : } /> } > } /> {/* Customers */} } /> } /> } /> } /> {/* Contracts */} } /> } /> } /> } /> } /> {/* Tasks / Support-Anfragen */} } /> {/* Portal: Meine Daten, Datenschutz, Vollmachten */} } /> } /> } /> } /> {/* Settings */} } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> } /> {/* Redirect old users route */} } /> {/* Redirect old platforms route */} } /> {/* Developer */} } /> } /> ); } export default App;