Presupuestador_web/client/src/Routes.tsx

148 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-06-11 16:48:09 +00:00
import { Outlet, RouterProvider, createBrowserRouter } from "react-router-dom";
2024-06-14 12:07:20 +00:00
import {
DealerLayout,
DealersList,
2024-08-12 18:22:34 +00:00
ErrorPage,
2024-06-14 12:07:20 +00:00
LoginPage,
LogoutPage,
2024-06-29 19:39:25 +00:00
QuoteCreate,
2024-07-01 17:12:15 +00:00
QuoteEdit,
2024-06-14 12:07:20 +00:00
SettingsEditor,
SettingsLayout,
StartPage,
} from "./app";
2024-06-11 16:48:09 +00:00
import { CatalogLayout, CatalogList } from "./app/catalog";
2024-07-03 18:05:26 +00:00
import { DashboardPage } from "./app/dashboard";
2024-06-29 19:39:25 +00:00
import { QuotesLayout } from "./app/quotes/layout";
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
},
];
2024-08-12 18:22:34 +00:00
const routesForErrors = [
{
path: "*",
Component: ErrorPage,
},
];
2024-06-06 11:05:54 +00:00
// Define routes accessible only to authenticated users
const routesForAuthenticatedOnly = [
2024-07-03 18:05:26 +00:00
{
path: "/home",
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-29 19:39:25 +00:00
<QuotesLayout>
<Outlet />
</QuotesLayout>
2024-06-09 20:22:22 +00:00
</ProtectedRoute>
),
2024-06-29 19:39:25 +00:00
children: [
{
index: true,
element: <QuotesList />,
},
{
path: "add",
element: <QuoteCreate />,
},
2024-07-01 17:12:15 +00:00
{
2024-07-09 16:21:12 +00:00
path: "edit/:id",
2024-07-01 17:12:15 +00:00
element: <QuoteEdit />,
},
2024-06-29 19:39:25 +00:00
],
2024-06-09 20:22:22 +00:00
},
{
path: "/settings",
element: (
<ProtectedRoute>
2024-06-14 12:07:20 +00:00
<SettingsLayout>
<Outlet />
</SettingsLayout>
2024-06-06 21:07:40 +00:00
</ProtectedRoute>
),
2024-06-14 12:07:20 +00:00
children: [
{
index: true,
element: <SettingsEditor />,
},
],
2024-06-06 21:07:40 +00:00
},
2024-06-06 11:05:54 +00:00
{
2024-06-09 20:22:22 +00:00
path: "/logout",
2024-07-09 16:21:12 +00:00
element: <LogoutPage />,
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
2024-06-29 19:39:25 +00:00
const router = createBrowserRouter(
2024-08-12 18:22:34 +00:00
[
...routesForPublic,
...routesForAuthenticatedOnly,
...routesForNotAuthenticatedOnly,
...routesForErrors,
],
2024-06-29 19:39:25 +00:00
{
//basename: "/app",
}
);
2024-06-06 11:05:54 +00:00
// Provide the router configuration using RouterProvider
return <RouterProvider router={router} />;
};