Revize ebfe6347
Přidáno uživatelem plundrichov před více než 4 roky(ů)
client/src/UpcomingRequests.js | ||
---|---|---|
1 |
import React, { useEffect } from 'react'; |
|
1 |
import React, { useState, useEffect } from 'react';
|
|
2 | 2 |
import './App.css'; |
3 |
import moment from 'moment'; |
|
3 | 4 |
import * as api_fetch from './api' |
4 | 5 |
|
5 | 6 |
function UpcomingRequests(props) { |
... | ... | |
21 | 22 |
{ |
22 | 23 |
title: request.firstName + ' ' + request.lastName, |
23 | 24 |
id: request.id, |
24 |
type: request.type,
|
|
25 |
start: b,
|
|
25 |
type: convertVacationType(request.type),
|
|
26 |
start: moment(b).format("D.M.YYYY"),
|
|
26 | 27 |
end: null, |
27 |
status: request.status |
|
28 |
status: request.status = request.status.toLowerCase()
|
|
28 | 29 |
}) |
29 | 30 |
})) |
30 | 31 |
}).catch(reason => { |
... | ... | |
32 | 33 |
}); |
33 | 34 |
} |
34 | 35 |
|
36 |
function convertVacationType(vacationType) { |
|
37 |
switch (vacationType) { |
|
38 |
case 'SICK_DAY' : |
|
39 |
return 'sickday'; |
|
40 |
case 'HOLIDAY': |
|
41 |
return 'holiday'; |
|
42 |
} |
|
43 |
} |
|
44 |
|
|
35 | 45 |
|
36 | 46 |
|
37 | 47 |
// send accepted request to server |
38 | 48 |
const acceptRequest = async (user) => { |
49 |
try { |
|
39 | 50 |
|
40 |
const acceptedRequests = { |
|
41 |
id: user.id, |
|
42 |
status: 'ACCEPTED', |
|
43 |
} |
|
51 |
const acceptedRequests = {
|
|
52 |
id: user.id,
|
|
53 |
status: 'ACCEPTED',
|
|
54 |
}
|
|
44 | 55 |
|
45 |
api_fetch.sendAcceptedRequest(acceptedRequests).then((data) => { |
|
46 |
|
|
47 |
const userProps = { |
|
48 |
title: user.title, |
|
49 |
id: 0, |
|
56 |
await api_fetch.sendAcceptedRequest(acceptedRequests).then(() => { |
|
57 |
|
|
58 |
const userProps = { |
|
59 |
title: user.title, |
|
60 |
id: 0, |
|
61 |
type: user.type, |
|
50 | 62 |
type: user.type, |
51 |
start: user.start |
|
52 |
} |
|
53 |
//concat new request to current ones |
|
63 |
type: user.type, |
|
64 |
start: user.start |
|
65 |
} |
|
66 |
//concat new request to current ones |
|
54 | 67 |
props.setRequest((acceptedRequest) => acceptedRequest.concat(userProps)) |
55 |
//request accept button |
|
68 |
//request accept button
|
|
56 | 69 |
props.setUser((pendingRequest) => pendingRequest.filter((item) => item !== user)); |
57 |
}).catch(response => { |
|
58 |
alert(response) |
|
59 |
}) |
|
70 |
}) |
|
71 |
} catch (e) { |
|
72 |
throw 'error catch GET DATA APP (getCurrentProfile)' |
|
73 |
} |
|
60 | 74 |
} |
61 | 75 |
|
62 |
|
|
63 | 76 |
|
64 | 77 |
//send rejected request to server |
65 | 78 |
const declineRequest = async (user) => { |
79 |
try{ |
|
66 | 80 |
|
67 |
const rejectedRequest = { |
|
68 |
id: user.id, |
|
69 |
status: 'REJECTED', |
|
70 |
} |
|
81 |
const rejectedRequest = {
|
|
82 |
id: user.id,
|
|
83 |
status: 'REJECTED',
|
|
84 |
}
|
|
71 | 85 |
|
72 |
api_fetch.sendRejectedRequest(rejectedRequest).then((data) => {
|
|
73 |
//request cancel button |
|
86 |
await api_fetch.sendRejectedRequest(rejectedRequest);
|
|
87 |
|
|
74 | 88 |
props.setUser((acceptedRequest) => acceptedRequest.filter((item) => item !== user)) |
75 |
}).catch(reason => { |
|
76 |
alert(reason) |
|
77 |
}); |
|
89 |
|
|
90 |
const usersOverview = await api_fetch.getUsersOverview(); |
|
91 |
props.setEmployees(usersOverview); |
|
92 |
|
|
93 |
} catch (e) { |
|
94 |
alert(e) |
|
95 |
} |
|
78 | 96 |
} |
79 | 97 |
|
80 | 98 |
return ( |
... | ... | |
84 | 102 |
<div className="offs-items column"> |
85 | 103 |
<div className="offs-item row"> |
86 | 104 |
<table> |
105 |
{/* {props.userRequest.length > 0 |
|
106 |
? */} |
|
87 | 107 |
<tbody> |
88 | 108 |
<tr> |
89 | 109 |
<th>Name</th> |
... | ... | |
102 | 122 |
</tr> |
103 | 123 |
))} |
104 | 124 |
</tbody> |
125 |
{/* : |
|
126 |
<tbody> |
|
127 |
<p>There are no requests.</p> |
|
128 |
</tbody> |
|
129 |
} */} |
|
130 |
|
|
105 | 131 |
</table> |
106 | 132 |
</div> |
107 | 133 |
</div> |
Také k dispozici: Unified diff
re #58 client part(especially rebuilt api.js, all fetches, little edits in YourRequests/UpcomingRequests and fixed bugs in calendar and overview (add event, save, post, numbers)