Projekt

Obecné

Profil

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