2024-04-11 23:10:39 +00:00
|
|
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
2023-12-11 14:35:34 +00:00
|
|
|
|
2024-04-11 23:10:39 +00:00
|
|
|
import Projects from './pages/org-slug';
|
|
|
|
import Settings from './pages/org-slug/Settings';
|
2023-12-22 08:49:59 +00:00
|
|
|
import {
|
|
|
|
projectsRoutesWithSearch,
|
|
|
|
projectsRoutesWithoutSearch,
|
2024-04-11 23:10:39 +00:00
|
|
|
} from './pages/org-slug/projects/routes';
|
|
|
|
import ProjectSearchLayout from './layouts/ProjectSearch';
|
|
|
|
import Index from './pages';
|
2024-04-21 23:02:42 +00:00
|
|
|
import AuthPage from './pages/AuthPage';
|
2024-04-11 23:10:39 +00:00
|
|
|
import { DashboardLayout } from './pages/org-slug/layout';
|
2024-04-21 23:02:42 +00:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
import Web3Provider from 'context/Web3Provider';
|
2023-12-11 14:35:34 +00:00
|
|
|
|
|
|
|
const router = createBrowserRouter([
|
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: ':orgSlug',
|
2024-02-28 09:22:54 +00:00
|
|
|
element: <DashboardLayout />,
|
2023-12-22 08:49:59 +00:00
|
|
|
children: [
|
|
|
|
{
|
|
|
|
element: <ProjectSearchLayout />,
|
|
|
|
children: [
|
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: '',
|
2024-02-07 13:11:54 +00:00
|
|
|
element: <Projects />,
|
2023-12-22 08:49:59 +00:00
|
|
|
},
|
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: 'projects',
|
2023-12-22 08:49:59 +00:00
|
|
|
children: projectsRoutesWithSearch,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: 'settings',
|
2023-12-22 08:49:59 +00:00
|
|
|
element: <Settings />,
|
|
|
|
},
|
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: 'projects',
|
2023-12-22 08:49:59 +00:00
|
|
|
children: projectsRoutesWithoutSearch,
|
|
|
|
},
|
|
|
|
],
|
2023-12-11 14:35:34 +00:00
|
|
|
},
|
2024-02-07 13:11:54 +00:00
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: '/',
|
2024-02-07 13:11:54 +00:00
|
|
|
element: <Index />,
|
|
|
|
},
|
2024-02-22 11:56:26 +00:00
|
|
|
{
|
2024-04-11 23:10:39 +00:00
|
|
|
path: '/login',
|
2024-04-21 23:02:42 +00:00
|
|
|
element: <AuthPage />,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/signup',
|
|
|
|
element: <AuthPage />,
|
2024-02-22 11:56:26 +00:00
|
|
|
},
|
2023-12-11 14:35:34 +00:00
|
|
|
]);
|
2023-12-08 05:20:55 +00:00
|
|
|
|
|
|
|
function App() {
|
2024-04-21 23:02:42 +00:00
|
|
|
// Hacky way of checking session
|
|
|
|
// TODO: Handle redirect backs
|
|
|
|
useEffect(() => {
|
|
|
|
fetch(`${import.meta.env.VITE_SERVER_URL}/auth/session`, {
|
|
|
|
credentials: 'include',
|
|
|
|
}).then((res) => {
|
|
|
|
if (res.status !== 200) {
|
|
|
|
localStorage.clear();
|
2024-04-24 02:10:20 +00:00
|
|
|
const path = window.location.pathname;
|
|
|
|
if (path !== '/login' && path !== '/signup') {
|
2024-04-21 23:02:42 +00:00
|
|
|
window.location.pathname = '/login';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Web3Provider>
|
2024-04-24 02:10:20 +00:00
|
|
|
<RouterProvider router={router} />
|
2024-04-21 23:02:42 +00:00
|
|
|
</Web3Provider>
|
|
|
|
);
|
2023-12-08 05:20:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|