Projekt

Obecné

Profil

Stáhnout (1.86 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
import convertVacationType from './convertVacationType'
6

    
7
function YourRequests(props) {
8

    
9
  useEffect( () => {
10
    if (props.currentUser !== undefined) {
11
      getData();
12
    }
13
  }, [props.currentUser]);
14

    
15
  // get requests from server
16
  const getData = async () => {
17

    
18
    api_fetch.loadYourRequests(props.currentUser).then((data) => {
19

    
20
      props.setUser(data.map(request => {
21
        const convertedDate = request.date.split("/").join("-");
22

    
23
      return (
24
        {
25
          title: props.currentUser.name,
26
          id: request.id,
27
          start: moment(convertedDate).format("D.M.YYYY"),
28
          status: request.status = request.status.toLowerCase(),
29
          type: convertVacationType(request.type)
30
        }
31
      )
32
    }))
33
    }).catch(reason => {
34
      alert(reason)
35
    });
36
}
37

    
38
  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
            {props.user.length > 0 ?
46
            
47
            <tbody>
48
              <tr>
49
                <th>Name</th>
50
                <th>Type</th>
51
                <th>Date</th>    
52
                <th>Status</th>    
53
              </tr>
54
              {props.user.map(user => (
55
                <tr key={user.id}>
56
                <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
            :
64
            <tbody>
65
              <div>No requests</div>
66
            </tbody>}
67
          </table>
68
        </div>
69
      </div>
70
    </div>
71
  )
72
}
73

    
74

    
75
export default YourRequests;
(12-12/18)