2024-06-11 16:48:09 +00:00
|
|
|
import { Outlet, RouterProvider, createBrowserRouter } from "react-router-dom";
|
|
|
|
|
import { DealerLayout, DealersList, LoginPage, LogoutPage, SettingsPage, StartPage } from "./app";
|
|
|
|
|
import { CatalogLayout, CatalogList } from "./app/catalog";
|
2024-06-09 20:04:46 +00:00
|
|
|
import { DashboardPage } from "./app/dashboard";
|
2024-06-09 20:22:22 +00:00
|
|
|
import { QuotesList } from "./app/quotes/list";
|
2024-06-06 11:05:54 +00:00
|
|
|
import { ProtectedRoute } from "./components";
|
|
|
|
|
|
|
|
|
|
export const Routes = () => {
|
|
|
|
|
// Define public routes accessible to all users
|
|
|
|
|
const routesForPublic = [
|
|
|
|
|
{
|
2024-06-09 20:04:46 +00:00
|
|
|
path: "/",
|
|
|
|
|
Component: StartPage,
|
2024-06-06 11:05:54 +00:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Define routes accessible only to authenticated users
|
|
|
|
|
const routesForAuthenticatedOnly = [
|
2024-06-09 20:04:46 +00:00
|
|
|
{
|
|
|
|
|
path: "/home",
|
2024-06-09 20:22:22 +00:00
|
|
|
element: (
|
|
|
|
|
<ProtectedRoute>
|
|
|
|
|
<DashboardPage />
|
|
|
|
|
</ProtectedRoute>
|
|
|
|
|
),
|
2024-06-09 20:04:46 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/catalog",
|
2024-06-09 20:22:22 +00:00
|
|
|
element: (
|
|
|
|
|
<ProtectedRoute>
|
2024-06-11 16:48:09 +00:00
|
|
|
<CatalogLayout>
|
|
|
|
|
<Outlet />
|
|
|
|
|
</CatalogLayout>
|
2024-06-09 20:22:22 +00:00
|
|
|
</ProtectedRoute>
|
|
|
|
|
),
|
2024-06-11 16:48:09 +00:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
index: true,
|
|
|
|
|
element: <CatalogList />,
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-06-09 20:04:46 +00:00
|
|
|
},
|
2024-06-06 21:07:40 +00:00
|
|
|
{
|
2024-06-09 20:22:22 +00:00
|
|
|
path: "/dealers",
|
2024-06-06 21:07:40 +00:00
|
|
|
element: (
|
|
|
|
|
<ProtectedRoute>
|
2024-06-11 16:48:09 +00:00
|
|
|
<DealerLayout>
|
|
|
|
|
<Outlet />
|
|
|
|
|
</DealerLayout>
|
2024-06-06 21:07:40 +00:00
|
|
|
</ProtectedRoute>
|
|
|
|
|
),
|
2024-06-11 16:48:09 +00:00
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
index: true,
|
|
|
|
|
element: <DealersList />,
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-06-06 21:07:40 +00:00
|
|
|
},
|
|
|
|
|
{
|
2024-06-09 20:22:22 +00:00
|
|
|
path: "/quotes",
|
2024-06-06 21:07:40 +00:00
|
|
|
element: (
|
|
|
|
|
<ProtectedRoute>
|
2024-06-09 20:22:22 +00:00
|
|
|
<QuotesList />
|
|
|
|
|
</ProtectedRoute>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: "/settings",
|
|
|
|
|
element: (
|
|
|
|
|
<ProtectedRoute>
|
|
|
|
|
<SettingsPage />
|
2024-06-06 21:07:40 +00:00
|
|
|
</ProtectedRoute>
|
|
|
|
|
),
|
|
|
|
|
},
|
2024-06-06 11:05:54 +00:00
|
|
|
{
|
2024-06-09 20:22:22 +00:00
|
|
|
path: "/logout",
|
|
|
|
|
element: (
|
|
|
|
|
<ProtectedRoute>
|
|
|
|
|
<LogoutPage />
|
|
|
|
|
</ProtectedRoute>
|
|
|
|
|
),
|
2024-06-06 11:05:54 +00:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Define routes accessible only to non-authenticated users
|
|
|
|
|
const routesForNotAuthenticatedOnly = [
|
|
|
|
|
{
|
|
|
|
|
path: "/login",
|
|
|
|
|
Component: LoginPage,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Combine and conditionally include routes based on authentication status
|
|
|
|
|
const router = createBrowserRouter([
|
|
|
|
|
...routesForPublic,
|
|
|
|
|
...routesForAuthenticatedOnly,
|
2024-06-09 20:04:46 +00:00
|
|
|
...routesForNotAuthenticatedOnly,
|
2024-06-06 11:05:54 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Provide the router configuration using RouterProvider
|
|
|
|
|
return <RouterProvider router={router} />;
|
|
|
|
|
};
|