112 lines
4.1 KiB
TypeScript
112 lines
4.1 KiB
TypeScript
import React from 'react';
|
|
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
|
import Login from './features/auth/Login';
|
|
import ForgotPassword from './features/auth/ForgotPassword';
|
|
import AppLayout from './features/layouts/AppLayout';
|
|
import AdminDashboard from './features/dashboard/AdminDashboard';
|
|
import ClientDashboard from './features/dashboard/ClientDashboard';
|
|
import VendorDashboard from './features/dashboard/VendorDashboard';
|
|
import ProtectedRoute from './features/layouts/ProtectedRoute';
|
|
import { RoleDashboardRedirect } from './features/dashboard/RoleDashboardRedirect';
|
|
import PublicLayout from './features/layouts/PublicLayout';
|
|
import StaffList from './features/workforce/directory/StaffList';
|
|
import EditStaff from './features/workforce/directory/EditStaff';
|
|
import AddStaff from './features/workforce/directory/AddStaff';
|
|
import ClientList from './features/business/clients/ClientList';
|
|
import EditClient from './features/business/clients/EditClient';
|
|
import AddClient from './features/business/clients/AddClient';
|
|
import ServiceRates from './features/business/rates/ServiceRates';
|
|
import OrderList from './features/operations/orders/OrderList';
|
|
import OrderDetail from './features/operations/orders/OrderDetail';
|
|
import ClientOrderList from './features/operations/orders/ClientOrderList';
|
|
import VendorOrderList from './features/operations/orders/VendorOrderList';
|
|
|
|
/**
|
|
* AppRoutes Component
|
|
* Defines the main routing structure of the application.
|
|
* Groups routes by Layout (Public vs App).
|
|
* Implements role-based redirection after login.
|
|
*/
|
|
const AppRoutes: React.FC = () => {
|
|
return (
|
|
<Router>
|
|
<Routes>
|
|
{/* Public Routes */}
|
|
<Route
|
|
path="/login"
|
|
element={
|
|
<PublicLayout>
|
|
<Login />
|
|
</PublicLayout>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/forgot-password"
|
|
element={
|
|
<ForgotPassword />
|
|
}
|
|
/>
|
|
{/* Authenticated Routes */}
|
|
<Route element={<AppLayout />}>
|
|
{/* Dashboard Redirect Logic - redirects to user's correct dashboard based on role */}
|
|
<Route path="/" element={<RoleDashboardRedirect />} />
|
|
|
|
{/* Protected Dashboard Routes */}
|
|
<Route
|
|
path="/dashboard/admin"
|
|
element={
|
|
<ProtectedRoute
|
|
allowedRoles={['admin']}
|
|
redirectTo="/dashboard/admin"
|
|
>
|
|
<AdminDashboard />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/dashboard/client"
|
|
element={
|
|
<ProtectedRoute
|
|
allowedRoles={['client']}
|
|
redirectTo="/dashboard/client"
|
|
>
|
|
<ClientDashboard />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
<Route
|
|
path="/dashboard/vendor"
|
|
element={
|
|
<ProtectedRoute
|
|
allowedRoles={['vendor']}
|
|
redirectTo="/dashboard/vendor"
|
|
>
|
|
<VendorDashboard />
|
|
</ProtectedRoute>
|
|
}
|
|
/>
|
|
{/* Workforce Routes */}
|
|
<Route path="/staff" element={<StaffList />} />
|
|
<Route path="/staff/add" element={<AddStaff />} />
|
|
<Route path="/staff/:id/edit" element={<EditStaff />} />
|
|
{/* Business Routes */}
|
|
<Route path="/clients" element={<ClientList />} />
|
|
<Route path="/clients/:id/edit" element={<EditClient />} />
|
|
<Route path="/clients/add" element={<AddClient />} />
|
|
<Route path="/rates" element={<ServiceRates />} />
|
|
{/* Operations Routes */}
|
|
<Route path="/orders" element={<OrderList />} />
|
|
<Route path="/orders/client" element={<ClientOrderList />} />
|
|
<Route path="/orders/:id" element={<OrderDetail />} />
|
|
<Route path="/orders/vendor" element={<VendorOrderList />} />
|
|
|
|
</Route>
|
|
<Route path="*" element={<Navigate to="/login" replace />} />
|
|
</Routes>
|
|
</Router>
|
|
);
|
|
};
|
|
|
|
|
|
export default AppRoutes;
|