import React from 'react';
import { Routes, Route, Navigate, useLocation } from 'react-router-dom';
import { useAuth } from './context/AuthContext';
import Layout from './components/Layout';
import Login from './pages/Login';
import Landing from './pages/Landing';
import Dashboard from './pages/Dashboard';
import Maps from './pages/Maps';
import AdminSchedule from './pages/AdminSchedule';
import CustomerProfile from './pages/CustomerProfile';
import ErrorBoundary from './components/ErrorBoundary';
import { Toaster } from 'sonner';
import NotFound from './pages/NotFound';
// Protected Route Component
const ProtectedRoute = ({ children, allowedRoles }) => {
const { user, isAuthenticated } = useAuth();
const location = useLocation();
if (!isAuthenticated) {
return ;
}
if (allowedRoles && !allowedRoles.includes(user.role)) {
// If user is employee but wrong role, go to their default dashboard
// For now, just redirect to home or show unauthorized
return ;
}
return children;
};
function App() {
return (
}>
{/* Public Routes */}
} />
} />
{/* Protected Field Agent Routes */}
} />
}
/>
}
/>
{/* Protected Admin Routes */}
}
/>
{/* Catch all */}
} />
);
}
export default App;