Projekt

Obecné

Profil

Stáhnout (2.03 KB) Statistiky
| Větev: | Tag: | Revize:
1
import React, { useEffect } from 'react';
2
import './App.css';
3

    
4
function YourRequests(props) {
5

    
6
  useEffect( () => {
7
      getData();
8
    }, []);
9

    
10
  // get requests from server
11
  const getData = async () => {
12
    try {
13
      const response = await fetch(
14
        'http://devcz.yoso.fi:8090/ymanager/user/6/calendar?from=2020/06/24&status=PENDING', {
15
          headers: {
16
            Authorization: 6
17
          },
18
        }
19
      );
20

    
21
    if (response.ok) {
22
      const data = await response.json();
23
      props.setUser(data.map(request => {
24
        const a = request.date;
25
        const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
26

    
27
      return (
28
        {
29
          title: props.userName.name,
30
          id: request.id,
31
          start: b,
32
          status: request.status,
33
          type: request.type
34
        }
35
      )
36
    }))
37
    } else {
38
      if(response.status === 400) {
39
        alert('error 400 GET DATA (YOUR REQUEST)')
40
     }
41
        else if (response.status === 500) {
42
           alert ('error 500 GET DATA (YOUR REQUEST)')
43
        }
44
        else {
45
           alert('error GET DATA (YOUR REQUEST)')
46
        }
47
    }
48
  } catch (e) {
49
    console.log(e)
50
    alert('error catch GET DATA (YOUR REQUEST)')
51
  }
52
}
53
        
54

    
55
  return (
56
    <div className="offs-request column">
57
      <h3>Your Requests</h3>
58
      <div className="underline-1"></div>
59
      <div className="offs-items column">
60
        <div className="offs-item row">
61
          <table>
62
            <tbody>
63
              <tr>
64
                <th>Name</th>
65
                <th>Type</th>
66
                <th>Date</th>    
67
                <th>Status</th>    
68
              </tr>
69
              {props.userRequest.map(user => (
70
              <tr>
71
                <td>{user.title}</td>
72
                <td>{user.type}</td>    
73
                <td>{user.end ? user.start + " - " + user.end : user.start}</td>
74
                <td>{user.status}</td>
75
              </tr>
76
              ))}
77
            </tbody>
78
          </table>
79
        </div>
80
      </div>
81
    </div>
82
  )
83
}
84

    
85

    
86
export default YourRequests;
(12-12/16)