Revize 1865a0be
Přidáno uživatelem Pavel Fidransky před více než 4 roky(ů)
client/src/App.js | ||
---|---|---|
9 | 9 |
import Setting from './Setting'; |
10 | 10 |
import LogOut from './LogOut'; |
11 | 11 |
import Login from './Login'; |
12 |
import { BrowserRouter, Route, Switch } from "react-router-dom";
|
|
13 |
import * as api_fetch from './api'
|
|
12 |
import { BrowserRouter, Route, Switch } from 'react-router-dom';
|
|
13 |
import * as api from './api';
|
|
14 | 14 |
|
15 |
function App() { |
|
15 |
export default function App() {
|
|
16 | 16 |
|
17 | 17 |
useEffect(() => { |
18 | 18 |
if (window.location.pathname === '/login' || window.location.pathname === '/logout') return; |
19 | 19 |
|
20 |
api_fetch.getCurrentProfile().then(currentProfile => {
|
|
20 |
api.getCurrentProfile().then(currentProfile => { |
|
21 | 21 |
setCurrentUser(currentProfile); |
22 | 22 |
}).catch(reason => { |
23 |
alert(reason)
|
|
23 |
alert(reason);
|
|
24 | 24 |
}); |
25 | 25 |
}, []); |
26 | 26 |
|
... | ... | |
32 | 32 |
<div className="App"> |
33 | 33 |
<Nav currentUser={currentUser} /> |
34 | 34 |
<div className="container"> |
35 |
<Switch> |
|
36 |
<Route path="/" exact component={() => <Home currentUser={currentUser} setCurrentUser={setCurrentUser}/>}/> |
|
37 |
<Route path="/setting"> |
|
38 |
{currentUser !== undefined && currentUser.role === 'EMPLOYER' |
|
39 |
? |
|
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 |
<Route path="/logout"><LogOut/></Route> |
|
48 |
<Route path="/login"><Login/></Route> |
|
49 |
</Switch> |
|
35 |
<Switch> |
|
36 |
<Route path="/" exact component={() => <Home currentUser={currentUser} setCurrentUser={setCurrentUser}/>}/> |
|
37 |
<Route path="/setting"> |
|
38 |
{currentUser !== undefined && currentUser.role === 'EMPLOYER' ? ( |
|
39 |
<Setting/> |
|
40 |
) : ( |
|
41 |
<div className="permissionText column"> |
|
42 |
<p>You don't have permission to access on this server.</p> |
|
43 |
</div> |
|
44 |
)} |
|
45 |
</Route> |
|
46 |
<Route path="/logout"><LogOut/></Route> |
|
47 |
<Route path="/login"><Login/></Route> |
|
48 |
</Switch> |
|
50 | 49 |
</div> |
51 | 50 |
</div> |
52 | 51 |
</BrowserRouter> |
53 | 52 |
); |
54 | 53 |
} |
55 | 54 |
|
56 |
const Home = (props) => { |
|
57 |
const [user, setUser] = useState([]); |
|
58 |
|
|
55 |
function Home(props) { |
|
56 |
const [user, setUser] = useState({}); |
|
59 | 57 |
const [acceptedRequest, setAcceptedRequest] = useState([]); |
60 | 58 |
|
61 |
// OverviewAdmin state
|
|
59 |
// OverviewAdmin state |
|
62 | 60 |
const [employees, setEmployees] = useState([]); |
63 | 61 |
|
64 | 62 |
return ( |
65 | 63 |
<div className="container"> |
66 | 64 |
<div className="main-content"> |
67 |
{props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER' |
|
68 |
? |
|
65 |
{props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER' ? ( |
|
69 | 66 |
<UpcomingRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} setEmployees={setEmployees}/> |
70 |
:
|
|
67 |
) : (
|
|
71 | 68 |
<YourRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser}/> |
72 |
} |
|
73 |
<Calendar setUser={setUser} user={user} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser} setEmployees={setEmployees} setCurrentUser={props.setCurrentUser}/>
|
|
69 |
)}
|
|
70 |
<Calendar setUser={setUser} user={user} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser} setEmployees={setEmployees} setCurrentUser={props.setCurrentUser}/> |
|
74 | 71 |
</div> |
75 |
{props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER' |
|
76 |
? |
|
72 |
{props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER' ? ( |
|
77 | 73 |
<OverviewAdmin employees={employees} setEmployees={setEmployees} /> |
78 |
:
|
|
79 |
<Overview currentUser={props.currentUser} employees={employees} />
|
|
80 |
} |
|
74 |
) : (
|
|
75 |
<Overview currentUser={props.currentUser} employees={employees} /> |
|
76 |
)}
|
|
81 | 77 |
</div> |
82 |
) |
|
83 |
}; |
|
84 |
|
|
85 |
export default App; |
|
86 |
|
|
78 |
); |
|
79 |
} |
Také k dispozici: Unified diff
re #58 massive code formatting