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 Komponenta1 from './Komponenta1';
|
13 |
|
|
// import Komponenta2 from './Komponenta2';
|
14 |
|
|
import { BrowserRouter, Route, Switch } from "react-router-dom";
|
15 |
|
|
|
16 |
|
|
function App() {
|
17 |
|
|
|
18 |
|
|
useEffect( () => {
|
19 |
|
|
getData();
|
20 |
|
|
}, []);
|
21 |
|
|
|
22 |
|
|
const getData = async () => {
|
23 |
|
|
try {
|
24 |
|
|
const response = await fetch(
|
25 |
|
|
'http://devcz.yoso.fi:8090/ymanager/users/current/profile', {
|
26 |
|
|
headers: {
|
27 |
|
|
Authorization: 1
|
28 |
|
|
}
|
29 |
|
|
}
|
30 |
|
|
);
|
31 |
|
|
|
32 |
|
|
if (response.ok) {
|
33 |
|
|
const data = await response.json();
|
34 |
|
|
setUserName({
|
35 |
|
|
name: data.firstName + ' ' + data.lastName,
|
36 |
|
|
role: data.role,
|
37 |
|
|
id: data.id,
|
38 |
|
|
holiday: data.vacationCount,
|
39 |
|
|
sickday: data.sickDayCount
|
40 |
|
|
})
|
41 |
|
|
} else {
|
42 |
|
|
if(response.status === 400) {
|
43 |
|
|
alert('error 400 GET DATA APP')
|
44 |
|
|
}
|
45 |
|
|
else if (response.status === 500) {
|
46 |
|
|
alert ('error 500 GET DATA APP')
|
47 |
|
|
}
|
48 |
|
|
else {
|
49 |
|
|
alert('error GET DATA APP')
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
} catch (e) {
|
53 |
|
|
console.log(e)
|
54 |
|
|
alert('error catch GET DATA APP')
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
const [userName, setUserName] = useState([
|
59 |
|
|
{
|
60 |
|
|
name: 'Golstoj Hyhrenciv'
|
61 |
|
|
}
|
62 |
|
|
]);
|
63 |
|
|
|
64 |
|
|
return (
|
65 |
|
|
<BrowserRouter>
|
66 |
|
|
<div className="App">
|
67 |
|
|
<Nav userName={userName} />
|
68 |
|
|
<div className="container">
|
69 |
|
|
<Switch>
|
70 |
|
|
<Route path="/" exact component={() => <Home userName={userName}/>}/>
|
71 |
|
|
<Route path="/setting"><Setting/></Route>
|
72 |
|
|
<Route path="/logout"><LogOut/></Route>
|
73 |
|
|
<Route path="/login"><Login/></Route>
|
74 |
|
|
</Switch>
|
75 |
|
|
</div>
|
76 |
|
|
</div>
|
77 |
|
|
</BrowserRouter>
|
78 |
|
|
);
|
79 |
|
|
}
|
80 |
|
|
|
81 |
|
|
const Home = (props) => {
|
82 |
|
|
const [userRequest, setUser] = useState([]);
|
83 |
|
|
|
84 |
|
|
const [acceptedRequest, setRequest] = useState([]);
|
85 |
|
|
|
86 |
|
|
useEffect(() => {
|
87 |
|
|
const dataUserRequest = getDataUserRequest();
|
88 |
|
|
setUser(dataUserRequest);
|
89 |
|
|
}, []);
|
90 |
|
|
|
91 |
|
|
function getDataUserRequest() {
|
92 |
|
|
return ([]);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
// const [data, setData] = useState([])
|
96 |
|
|
// const [todo, setTodo] = useState([])
|
97 |
|
|
|
98 |
|
|
return (
|
99 |
|
|
<div className="container">
|
100 |
|
|
<div className="main-content">
|
101 |
|
|
{props.userName.role === 'EMPLOYER' ? <UpcomingRequests userRequest={userRequest} setUser={setUser} acceptedRequest={acceptedRequest} setRequest={setRequest} /> : <YourRequests userRequest={userRequest} setUser={setUser} acceptedRequest={acceptedRequest} setRequest={setRequest} userName={props.userName}/>}
|
102 |
|
|
<Calendar setUser={setUser} userRequest={userRequest} acceptedRequest={acceptedRequest} setRequest={setRequest} userName={props.userName}/>
|
103 |
|
|
</div>
|
104 |
|
|
{props.userName.role === 'EMPLOYER' ? <OverviewAdmin /> : <Overview userName={props.userName} />}
|
105 |
|
|
</div>
|
106 |
|
|
)
|
107 |
|
|
};
|
108 |
|
|
|
109 |
|
|
export default App;
|
110 |
|
|
|
111 |
|
|
/* <Komponenta1 todo={todo} setTodo={setTodo}/>
|
112 |
|
|
<Komponenta2 todo={todo} setTodo={setTodo}/> */
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|