Skip to content

Commit

Permalink
Merge pull request #649 from universi-me/change#648/mover-routestsx-c…
Browse files Browse the repository at this point in the history
…onfigs

CHANGE #648: Mover routes.tsx para src/configs
  • Loading branch information
NiiMiyo authored Nov 22, 2024
2 parents 7a9e484 + 3c0250c commit 9c1c150
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 118 deletions.
131 changes: 131 additions & 0 deletions src/configs/routes.tsx
Original file line number Diff line number Diff line change
@@ -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: <App />,
errorElement: <PageNotFound />,
children: [
{
path: "/",
element: <Homepage />
},
{
path: "/profile/:id",
element: <ProfilePage />,
loader: ProfilePageLoader
},
{
path: "/manage-profile",
element: <ManageProfilePage />,
loader: ManageProfileLoader
},
{
path: "/group/*",
element: <GroupPage />,
loader: GroupPageLoader
},
{
path: "/recovery-password/:id",
element: <NewPassword />
},
{
path: "/login",
element: <Singin />
},
{
path: "/signup",
element: <SignUpPage />
},
{
path: "/recovery",
element: <Recovery />
},
{
path: "/google-oauth-redirect",
element: <OAuth2Element />
},
{
path: "/keycloak-oauth-redirect",
element: <KeyCloakOAuth2Element />
},
{
path: "/settings",
element: <SettingsPage />,
children: [
{
path: "email-filter",
element: <GroupEmailFilterPage />,
loader: GroupEmailFilterLoader,
},
{
path: "roles",
element: <RolesPage />,
loader: RolesPageLoader,
},
{
path: "environments",
element: <EnvironmentsPage />,
loader: EnvironmentsLoader,
},
{
path: "competences",
element: <CompetencesSettingsPage />,
loader: CompetencesSettingsLoader,
},
{
path: "theme-color",
element: <GroupThemeColorPage />,
}
],
},
{
path: "/content/:id",
element: <ContentPage />,
loader: ContentPageLoader,
},
{
path: "/job/:id",
element: <JobPage />,
loader: JobPageLoader
}
]
}, {
path: "/health",
element: <HealthCheckPage />
} ]);


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 );
}
2 changes: 1 addition & 1 deletion src/contexts/Auth/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/services/UniversimeApi/api.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
115 changes: 0 additions & 115 deletions src/services/routes.tsx

This file was deleted.

0 comments on commit 9c1c150

Please sign in to comment.