// src/App.tsx
import React from 'react';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { AuthProvider, useAuth } from './contexts/AuthContext';
import { NotificationProvider } from './contexts/NotificationContext';
import NotificationContainer from './components/Notification/NotificationContainer';
import Layout from './components/Layout/Layout';
import Login from './pages/Auth/Login';
import Dashboard from './pages/Dashboard/Dashboard';
import ShiftPlanList from './pages/ShiftPlans/ShiftPlanList';
import ShiftPlanCreate from './pages/ShiftPlans/ShiftPlanCreate';
import ShiftPlanEdit from './pages/ShiftPlans/ShiftPlanEdit';
import ShiftPlanView from './pages/ShiftPlans/ShiftPlanView';
import EmployeeManagement from './pages/Employees/EmployeeManagement';
import Settings from './pages/Settings/Settings';
import Help from './pages/Help/Help';
import Setup from './pages/Setup/Setup';
// Free Footer Link Pages (always available)
import FAQ from './components/Layout/FooterLinks/FAQ/FAQ';
import About from './components/Layout/FooterLinks/About/About';
import Features from './components/Layout/FooterLinks/Features/Features';
import { CommunityContact, CommunityLegalPage } from './components/Layout/FooterLinks/CommunityLinks/communityLinks';
// Vite environment variables (use import.meta.env instead of process.env)
const ENABLE_PRO = import.meta.env.ENABLE_PRO === 'true';
// Conditional Premium Components
let PremiumContact: React.FC = CommunityContact;
let PremiumPrivacy: React.FC = () => ;
let PremiumImprint: React.FC = () => ;
let PremiumTerms: React.FC = () => ;
// Load premium components only when ENABLE_PRO is true
if (ENABLE_PRO) {
try {
// Use require with type assertions to avoid dynamic import issues
const premiumModule = require('@premium-frontend/components/FooterLinks');
if (premiumModule.Contact) PremiumContact = premiumModule.Contact;
if (premiumModule.Privacy) PremiumPrivacy = premiumModule.Privacy;
if (premiumModule.Imprint) PremiumImprint = premiumModule.Imprint;
if (premiumModule.Terms) PremiumTerms = premiumModule.Terms;
console.log('✅ Premium components loaded successfully');
} catch (error) {
console.warn('⚠️ Premium components not available, using community fallbacks:', error);
}
}
// Protected Route Component
const ProtectedRoute: React.FC<{ children: React.ReactNode; roles?: string[] }> = ({
children,
roles = ['admin', 'maintenance', 'user']
}) => {
const { user, loading, hasRole } = useAuth();
if (loading) {
return (
);
}
if (!user) {
return ;
}
if (!hasRole(roles)) {
return (
Zugriff verweigert
Sie haben keine Berechtigung für diese Seite.
);
}
return {children};
};
// Public Route Component (without Layout for footer pages)
const PublicRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { user, loading } = useAuth();
if (loading) {
return (
);
}
return user ? {children} : <>{children}>;
};
// Main App Content
const AppContent: React.FC = () => {
const { loading, needsSetup, user } = useAuth();
console.log('🏠 AppContent rendering - loading:', loading, 'needsSetup:', needsSetup, 'user:', user);
console.log('🎯 Premium features enabled:', ENABLE_PRO);
// Während des Ladens
if (loading) {
return (
);
}
// Setup benötigt
if (needsSetup) {
console.log('🔧 Showing setup page');
return ;
}
// Kein User eingeloggt
if (!user) {
console.log('🔐 Showing login page');
return ;
}
// User eingeloggt - Geschützte Routen
console.log('✅ Showing protected routes for user:', user.email);
return (
{/* Protected Routes (require login) */}
} />
} />
} />
} />
} />
} />
} />
} />
{/* Public Footer Link Pages (always available) */}
} />
} />
} />
{/* PREMIUM Footer Link Pages (conditionally available) */}
} />
} />
} />
} />
{/* Auth Routes */}
} />
{/* Catch-all Route */}
} />
);
};
function App() {
return (
);
}
export default App;