Projekt

Obecné

Profil

Stáhnout (2.1 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 c46ffe2f plundrichov
6
function YourRequests(props) {
7
8
  useEffect( () => {
9
      getData();
10
    }, []);
11
12
  // get requests from server
13
  const getData = async () => {
14
15 9f045397 plundrichov
    api_fetch.loadYourRequests().then((data) => {
16
17 c46ffe2f plundrichov
      props.setUser(data.map(request => {
18
        const a = request.date;
19
        const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
20
21
      return (
22
        {
23
          title: props.userName.name,
24
          id: request.id,
25 ebfe6347 plundrichov
          start: moment(b).format("D.M.YYYY"),
26
          status: request.status = request.status.toLowerCase(),
27
          type: convertVacationType(request.type)
28 c46ffe2f plundrichov
        }
29
      )
30
    }))
31 9f045397 plundrichov
    }).catch(reason => {
32
      alert(reason)
33
    });
34 c46ffe2f plundrichov
}
35 ebfe6347 plundrichov
36
function convertVacationType(vacationType) {
37
  // vacationType =  'SICK_DAY' ? 'sickday' : 'holiday'
38
39
  // if (vacationType = 'SICK_DAY') {
40
  // return: 'sickday',
41
  // } else {
42
  //   return: 'holiday'
43
  // }
44
45
  switch (vacationType) {
46
    case 'SICK_DAY' :
47
      return 'sickday';
48
    case 'HOLIDAY':
49
      return 'holiday';
50
  }
51
}
52 9f045397 plundrichov
  
53 c46ffe2f plundrichov
54
  return (
55
    <div className="offs-request column">
56
      <h3>Your Requests</h3>
57
      <div className="underline-1"></div>
58
      <div className="offs-items column">
59
        <div className="offs-item row">
60
          <table>
61 ebfe6347 plundrichov
            {props.userRequest.length > 0 ?
62
            
63 c46ffe2f plundrichov
            <tbody>
64
              <tr>
65
                <th>Name</th>
66
                <th>Type</th>
67
                <th>Date</th>    
68
                <th>Status</th>    
69
              </tr>
70
              {props.userRequest.map(user => (
71 ebfe6347 plundrichov
                <tr key={user.id}>
72 c46ffe2f plundrichov
                <td>{user.title}</td>
73
                <td>{user.type}</td>    
74
                <td>{user.end ? user.start + " - " + user.end : user.start}</td>
75
                <td>{user.status}</td>
76
              </tr>
77
              ))}
78
            </tbody>
79 ebfe6347 plundrichov
            :
80
            <tbody>
81
              <div>No requests</div>
82
            </tbody>}
83 c46ffe2f plundrichov
          </table>
84
        </div>
85
      </div>
86
    </div>
87
  )
88
}
89
90
91
export default YourRequests;