1 |
c46ffe2f
|
plundrichov
|
import React, { useEffect, useState } from 'react';
|
2 |
|
|
import './App.css';
|
3 |
|
|
import Nav from './Nav';
|
4 |
|
|
import Overview from './Overview';
|
5 |
|
|
import OverviewAdmin from './OverviewAdmin';
|
6 |
|
|
import Calendar from './Calendar';
|
7 |
|
|
import UpcomingRequests from './UpcomingRequests';
|
8 |
|
|
import YourRequests from './YourRequests';
|
9 |
|
|
import Setting from './Setting';
|
10 |
|
|
import LogOut from './LogOut';
|
11 |
|
|
import Login from './Login';
|
12 |
|
|
import { BrowserRouter, Route, Switch } from "react-router-dom";
|
13 |
7495b9eb
|
plundrichov
|
import * as api_fetch from './api'
|
14 |
c46ffe2f
|
plundrichov
|
|
15 |
|
|
function App() {
|
16 |
|
|
|
17 |
7495b9eb
|
plundrichov
|
useEffect(() => {
|
18 |
a12a4e99
|
plundrichov
|
if (window.location.pathname === '/login' || window.location.pathname === '/logout') return;
|
19 |
faed7f5e
|
plundrichov
|
|
20 |
7495b9eb
|
plundrichov
|
api_fetch.getCurrentProfile().then(currentProfile => {
|
21 |
5bedee9e
|
plundrichov
|
setCurrentUser(currentProfile);
|
22 |
9f045397
|
plundrichov
|
}).catch(reason => {
|
23 |
ebfe6347
|
plundrichov
|
alert(reason)
|
24 |
7495b9eb
|
plundrichov
|
});
|
25 |
c46ffe2f
|
plundrichov
|
}, []);
|
26 |
|
|
|
27 |
5bedee9e
|
plundrichov
|
const [currentUser, setCurrentUser] = useState();
|
28 |
ebfe6347
|
plundrichov
|
|
29 |
c46ffe2f
|
plundrichov
|
|
30 |
|
|
return (
|
31 |
|
|
<BrowserRouter>
|
32 |
|
|
<div className="App">
|
33 |
5bedee9e
|
plundrichov
|
<Nav currentUser={currentUser} />
|
34 |
c46ffe2f
|
plundrichov
|
<div className="container">
|
35 |
|
|
<Switch>
|
36 |
5bedee9e
|
plundrichov
|
<Route path="/" exact component={() => <Home currentUser={currentUser} setCurrentUser={setCurrentUser}/>}/>
|
37 |
ebfe6347
|
plundrichov
|
<Route path="/setting">
|
38 |
5bedee9e
|
plundrichov
|
{currentUser !== undefined && currentUser.role === 'EMPLOYER'
|
39 |
ebfe6347
|
plundrichov
|
?
|
40 |
|
|
<Setting/>
|
41 |
|
|
:
|
42 |
|
|
<div className="permissionText column">
|
43 |
|
|
<p>You don't have permission to access on this server.</p>
|
44 |
|
|
</div>
|
45 |
|
|
}
|
46 |
|
|
</Route>
|
47 |
c46ffe2f
|
plundrichov
|
<Route path="/logout"><LogOut/></Route>
|
48 |
|
|
<Route path="/login"><Login/></Route>
|
49 |
|
|
</Switch>
|
50 |
|
|
</div>
|
51 |
|
|
</div>
|
52 |
|
|
</BrowserRouter>
|
53 |
|
|
);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
const Home = (props) => {
|
57 |
1a58c244
|
plundrichov
|
const [user, setUser] = useState([]);
|
58 |
c46ffe2f
|
plundrichov
|
|
59 |
1a58c244
|
plundrichov
|
const [acceptedRequest, setAcceptedRequest] = useState([]);
|
60 |
c46ffe2f
|
plundrichov
|
|
61 |
ebfe6347
|
plundrichov
|
// OverviewAdmin state
|
62 |
5bedee9e
|
plundrichov
|
const [employees, setEmployees] = useState([]);
|
63 |
ebfe6347
|
plundrichov
|
|
64 |
c46ffe2f
|
plundrichov
|
return (
|
65 |
ebfe6347
|
plundrichov
|
<div className="container">
|
66 |
|
|
<div className="main-content">
|
67 |
5bedee9e
|
plundrichov
|
{props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER'
|
68 |
ebfe6347
|
plundrichov
|
?
|
69 |
1a58c244
|
plundrichov
|
<UpcomingRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} setEmployees={setEmployees}/>
|
70 |
ebfe6347
|
plundrichov
|
:
|
71 |
5bedee9e
|
plundrichov
|
<YourRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser}/>
|
72 |
ebfe6347
|
plundrichov
|
}
|
73 |
5bedee9e
|
plundrichov
|
<Calendar setUser={setUser} user={user} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser} setEmployees={setEmployees} setCurrentUser={props.setCurrentUser}/>
|
74 |
ebfe6347
|
plundrichov
|
</div>
|
75 |
5bedee9e
|
plundrichov
|
{props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER'
|
76 |
ebfe6347
|
plundrichov
|
?
|
77 |
|
|
<OverviewAdmin employees={employees} setEmployees={setEmployees} />
|
78 |
|
|
:
|
79 |
5bedee9e
|
plundrichov
|
<Overview currentUser={props.currentUser} employees={employees} />
|
80 |
ebfe6347
|
plundrichov
|
}
|
81 |
c46ffe2f
|
plundrichov
|
</div>
|
82 |
|
|
)
|
83 |
|
|
};
|
84 |
|
|
|
85 |
|
|
export default App;
|