Spaces:
Sleeping
Sleeping
| import { Toaster } from "@/components/ui/toaster"; | |
| 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 { AuthProvider, useAuth } from "@/contexts/AuthContext"; | |
| import { MainLayout } from "@/components/layout/MainLayout"; | |
| import { HatcheryLayout } from "@/components/layout/HatcheryLayout"; | |
| import { FarmLayout } from "@/components/layout/FarmLayout"; | |
| import { AuditorLayout } from "@/components/layout/AuditorLayout"; | |
| import Login from "./pages/Login"; | |
| import Dashboard from "./pages/Dashboard"; | |
| import Hatcheries from "./pages/Hatcheries"; | |
| import Farms from "./pages/Farms"; | |
| import Applications from "./pages/Applications"; | |
| import Audits from "./pages/Audits"; | |
| import Certificates from "./pages/Certificates"; | |
| import TAClaims from "./pages/TAClaims"; | |
| import RawMaterials from "./pages/RawMaterials"; | |
| import Processors from "./pages/Processors"; | |
| import Reports from "./pages/Reports"; | |
| import Users from "./pages/Users"; | |
| import Settings from "./pages/Settings"; | |
| import NotFound from "./pages/NotFound"; | |
| import HatcheryDashboard from "./pages/HatcheryDashboard"; | |
| import HatcheryApplications from "./pages/HatcheryApplications"; | |
| import HatcheryApplicationDetail from "./pages/HatcheryApplicationDetail"; | |
| import HatcheryNcResponse from "./pages/HatcheryNcResponse"; | |
| import HatcheryCertificates from "./pages/HatcheryCertificates"; | |
| import NewHatcheryApplication from "./pages/NewHatcheryApplication"; | |
| import FarmerDashboard from "./pages/FarmerDashboard"; | |
| import FarmerApplications from "./pages/FarmerApplications"; | |
| import FarmerApplicationDetail from "./pages/FarmerApplicationDetail"; | |
| import FarmerNcResponse from "./pages/FarmerNcResponse"; | |
| import FarmerCertificates from "./pages/FarmerCertificates"; | |
| import NewFarmApplication from "./pages/NewFarmApplication"; | |
| import AuditorDashboard from "./pages/AuditorDashboard"; | |
| import AuditorAudits from "./pages/AuditorAudits"; | |
| import AuditorAuditDetail from "./pages/AuditorAuditDetail"; | |
| import AuditorTaClaims from "./pages/AuditorTaClaims"; | |
| import NewAuditorTaClaim from "./pages/NewAuditorTaClaim"; | |
| import CcOfficerAuditAssignments from "./pages/CcOfficerAuditAssignments"; | |
| import CcOfficerCertificationDashboard from "./pages/CcOfficerCertificationDashboard"; | |
| import JdApprovalQueue from "./pages/JdApprovalQueue"; | |
| import DirectorApprovalQueue from "./pages/DirectorApprovalQueue"; | |
| import SurveillanceSchedule from "./pages/SurveillanceSchedule"; | |
| import FoiApplications from "./pages/FoiApplications"; | |
| import FoVisits from "./pages/FoVisits"; | |
| const queryClient = new QueryClient(); | |
| function ProtectedRoute({ children }: { children: React.ReactNode }) { | |
| const { isAuthenticated } = useAuth(); | |
| if (!isAuthenticated) { | |
| return <Navigate to="/login" replace />; | |
| } | |
| return <>{children}</>; | |
| } | |
| function AppRoutes() { | |
| const { isAuthenticated, user } = useAuth(); | |
| const defaultAuthenticatedPath = | |
| user?.role === "hatchery_operator" | |
| ? "/hatchery/dashboard" | |
| : user?.role === "farmer" | |
| ? "/farm/dashboard" | |
| : user?.role === "auditor" | |
| ? "/auditor/dashboard" | |
| : user?.role === "cc_officer" | |
| ? "/cc-officer/audits" | |
| : user?.role === "foi" | |
| ? "/foi/applications" | |
| : user?.role === "fo" | |
| ? "/fo/visits" | |
| : user?.role === "director" | |
| ? "/director/approvals" | |
| : user?.role === "jd" | |
| ? "/jd/approvals" | |
| : "/dashboard"; | |
| return ( | |
| <Routes> | |
| <Route | |
| path="/login" | |
| element={isAuthenticated ? <Navigate to={defaultAuthenticatedPath} replace /> : <Login />} | |
| /> | |
| <Route | |
| path="/" | |
| element={<Navigate to={isAuthenticated ? defaultAuthenticatedPath : "/login"} replace />} | |
| /> | |
| <Route element={<ProtectedRoute><HatcheryLayout /></ProtectedRoute>}> | |
| <Route path="/hatchery/dashboard" element={<HatcheryDashboard />} /> | |
| <Route path="/hatchery/applications" element={<HatcheryApplications />} /> | |
| <Route path="/hatchery/applications/new" element={<NewHatcheryApplication />} /> | |
| <Route path="/hatchery/applications/:id" element={<HatcheryApplicationDetail />} /> | |
| <Route path="/hatchery/applications/:id/nc-response" element={<HatcheryNcResponse />} /> | |
| <Route path="/hatchery/certificates" element={<HatcheryCertificates />} /> | |
| </Route> | |
| <Route element={<ProtectedRoute><FarmLayout /></ProtectedRoute>}> | |
| <Route path="/farm/dashboard" element={<FarmerDashboard />} /> | |
| <Route path="/farm/applications" element={<FarmerApplications />} /> | |
| <Route path="/farm/applications/new" element={<NewFarmApplication />} /> | |
| <Route path="/farm/applications/:id" element={<FarmerApplicationDetail />} /> | |
| <Route path="/farm/applications/:id/nc-response" element={<FarmerNcResponse />} /> | |
| <Route path="/farm/certificates" element={<FarmerCertificates />} /> | |
| </Route> | |
| <Route element={<ProtectedRoute><AuditorLayout /></ProtectedRoute>}> | |
| <Route path="/auditor/dashboard" element={<AuditorDashboard />} /> | |
| <Route path="/auditor/audits" element={<AuditorAudits />} /> | |
| <Route path="/auditor/audits/:id" element={<AuditorAuditDetail />} /> | |
| <Route path="/auditor/ta-claims" element={<AuditorTaClaims />} /> | |
| <Route path="/auditor/ta-claims/new" element={<NewAuditorTaClaim />} /> | |
| </Route> | |
| <Route element={<ProtectedRoute><MainLayout /></ProtectedRoute>}> | |
| <Route path="/dashboard" element={<Dashboard />} /> | |
| <Route path="/hatcheries" element={<Hatcheries />} /> | |
| <Route path="/farms" element={<Farms />} /> | |
| <Route path="/applications" element={<Applications />} /> | |
| <Route path="/audits" element={<Audits />} /> | |
| <Route path="/cc-officer/audits" element={<CcOfficerAuditAssignments />} /> | |
| <Route path="/cc-officer/certification" element={<CcOfficerCertificationDashboard />} /> | |
| <Route path="/foi/applications" element={<FoiApplications />} /> | |
| <Route path="/fo/visits" element={<FoVisits />} /> | |
| <Route path="/jd/approvals" element={<JdApprovalQueue />} /> | |
| <Route path="/director/approvals" element={<DirectorApprovalQueue />} /> | |
| <Route path="/surveillance-schedule" element={<SurveillanceSchedule />} /> | |
| <Route path="/certificates" element={<Certificates />} /> | |
| <Route path="/ta-claims" element={<TAClaims />} /> | |
| <Route path="/raw-materials" element={<RawMaterials />} /> | |
| <Route path="/processors" element={<Processors />} /> | |
| <Route path="/reports" element={<Reports />} /> | |
| <Route path="/users" element={<Users />} /> | |
| <Route path="/settings" element={<Settings />} /> | |
| </Route> | |
| <Route path="*" element={<NotFound />} /> | |
| </Routes> | |
| ); | |
| } | |
| const App = () => ( | |
| <QueryClientProvider client={queryClient}> | |
| <AuthProvider> | |
| <TooltipProvider> | |
| <Toaster /> | |
| <Sonner /> | |
| <BrowserRouter> | |
| <AppRoutes /> | |
| </BrowserRouter> | |
| </TooltipProvider> | |
| </AuthProvider> | |
| </QueryClientProvider> | |
| ); | |
| export default App; | |