Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor routes to be compliant with V6 #218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions src/main/webapp/src/Paths.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
export const formatPath = (path: Paths, data: any) => {
let url = path as string;

for (const k of Object.keys(data)) {
url = url.replace(":" + k, data[k]);
}

return url;
};

export enum Paths {
base = "/",
notFound = "/not-found",

consultaRuc = "/consulta-numero-documento",
contribuyenteList = "/contribuyentes",
versionList = "/versiones",
contribuyentes = "/contribuyentes",
versiones = "/versiones",

settings = "/settings",
settings_userList = "/settings/users",
settings_users = "/settings/users",
}
96 changes: 36 additions & 60 deletions src/main/webapp/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,58 @@ import { SimplePlaceholder } from "@project-openubl/lib-ui";

import { ProtectedRoute } from "ProtectedRoute";
import { isElasticsearchEnabled, Permission } from "Constants";

import { Paths } from "./Paths";
import { Paths } from "Paths";

const ConsultaRuc = lazy(() => import("./pages/consulta-ruc"));
const Contribuyentes = lazy(() => import("./pages/contribuyentes"));
const Versions = lazy(() => import("./pages/versions"));
const Settings = lazy(() => import("./pages/settings"));
const SettingsUsers = lazy(() => import("./pages/settings/users"));

export const AppRoutes = () => {
// const routes = [
// {
// Component: ConsultaRuc,
// path: Paths.consultaRuc,
// hasAny: [Permission.admin, Permission.search],
// },
// {
// Component: Contribuyentes,
// path: Paths.contribuyenteList,
// hasAny: [Permission.admin, Permission.search],
// },
// {
// Component: Versions,
// path: Paths.versionList,
// hasAny: [Permission.admin, Permission.version_write],
// },
// {
// Component: Settings,
// path: Paths.settings,
// hasAny: [Permission.admin, Permission.user_write],
// },
// ];
const routes = [
{
Component: ConsultaRuc,
path: Paths.consultaRuc,
hasAny: [Permission.admin, Permission.search],
},
{
Component: Contribuyentes,
path: Paths.contribuyentes,
hasAny: [Permission.admin, Permission.search],
},
{
Component: Versions,
path: Paths.versiones,
hasAny: [Permission.admin, Permission.version_write],
},
{
Component: SettingsUsers,
path: Paths.settings_users,
hasAny: [Permission.admin, Permission.user_write],
},
];

return (
<Suspense fallback={<SimplePlaceholder />}>
<Routes>
<Route
path={Paths.consultaRuc}
element={
<ProtectedRoute hasAny={[Permission.admin, Permission.search]}>
<ConsultaRuc />
</ProtectedRoute>
}
/>
<Route
path="/contribuyentes/*"
element={
<ProtectedRoute hasAny={[Permission.admin, Permission.search]}>
<Contribuyentes />
</ProtectedRoute>
}
/>
<Route
path="/versiones/*"
element={
<ProtectedRoute
hasAny={[Permission.admin, Permission.version_write]}
>
<Versions />
</ProtectedRoute>
}
/>
<Route
path="/settings/*"
element={
<ProtectedRoute hasAny={[Permission.admin, Permission.user_write]}>
<Settings />
</ProtectedRoute>
}
/>
{routes.map(({ path, hasAny, Component }, index) => (
<Route
key={index}
path={path}
element={
<ProtectedRoute hasAny={hasAny}>
<Component />
</ProtectedRoute>
}
/>
))}
<Route
path="*"
element={
<Navigate
to={
isElasticsearchEnabled()
? Paths.contribuyenteList
? Paths.contribuyentes
: Paths.consultaRuc
}
/>
Expand Down

This file was deleted.

This file was deleted.

Loading