Projekt

Obecné

Profil

Stáhnout (1.92 KB) Statistiky
| Větev: | Tag: | Revize:
1
import React, { useEffect } from 'react';
2
import './App.css';
3
import moment from 'moment';
4
import * as api_fetch from './api'
5

    
6
function YourRequests(props) {
7

    
8
  useEffect( () => {
9
      getData();
10
    }, []);
11

    
12
  // get requests from server
13
  const getData = async () => {
14

    
15
    api_fetch.loadYourRequests().then((data) => {
16

    
17
      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
          start: moment(b).format("D.M.YYYY"),
26
          status: request.status = request.status.toLowerCase(),
27
          type: convertVacationType(request.type)
28
        }
29
      )
30
    }))
31
    }).catch(reason => {
32
      alert(reason)
33
    });
34
}
35

    
36
function convertVacationType(vacationType) {
37
  switch (vacationType) {
38
    case 'SICK_DAY' :
39
      return 'sickday';
40
    default:
41
      return 'holiday';
42
  }
43
}
44
  
45

    
46
  return (
47
    <div className="offs-request column">
48
      <h3>Your Requests</h3>
49
      <div className="underline-1"></div>
50
      <div className="offs-items column">
51
        <div className="offs-item row">
52
          <table>
53
            {props.user.length > 0 ?
54
            
55
            <tbody>
56
              <tr>
57
                <th>Name</th>
58
                <th>Type</th>
59
                <th>Date</th>    
60
                <th>Status</th>    
61
              </tr>
62
              {props.user.map(user => (
63
                <tr key={user.id}>
64
                <td>{user.title}</td>
65
                <td>{user.type}</td>    
66
                <td>{user.end ? user.start + " - " + user.end : user.start}</td>
67
                <td>{user.status}</td>
68
              </tr>
69
              ))}
70
            </tbody>
71
            :
72
            <tbody>
73
              <div>No requests</div>
74
            </tbody>}
75
          </table>
76
        </div>
77
      </div>
78
    </div>
79
  )
80
}
81

    
82

    
83
export default YourRequests;
(12-12/17)