import "./global.css";
import { Toaster } from "@/components/ui/toaster";
import { createRoot } from "react-dom/client";
import { Toaster as Sonner } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import Index from "./pages/Index";
import Login from "./pages/Login";
import { Register } from "./pages/Register";
import Admin from "./pages/Admin";
import ManagerDashboard from "./pages/ManagerDashboard";
import ClientDetail from "./pages/ClientDetail";
import ClientActivities from "./pages/ClientActivities";
import NotFound from "./pages/NotFound";
import { isAuthenticated, getCurrentUser } from "@/lib/auth";
const queryClient = new QueryClient();
// Protected route component
function ProtectedRoute({ children }: { children: React.ReactNode }) {
if (!isAuthenticated()) {
return ;
}
return <>{children}>;
}
// Admin protected route component
function AdminProtectedRoute({ children }: { children: React.ReactNode }) {
const user = getCurrentUser();
if (!user || user.role !== "admin") {
return ;
}
return <>{children}>;
}
// Manager protected route component
function ManagerProtectedRoute({ children }: { children: React.ReactNode }) {
const user = getCurrentUser();
if (!user || user.role !== "gestor") {
return ;
}
return <>{children}>;
}
const App = () => (
} />
} />
}
/>
}
/>
}
/>
}
/>
}
/>
{/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
} />
);
createRoot(document.getElementById("root")!).render();