2024-06-22 01:07:41 +00:00
|
|
|
import { useEffect } from 'react';
|
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 Web3Provider from 'context/Web3Provider';
|
2024-10-18 12:47:11 +00:00
|
|
|
import { BASE_URL } from 'utils/constants';
|
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 />,
|
|
|
|
},
|
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(() => {
|
2024-10-18 12:47:11 +00:00
|
|
|
fetch(`${BASE_URL}/auth/session`, {
|
2024-04-21 23:02:42 +00:00
|
|
|
credentials: 'include',
|
|
|
|
}).then((res) => {
|
2024-10-18 12:47:11 +00:00
|
|
|
const path = window.location.pathname;
|
2024-04-21 23:02:42 +00:00
|
|
|
if (res.status !== 200) {
|
|
|
|
localStorage.clear();
|
2024-10-18 12:47:11 +00:00
|
|
|
|
|
|
|
if (path !== '/login') {
|
2024-04-21 23:02:42 +00:00
|
|
|
window.location.pathname = '/login';
|
|
|
|
}
|
2024-10-18 12:47:11 +00:00
|
|
|
} else {
|
|
|
|
if (path === '/login') {
|
|
|
|
window.location.pathname = '/';
|
|
|
|
}
|
2024-04-21 23:02:42 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
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;
|