twenty/front/src/App.tsx

73 lines
2.0 KiB
TypeScript
Raw Normal View History

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';
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';
import Opportunities from './pages/opportunities/Opportunities';
2023-05-17 23:31:16 +03:00
import { User, mapToUser } from './interfaces/entities/user.interface';
import { useGetCurrentUserQuery } from './services/api/users';
import { getUserIdFromToken } from './services/auth/AuthService';
2022-12-01 17:58:08 +03:00
function App() {
const [user, setUser] = useState<User | undefined>(undefined);
2023-01-27 14:12:04 +03:00
const userIdFromToken = getUserIdFromToken();
const { data } = useGetCurrentUserQuery(userIdFromToken);
useEffect(() => {
if (data?.users[0]) {
setUser(mapToUser(data?.users[0]));
}
}, [data]);
2023-04-09 17:43:43 +03:00
2022-12-01 17:58:08 +03:00
return (
<div>
{
<AppLayout user={user}>
<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>
}
/>
<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 />} />
</Routes>
</AppLayout>
}
</div>
2022-12-01 17:58:08 +03:00
);
}
export default App;