From 3c0250cc1d95f70c2ef7c6f474039a423f2c44d9 Mon Sep 17 00:00:00 2001 From: Douglas Sebastian Date: Fri, 22 Nov 2024 11:33:08 -0300 Subject: [PATCH] change: move services/routes.tsx to configs/routes.tsx --- src/configs/routes.tsx | 131 +++++++++++++++++++++++++++++ src/contexts/Auth/AuthProvider.tsx | 2 +- src/main.tsx | 2 +- src/services/UniversimeApi/api.ts | 2 +- src/services/routes.tsx | 115 ------------------------- 5 files changed, 134 insertions(+), 118 deletions(-) create mode 100644 src/configs/routes.tsx delete mode 100644 src/services/routes.tsx diff --git a/src/configs/routes.tsx b/src/configs/routes.tsx new file mode 100644 index 00000000..98b00156 --- /dev/null +++ b/src/configs/routes.tsx @@ -0,0 +1,131 @@ +import { createBrowserRouter } from 'react-router-dom'; + + +// Import pages +import { App } from "@/src/App"; +import GroupPage, { GroupPageLoader } from "@/pages/Group"; +import { ProfilePage, ProfilePageLoader } from "@/pages/Profile"; +import Singin from "@/pages/singin/Singin"; +import SignUpPage from "@/pages/SignUp"; +import Recovery from "@/pages/Recovery/Recovery"; +import NewPassword from "@/pages/NewPassword/NewPassword"; +import ManageProfilePage, { ManageProfileLoader } from "@/pages/ManageProfile"; +import Homepage from "@/pages/Homepage"; +import SettingsPage, { GroupEmailFilterPage, GroupEmailFilterLoader, RolesPage, RolesPageLoader, EnvironmentsPage, EnvironmentsLoader, CompetencesSettingsPage, CompetencesSettingsLoader, GroupThemeColorPage } from "@/pages/Settings"; +import ContentPage from "@/pages/Content"; +import { ContentPageLoader } from "@/pages/Content/ContentPageLoader"; +import PageNotFound from "@/pages/PageNotFound/PageNotFound"; +import JobPage, { JobPageLoader } from "@/pages/JobPage"; +import HealthCheckPage from "@/pages/HealthCheckPage"; + +// Import services +import { OAuth2Element } from '@/services/oauth2-google'; +import { KeyCloakOAuth2Element } from "@/services/oauth2-keycloak"; + +// Configure pages routing +export const router = createBrowserRouter([{ + path: "/", + element: , + errorElement: , + children: [ + { + path: "/", + element: + }, + { + path: "/profile/:id", + element: , + loader: ProfilePageLoader + }, + { + path: "/manage-profile", + element: , + loader: ManageProfileLoader + }, + { + path: "/group/*", + element: , + loader: GroupPageLoader + }, + { + path: "/recovery-password/:id", + element: + }, + { + path: "/login", + element: + }, + { + path: "/signup", + element: + }, + { + path: "/recovery", + element: + }, + { + path: "/google-oauth-redirect", + element: + }, + { + path: "/keycloak-oauth-redirect", + element: + }, + { + path: "/settings", + element: , + children: [ + { + path: "email-filter", + element: , + loader: GroupEmailFilterLoader, + }, + { + path: "roles", + element: , + loader: RolesPageLoader, + }, + { + path: "environments", + element: , + loader: EnvironmentsLoader, + }, + { + path: "competences", + element: , + loader: CompetencesSettingsLoader, + }, + { + path: "theme-color", + element: , + } + ], + }, + { + path: "/content/:id", + element: , + loader: ContentPageLoader, + }, + { + path: "/job/:id", + element: , + loader: JobPageLoader + } + ] +}, { + path: "/health", + element: +} ]); + + +export function goTo( pathname: string ) { + if ( !window ) + return; + + const pathnameWithSlash = pathname.startsWith('/') ? pathname : "/" + pathname; + const destiny = `${window.location.origin}${pathnameWithSlash}`; + const alreadyThere = location.href === destiny; + + if ( !alreadyThere ) + router.navigate( pathnameWithSlash ); +} diff --git a/src/contexts/Auth/AuthProvider.tsx b/src/contexts/Auth/AuthProvider.tsx index c68b0839..d629687d 100644 --- a/src/contexts/Auth/AuthProvider.tsx +++ b/src/contexts/Auth/AuthProvider.tsx @@ -2,7 +2,7 @@ import { ReactNode, useEffect, useState } from "react"; import { AuthContext } from "./AuthContext"; import { ProfileClass } from "@/types/Profile"; import { UniversimeApi } from "@/services/UniversimeApi"; -import { goTo } from "@/services/routes"; +import { goTo } from "@/configs/routes"; import type { Group } from "@/types/Group"; import type { Link } from "@/types/Link"; import { Nullable, Possibly } from "@/types/utils"; diff --git a/src/main.tsx b/src/main.tsx index 6ad71ac7..0c8d7aee 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -2,7 +2,7 @@ import React from "react"; import ReactDOM from "react-dom/client"; import {RouterProvider} from 'react-router-dom' -import { router } from "@/services/routes"; +import { router } from "@/configs/routes"; import 'bootstrap-icons/font/bootstrap-icons.min.css' import 'sweetalert2/dist/sweetalert2.min.css' diff --git a/src/services/UniversimeApi/api.ts b/src/services/UniversimeApi/api.ts index e8f97e91..4ae3c617 100644 --- a/src/services/UniversimeApi/api.ts +++ b/src/services/UniversimeApi/api.ts @@ -1,7 +1,7 @@ import type { ApiResponse } from "@/types/UniversimeApi"; import * as SwalUtils from "@/utils/sweetalertUtils" import axios from "axios"; -import { goTo } from "@/services/routes"; +import { goTo } from "@/configs/routes"; import { LOGIN_REDIRECT_PARAM } from "@/pages/singin/Singin"; export const api = axios.create({ diff --git a/src/services/routes.tsx b/src/services/routes.tsx deleted file mode 100644 index 6c8e2496..00000000 --- a/src/services/routes.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import { App } from "@/src/App"; -import GroupPage, { GroupPageLoader } from "@/pages/Group"; -import { ProfilePage, ProfilePageLoader } from "@/pages/Profile"; - -import { createBrowserRouter } from 'react-router-dom'; -import Singin from "@/pages/singin/Singin"; - -import { OAuth2Element } from './oauth2-google'; -import { KeyCloakOAuth2Element } from "./oauth2-keycloak"; - -import SignUpPage from "@/pages/SignUp"; -import Recovery from "@/pages/Recovery/Recovery"; -import NewPassword from "@/pages/NewPassword/NewPassword"; -import ManageProfilePage, { ManageProfileLoader } from "@/pages/ManageProfile"; -import Homepage from "@/pages/Homepage"; -import SettingsPage, { GroupEmailFilterPage, GroupEmailFilterLoader, RolesPage, RolesPageLoader, EnvironmentsPage, EnvironmentsLoader, CompetencesSettingsPage, CompetencesSettingsLoader, GroupThemeColorPage} from "@/pages/Settings"; -import ContentPage from "@/pages/Content"; -import { ContentPageLoader } from "@/pages/Content/ContentPageLoader"; -import PageNotFound from "@/pages/PageNotFound/PageNotFound"; -import JobPage, { JobPageLoader } from "@/pages/JobPage"; -import HealthCheckPage from "@/pages/HealthCheckPage"; - - - -export const router = createBrowserRouter([{ - path: "/", - element: , - errorElement: , - children: [ - { - path: "/", - element: - }, - { path: "/profile/:id", element: , loader: ProfilePageLoader }, - { path: "/manage-profile", element: , loader: ManageProfileLoader }, - { path: "/group/*", element: , loader: GroupPageLoader }, - { path: "/recovery-password/:id", element: }, - { - path: "/login", - element: - }, - { - path: "/signup", - element: - }, - { - path: "/recovery", - element: - }, - { - path: "/google-oauth-redirect", - element: - }, - { - path: "/keycloak-oauth-redirect", - element: - }, - { - path: "/settings", - element: , - children: [ - { - path: "email-filter", - element: , - loader: GroupEmailFilterLoader, - }, - { - path: "roles", - element: , - loader: RolesPageLoader, - }, - { - path: "environments", - element: , - loader: EnvironmentsLoader, - }, - { - path: "competences", - element: , - loader: CompetencesSettingsLoader, - }, - { - path:"theme-color", - element: , - } - ], - }, - { - path: "/content/:id", - element: , - loader: ContentPageLoader, - }, - { - path: "/job/:id", - element: , - loader: JobPageLoader - } - ] -}, -{ - path: "/health", - element: -} -]) - -export function goTo(pathname: string) { - if (!window) - return; - const pathnameWithoutSlash = pathname.startsWith('/')? pathname.substring(1) : pathname; - const destiny = `${window.location.origin}/${pathnameWithoutSlash}`; - const alreadyThere = location.href === destiny; - if (!alreadyThere) - router.navigate(`/${pathnameWithoutSlash}`); - -} \ No newline at end of file