Projekt

Obecné

Profil

Stáhnout (1.88 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 from './api';
5
import convertVacationType from './convertVacationType';
6

    
7
export default function YourRequests(props) {
8

    
9
  useEffect( () => {
10
    if (props.currentUser === undefined) {
11
      return;
12
    }
13

    
14
    getData();
15
  }, [props.currentUser]); // eslint-disable-line
16

    
17
  // get requests from server
18
  async function getData() {
19
    api.loadYourRequests(props.currentUser).then((data) => {
20
      props.setUser(data.map(request => {
21
        const convertedDate = request.date.split('/').join('-');
22

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

    
36
  return (
37
    <div className="offs-request column">
38
      <h3>Your Requests</h3>
39
      <div className="underline-1"></div>
40
      <div className="offs-items column">
41
        <div className="offs-item row">
42
          <table>
43
            {props.user.length > 0 ? (
44
              <tbody>
45
                <tr>
46
                  <th>Name</th>
47
                  <th>Type</th>
48
                  <th>Date</th>
49
                  <th>Status</th>
50
                </tr>
51
                {props.user.map(user => (
52
                  <tr key={user.id}>
53
                    <td>{user.title}</td>
54
                    <td>{user.type}</td>
55
                    <td>{user.end ? user.start + ' - ' + user.end : user.start}</td>
56
                    <td>{user.status}</td>
57
                  </tr>
58
                ))}
59
              </tbody>
60
            ) : (
61
              <tbody>
62
                <div>No requests</div>
63
              </tbody>
64
            )}
65
          </table>
66
        </div>
67
      </div>
68
    </div>
69
  );
70
}
(13-13/19)