2023-05-04 12:09:06 +03:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2023-04-09 17:43:43 +03:00
|
|
|
import People from './pages/people/People';
|
|
|
|
import Companies from './pages/companies/Companies';
|
2023-04-20 19:46:27 +03:00
|
|
|
import AuthCallback from './pages/auth/Callback';
|
|
|
|
import Login from './pages/auth/Login';
|
2022-12-05 00:59:30 +03:00
|
|
|
import AppLayout from './layout/AppLayout';
|
2023-04-09 17:43:43 +03:00
|
|
|
import { Routes, Route, Navigate } from 'react-router-dom';
|
2023-04-21 16:36:10 +03:00
|
|
|
import RequireAuth from './components/auth/RequireAuth';
|
2023-04-26 19:00:06 +03:00
|
|
|
import Opportunities from './pages/opportunities/Opportunities';
|
2023-05-04 12:09:06 +03:00
|
|
|
import { User, mapUser } from './interfaces/user.interface';
|
|
|
|
import { useGetCurrentUserQuery } from './services/users';
|
2022-12-01 17:58:08 +03:00
|
|
|
|
|
|
|
function App() {
|
2023-05-04 12:09:06 +03:00
|
|
|
const [user, setUser] = useState<User | undefined>(undefined);
|
2023-01-27 14:12:04 +03:00
|
|
|
|
2023-05-04 12:09:06 +03:00
|
|
|
const { data } = useGetCurrentUserQuery();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (data?.users[0]) {
|
|
|
|
setUser(mapUser(data?.users[0]));
|
|
|
|
}
|
|
|
|
}, [data]);
|
2023-04-09 17:43:43 +03:00
|
|
|
|
2022-12-01 17:58:08 +03:00
|
|
|
return (
|
2023-02-03 21:59:00 +03:00
|
|
|
<div>
|
2023-03-06 18:15:46 +03:00
|
|
|
{
|
2023-05-04 12:09:06 +03:00
|
|
|
<AppLayout user={user}>
|
2023-03-06 18:15:46 +03:00
|
|
|
<Routes>
|
2023-04-21 16:36:10 +03:00
|
|
|
<Route
|
|
|
|
path="/"
|
|
|
|
element={
|
|
|
|
<RequireAuth>
|
|
|
|
<Navigate to="/people" replace />
|
|
|
|
</RequireAuth>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/people"
|
|
|
|
element={
|
|
|
|
<RequireAuth>
|
|
|
|
<People />
|
|
|
|
</RequireAuth>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="/companies"
|
|
|
|
element={
|
|
|
|
<RequireAuth>
|
|
|
|
<Companies />
|
|
|
|
</RequireAuth>
|
|
|
|
}
|
|
|
|
/>
|
2023-04-26 19:00:06 +03:00
|
|
|
<Route
|
|
|
|
path="/opportunities"
|
|
|
|
element={
|
|
|
|
<RequireAuth>
|
|
|
|
<Opportunities />
|
|
|
|
</RequireAuth>
|
|
|
|
}
|
|
|
|
/>
|
2023-04-20 19:46:27 +03:00
|
|
|
<Route path="/auth/callback" element={<AuthCallback />} />
|
|
|
|
<Route path="/auth/login" element={<Login />} />
|
2023-03-06 18:15:46 +03:00
|
|
|
</Routes>
|
|
|
|
</AppLayout>
|
|
|
|
}
|
2023-02-03 21:59:00 +03:00
|
|
|
</div>
|
2022-12-01 17:58:08 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|