Projekt

Obecné

Profil

Stáhnout (2.1 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
  // 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
  
53

    
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
            {props.userRequest.length > 0 ?
62
            
63
            <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
                <tr key={user.id}>
72
                <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
            :
80
            <tbody>
81
              <div>No requests</div>
82
            </tbody>}
83
          </table>
84
        </div>
85
      </div>
86
    </div>
87
  )
88
}
89

    
90

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