1 |
c46ffe2f
|
plundrichov
|
import React, { useEffect } from 'react';
|
2 |
|
|
import './App.css';
|
3 |
ebfe6347
|
plundrichov
|
import moment from 'moment';
|
4 |
1865a0be
|
Pavel Fidransky
|
import * as api from './api';
|
5 |
|
|
import convertVacationType from './convertVacationType';
|
6 |
c46ffe2f
|
plundrichov
|
|
7 |
1865a0be
|
Pavel Fidransky
|
export default function YourRequests(props) {
|
8 |
c46ffe2f
|
plundrichov
|
|
9 |
|
|
useEffect( () => {
|
10 |
1865a0be
|
Pavel Fidransky
|
if (props.currentUser === undefined) {
|
11 |
|
|
return;
|
12 |
5bedee9e
|
plundrichov
|
}
|
13 |
c46ffe2f
|
plundrichov
|
|
14 |
1865a0be
|
Pavel Fidransky
|
getData();
|
15 |
|
|
}, [props.currentUser]); // eslint-disable-line
|
16 |
9f045397
|
plundrichov
|
|
17 |
1865a0be
|
Pavel Fidransky
|
// get requests from server
|
18 |
|
|
async function getData() {
|
19 |
|
|
api.loadYourRequests(props.currentUser).then((data) => {
|
20 |
c46ffe2f
|
plundrichov
|
props.setUser(data.map(request => {
|
21 |
1865a0be
|
Pavel Fidransky
|
const convertedDate = request.date.split('/').join('-');
|
22 |
c46ffe2f
|
plundrichov
|
|
23 |
1865a0be
|
Pavel Fidransky
|
return ({
|
24 |
5bedee9e
|
plundrichov
|
title: props.currentUser.name,
|
25 |
c46ffe2f
|
plundrichov
|
id: request.id,
|
26 |
1865a0be
|
Pavel Fidransky
|
start: moment(convertedDate).format('D.M.YYYY'),
|
27 |
|
|
status: request.status.toLowerCase(),
|
28 |
|
|
type: convertVacationType(request.type),
|
29 |
|
|
});
|
30 |
|
|
}));
|
31 |
9f045397
|
plundrichov
|
}).catch(reason => {
|
32 |
1865a0be
|
Pavel Fidransky
|
alert(reason);
|
33 |
9f045397
|
plundrichov
|
});
|
34 |
1865a0be
|
Pavel Fidransky
|
}
|
35 |
ebfe6347
|
plundrichov
|
|
36 |
c46ffe2f
|
plundrichov
|
return (
|
37 |
|
|
<div className="offs-request column">
|
38 |
|
|
<h3>Your Requests</h3>
|
39 |
|
|
<div className="underline-1"></div>
|
40 |
|
|
<div className="offs-items column">
|
41 |
|
|
<div className="offs-item row">
|
42 |
|
|
<table>
|
43 |
1865a0be
|
Pavel Fidransky
|
{props.user.length > 0 ? (
|
44 |
|
|
<tbody>
|
45 |
|
|
<tr>
|
46 |
|
|
<th>Name</th>
|
47 |
|
|
<th>Type</th>
|
48 |
|
|
<th>Date</th>
|
49 |
|
|
<th>Status</th>
|
50 |
|
|
</tr>
|
51 |
|
|
{props.user.map(user => (
|
52 |
|
|
<tr key={user.id}>
|
53 |
|
|
<td>{user.title}</td>
|
54 |
|
|
<td>{user.type}</td>
|
55 |
|
|
<td>{user.end ? user.start + ' - ' + user.end : user.start}</td>
|
56 |
|
|
<td>{user.status}</td>
|
57 |
|
|
</tr>
|
58 |
|
|
))}
|
59 |
|
|
</tbody>
|
60 |
|
|
) : (
|
61 |
|
|
<tbody>
|
62 |
|
|
<div>No requests</div>
|
63 |
|
|
</tbody>
|
64 |
|
|
)}
|
65 |
c46ffe2f
|
plundrichov
|
</table>
|
66 |
|
|
</div>
|
67 |
|
|
</div>
|
68 |
|
|
</div>
|
69 |
1865a0be
|
Pavel Fidransky
|
);
|
70 |
c46ffe2f
|
plundrichov
|
}
|