1
|
import React, { useEffect } from 'react';
|
2
|
import './App.css';
|
3
|
import * as api_fetch from './api'
|
4
|
|
5
|
function YourRequests(props) {
|
6
|
|
7
|
useEffect( () => {
|
8
|
getData();
|
9
|
}, []);
|
10
|
|
11
|
// get requests from server
|
12
|
const getData = async () => {
|
13
|
|
14
|
api_fetch.loadYourRequests().then((data) => {
|
15
|
|
16
|
props.setUser(data.map(request => {
|
17
|
const a = request.date;
|
18
|
const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
|
19
|
|
20
|
return (
|
21
|
{
|
22
|
title: props.userName.name,
|
23
|
id: request.id,
|
24
|
start: b,
|
25
|
status: request.status,
|
26
|
type: request.type
|
27
|
}
|
28
|
)
|
29
|
}))
|
30
|
}).catch(reason => {
|
31
|
alert(reason)
|
32
|
});
|
33
|
}
|
34
|
|
35
|
|
36
|
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
|
<tbody>
|
44
|
<tr>
|
45
|
<th>Name</th>
|
46
|
<th>Type</th>
|
47
|
<th>Date</th>
|
48
|
<th>Status</th>
|
49
|
</tr>
|
50
|
{props.userRequest.map(user => (
|
51
|
<tr key={user.id}>
|
52
|
<td>{user.title}</td>
|
53
|
<td>{user.type}</td>
|
54
|
<td>{user.end ? user.start + " - " + user.end : user.start}</td>
|
55
|
<td>{user.status}</td>
|
56
|
</tr>
|
57
|
))}
|
58
|
</tbody>
|
59
|
</table>
|
60
|
</div>
|
61
|
</div>
|
62
|
</div>
|
63
|
)
|
64
|
}
|
65
|
|
66
|
|
67
|
export default YourRequests;
|