Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5bedee9e

Přidáno uživatelem plundrichov před více než 4 roky(ů)

re #58 Rewrited client app to React #58 // yoso internal app // in progress #60 // fixed

Zobrazit rozdíly:

client/index.html
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
    <meta charset="UTF-8">
5
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
    <title>Document</title>
7
</head>
8
<body>
9
    <img src="http://placekitten.com/200/300" class="">
10
</body>
11
</html>
client/public/index.html
5 5
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6 6
    <meta name="viewport" content="width=device-width, initial-scale=1" />
7 7
    <meta name="theme-color" content="#000000" />
8
    <meta
9
      name="description"
10
      content="Web site created using create-react-app"
11
    />
8
  
12 9
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13 10
    <!--
14 11
      manifest.json provides metadata used when your web app is installed on a
......
24 21
      work correctly both with client-side routing and a non-root public URL.
25 22
      Learn how to configure a non-root public URL by running `npm run build`.
26 23
    -->
27
    <title>React App</title>
24
    <title>Ymanager</title>
28 25
  </head>
29 26
  <body>
30 27
    <noscript>You need to enable JavaScript to run this app.</noscript>
31 28
    <div id="root"></div>
32
    <!--
33
      This HTML file is a template.
34
      If you open it directly in the browser, you will see an empty page.
35

  
36
      You can add webfonts, meta tags, or analytics to this file.
37
      The build step will place the bundled scripts into the <body> tag.
38

  
39
      To begin the development, run `npm start` or `yarn start`.
40
      To create a production bundle, use `npm run build` or `yarn build`.
41
    -->
42 29
  </body>
43 30
</html>
client/src/App.css
52 52
    object-fit: cover;
53 53
}
54 54

  
55
.top-nav h3 {
55
.top-nav h1 {
56 56
    margin-left: 85px;
57 57
}
58 58

  
......
294 294
.login-container:hover {
295 295
    background-color: #ffffff25;
296 296
}
297
.login-container h1 {
297
.login-container p {
298 298
    color: white;
299 299
    font-size: 90px;
300 300
}
......
383 383

  
384 384
/* -------------------LogOut------------------- */
385 385

  
386
.logout h1 {
386
.logout p {
387 387
    font-size: 48px;
388 388
    text-align: center;
389 389
    padding: 40px;
390
}
391
.logout h4 {
392
    font-size: 18px;
393
    text-align: center;
394
    color: #ffffffc4;
390
    color: #ffffff;
395 391
    transition: all 0.2s;
396 392
}
397 393

  
398

  
399 394
/* ------------ responsive --------- */
400 395

  
401 396
@media only screen and (max-width: 990px) {
......
585 580
        margin: 2px 0px 2px 5px;
586 581
    }
587 582

  
588
    /* .side-board {
589
        box-shadow: 1px 0px 15px rgb(161, 161, 161);
590
    } */
583
    .calendarInputs {
584
        display: flex;
585
        flex-direction: column;
586
    }
587
    .input-time {
588
        margin: 0;
589
    }
590
    .main-content .btn {
591
        margin-left: 0px;
592
    }
593
    .calendar-form h2 {
594
        font-size: 15px;
595
    }
596
    .calendar-form h4 {
597
        font-size: 13px;
598
    }
599

  
591 600
}
592 601

  
593 602
@media only screen and (max-width: 320px) {
......
661 670
    }
662 671

  
663 672
    .date-input {
664
        width: 135px;
673
        width: 130px;
665 674
    }
666 675
    .offs-request table {
667 676
        font-size: 10px;
......
675 684
        font-size: 11px;
676 685
        margin: 5px 0px 2px 5px;
677 686
    }
687
    .calendar-form h2 {
688
        font-size: 14px;
689
    }
690
    .calendar-form h4 {
691
        font-size: 12px;
692
    }
678 693
}
679

  
680
/* .todoDiv {
681
    padding-left: 200px;
682
} */
683

  
client/src/App.js
18 18
    if (window.location.pathname === '/login') return;
19 19

  
20 20
    api_fetch.getCurrentProfile().then(currentProfile => {
21
      setUserName(currentProfile);
21
      setCurrentUser(currentProfile);
22 22
    }).catch(reason => {
23 23
        alert(reason)
24 24
    });
25 25
  }, []);
26 26

  
27
  const [userName, setUserName] = useState([
28
    { name: 'Golstoj Hyhrenciv' }
29
  ]);
30

  
27
  const [currentUser, setCurrentUser] = useState();
31 28

  
32 29

  
33 30
  return (
34 31
    <BrowserRouter>
35 32
      <div className="App">
36
        <Nav userName={userName} />
33
        <Nav currentUser={currentUser} />
37 34
        <div className="container">
38 35
        <Switch>
39
          <Route path="/" exact component={() => <Home userName={userName} setUserName={setUserName}/>}/>
36
          <Route path="/" exact component={() => <Home currentUser={currentUser} setCurrentUser={setCurrentUser}/>}/>
40 37
          <Route path="/setting">
41
            {userName.role === 'EMPLOYER'
38
            {currentUser !== undefined && currentUser.role === 'EMPLOYER'
42 39
            ?
43 40
              <Setting/> 
44 41
            :
......
61 58

  
62 59
  const [acceptedRequest, setAcceptedRequest] = useState([]);
63 60

  
64
  useEffect(() => {
65
    const datauser = getDatauser();
66
    setUser(datauser);
67
  }, []);
68

  
69 61
  // OverviewAdmin state 
70
  const [employees, setEmployees] = useState([
71
    {
72
       name: 'Sadam',
73
       id: 0,
74
       sickday: 10,
75
       holiday: 10,
76
       takenSickday: 2
77
    }
78
 ]);
62
  const [employees, setEmployees] = useState([]);
79 63

  
80
  function getDatauser() {
81
    return ([]);
82
  }
83
  
84 64
  return (
85 65
    <div className="container">
86 66
      <div className="main-content">
87
        {props.userName.role === 'EMPLOYER'
67
        {props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER'
88 68
        ? 
89 69
          <UpcomingRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} setEmployees={setEmployees}/>
90 70
        : 
91
          <YourRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} userName={props.userName}/>
71
          <YourRequests user={user} setUser={setUser} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser}/>
92 72
        }
93
        <Calendar setUser={setUser} user={user} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} userName={props.userName} setEmployees={setEmployees} setUserName={props.setUserName}/> 
73
        <Calendar setUser={setUser} user={user} acceptedRequest={acceptedRequest} setAcceptedRequest={setAcceptedRequest} currentUser={props.currentUser} setEmployees={setEmployees} setCurrentUser={props.setCurrentUser}/> 
94 74
      </div>
95
      {props.userName.role === 'EMPLOYER'
75
      {props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER'
96 76
      ?
97 77
        <OverviewAdmin employees={employees} setEmployees={setEmployees} />
98 78
      :
99
        <Overview userName={props.userName} employees={employees}  />
79
        <Overview currentUser={props.currentUser} employees={employees}  />
100 80
      }
101 81
    </div>
102 82
  )
client/src/Calendar.js
13 13
function Calendar(props) {
14 14
  
15 15
  useEffect( () => {
16
    if (props.userName.id !== undefined) {
17
      props.userName.role === 'EMPLOYER'
16
    if (props.currentUser !== undefined) {
17
      props.currentUser.role === 'EMPLOYER'
18 18
        ?
19 19
          api_fetch.getAdminCalendar().then(adminCalendar => { 
20 20
            props.setAcceptedRequest(adminCalendar);
......
22 22
            alert(reason)
23 23
          })
24 24
        :
25
          api_fetch.getUserCalendar(props.userName, todayTwo).then(userCalendar => {
25
          api_fetch.getUserCalendar(props.currentUser, convertedDate).then(userCalendar => {
26 26
            props.setAcceptedRequest(userCalendar);
27 27
          }).catch(reason => {
28 28
            alert(reason)
29 29
          });
30 30
    }
31
  }, [props.userName.id]);
31
  }, [props.currentUser]);
32 32

  
33 33
//states
34 34
  const [isOpen, setOpen] = useState(false)
......
43 43

  
44 44
// setting date to right format
45 45
  today = today.toISOString().split('T')[0]
46
  const todayTwo = today.split("-").join("/")
47

  
48
// LOAD DATA from server to calendar **** EMPLOYEE ****
49
  
50
// LOAD DATA from server to calendar **** EMPLOYER ****
46
  const convertedDate = today.split("-").join("/")
51 47

  
52 48
// ********************* ADD EVENT - EMPLOYEE **************************
53 49

  
......
67 63

  
68 64
  await api_fetch.addEventApi(dataAddEventEmployee);
69 65
    if (typeRadio === 'holiday') {
70
      props.setUserName({
71
        ...props.userName,
72
        holiday: props.userName.holiday - whatTime
66
      props.setCurrentUser({
67
        ...props.currentUser,
68
        holiday: props.currentUser.holiday - whatTime
73 69
      })
74 70
    } else if (typeRadio === 'sickday') {
75
      props.setUserName({
76
        ...props.userName,
77
        takenSickday: props.userName.takenSickday + 1
71
      props.setCurrentUser({
72
        ...props.currentUser,
73
        takenSickday: props.currentUser.takenSickday + 1
78 74
      })
79 75
    }
80 76
    
......
100 96

  
101 97
  api_fetch.addEventApiAdmin(dataAddEventAdmin).then(() => {
102 98
    const userProps = {
103
      title: props.userName.name, 
99
      title: props.currentUser.name, 
104 100
      start: whatDate      
105 101
  }
106 102
  //concat new request to current ones
......
117 113
    alert(reason)
118 114
 });
119 115
}
116

  
117
  const DEFAULT_MANDAY_HOURS = 7.5;
118
  
120 119
    
121 120
  return (
122 121
    <div className="calendar">
......
124 123
    <FullCalendar defaultView="dayGridMonth" plugins={[ dayGridPlugin, interactionPlugin ]}
125 124

  
126 125
    dateClick={function(info) {
127
      //setOpen(true === info.dateStr > today ? true : false )
128 126
      setOpen(info.dateStr > today)
129 127
      setDate(info.dateStr)
130
      setWhatTime(7.5)
128
      setWhatTime(DEFAULT_MANDAY_HOURS)
131 129
    }}
132 130
    events={[
133 131
      ...props.acceptedRequest
......
142 140
    onClose={() => setOpen(false)}
143 141
    >
144 142
    <div className="calendar-form">
145
      {/* <form onSubmit={(e) => addEvent(e)}> */}
146
      <form onSubmit={props.userName.role === 'EMPLOYER' 
143
      <form onSubmit={props.currentUser !== undefined && props.currentUser.role === 'EMPLOYER' 
147 144
      ? (e) => addEventAdmin(e)
148 145
      : (e) => addEvent(e)
149 146
      }>
150
        <h2>Choose an option</h2>
147
        <h2>Choose vacation type</h2>
151 148
        <div className="calendar-radio">
152 149
          <input checked={
153 150
            typeRadio === 'sickday' ? 'checked' : null}
......
165 162
          <label for="holiday">Extra Holiday</label>
166 163
        </div>
167 164
        <div>
168
          <h4>Date & Hours</h4>
169
          <div className="row">
165
          {typeRadio === 'holiday' ? <h4>Date & Hours</h4> : <h4>Date</h4>}
166
          <div className="row calendarInputs">
170 167
            <input 
171 168
              className="date-input" 
172 169
              type='date' onChange={(e) => setDate(e.target.value)} 
......
185 182
          /> : null}
186 183
             </div> 
187 184
          </div>
188
        <button className="btn btn-submit" type="submit">Submit</button>
185
        <button className="btn btn-submit" type="submit">Request vacation</button>
189 186
      </form>
190 187
    </div>
191 188
    </Popup>
client/src/LogOut.js
5 5

  
6 6
  return (
7 7
    <div className="login-container logout column">
8
      <h1>You have been successfully logged out!</h1>
9
      <h4>Click to log in</h4>
8
      <p>You have been successfully logged out!</p>
10 9
    </div>
11 10
  )
12 11
}
client/src/Login.js
3 3

  
4 4

  
5 5
function Login() {
6
console.log(window.config)
7 6
  return (
8
    <div className="login-container column">
9
     
10
    <a href={window.config.baseUrl + '/login/google?target=' + window.config.redirectUrl}><h1>log in</h1></a>
11
     
12

  
7
    <div className="login-container column">  
8
    <a href={window.config.baseUrl + '/login/google?target=' + window.config.redirectUrl}><p>log in</p></a>
13 9
    </div>
14 10
  )
15 11
}
client/src/Nav.js
5 5
function Nav(props) {
6 6

  
7 7
  return (
8
    <nav className="top-nav">
9
      <a className="link-nav" href="http://localhost:3000/"><h3>YOSO</h3></a>
10
      <div className="profile-comp">
11
      <img src="https://cataas.com/cat/says/hello%20world!" className="img-avatar" alt="cat"></img>
12
        <h5>{props.userName.name}</h5>
13
          <ul>
14
            {props.userName.role === 'EMPLOYER' ? 
15
            <li>
16
              <Link to="/setting">
17
                <svg className="bi bi-gear-fill navIcon" width="20px" height="20px" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
18
                  <path fillRule="evenodd" d="M8.837 1.626c-.246-.835-1.428-.835-1.674 0l-.094.319A1.873 1.873 0 0 1 4.377 3.06l-.292-.16c-.764-.415-1.6.42-1.184 1.185l.159.292a1.873 1.873 0 0 1-1.115 2.692l-.319.094c-.835.246-.835 1.428 0 1.674l.319.094a1.873 1.873 0 0 1 1.115 2.693l-.16.291c-.415.764.42 1.6 1.185 1.184l.292-.159a1.873 1.873 0 0 1 2.692 1.116l.094.318c.246.835 1.428.835 1.674 0l.094-.319a1.873 1.873 0 0 1 2.693-1.115l.291.16c.764.415 1.6-.42 1.184-1.185l-.159-.291a1.873 1.873 0 0 1 1.116-2.693l.318-.094c.835-.246.835-1.428 0-1.674l-.319-.094a1.873 1.873 0 0 1-1.115-2.692l.16-.292c.415-.764-.42-1.6-1.185-1.184l-.291.159A1.873 1.873 0 0 1 8.93 1.945l-.094-.319zm-2.633-.283c.527-1.79 3.065-1.79 3.592 0l.094.319a.873.873 0 0 0 1.255.52l.292-.16c1.64-.892 3.434.901 2.54 2.541l-.159.292a.873.873 0 0 0 .52 1.255l.319.094c1.79.527 1.79 3.065 0 3.592l-.319.094a.873.873 0 0 0-.52 1.255l.16.292c.893 1.64-.902 3.434-2.541 2.54l-.292-.159a.873.873 0 0 0-1.255.52l-.094.319c-.527 1.79-3.065 1.79-3.592 0l-.094-.319a.873.873 0 0 0-1.255-.52l-.292.16c-1.64.893-3.433-.902-2.54-2.541l.159-.292a.873.873 0 0 0-.52-1.255l-.319-.094c-1.79-.527-1.79-3.065 0-3.592l.319-.094a.873.873 0 0 0 .52-1.255l-.16-.292c-.892-1.64.902-3.433 2.541-2.54l.292.159a.873.873 0 0 0 1.255-.52l.094-.319z"/>
19
                 <path fillRule="evenodd" d="M8 5.754a2.246 2.246 0 1 0 0 4.492 2.246 2.246 0 0 0 0-4.492zM4.754 8a3.246 3.246 0 1 1 6.492 0 3.246 3.246 0 0 1-6.492 0z"/>
20
                </svg>
21
              </Link>
22
            </li>
23
             :  null }
24
            <li>
25
              <Link to="/logout">
26
                <svg className="bi bi-power navIcon" width="20px" height="20px" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
27
                  <path fillRule="evenodd" d="M5.578 4.437a5 5 0 1 0 4.922.044l.5-.866a6 6 0 1 1-5.908-.053l.486.875z"/>
28
                  <path fillRule="evenodd" d="M7.5 8V1h1v7h-1z"/>
29
                </svg>
30
              </Link>
31
            </li>
32
        </ul>
33
      </div>
34
    </nav>
35
  )
36
}
8
    props.currentUser === undefined
9
  ?
10
      <nav className="top-nav">
11
        <Link className="link-nav" to="/"><h1>YOSO</h1></Link>
12
      </nav>
13
  :
14
      <nav className="top-nav">
15
         <Link className="link-nav" to="/"><h1>YOSO</h1></Link>
16
        <div className="profile-comp">
17
        <img src={props.currentUser.photo} className="img-avatar" alt="profile_photo"></img>
18
          <h5>{props.currentUser.name}</h5>
19
            <ul>
20
              {props.currentUser.role === 'EMPLOYER' ? 
21
              <li>
22
                <Link to="/setting">
23
                  <svg className="bi bi-gear-fill navIcon" width="20px" height="20px" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
24
                    <path fillRule="evenodd" d="M8.837 1.626c-.246-.835-1.428-.835-1.674 0l-.094.319A1.873 1.873 0 0 1 4.377 3.06l-.292-.16c-.764-.415-1.6.42-1.184 1.185l.159.292a1.873 1.873 0 0 1-1.115 2.692l-.319.094c-.835.246-.835 1.428 0 1.674l.319.094a1.873 1.873 0 0 1 1.115 2.693l-.16.291c-.415.764.42 1.6 1.185 1.184l.292-.159a1.873 1.873 0 0 1 2.692 1.116l.094.318c.246.835 1.428.835 1.674 0l.094-.319a1.873 1.873 0 0 1 2.693-1.115l.291.16c.764.415 1.6-.42 1.184-1.185l-.159-.291a1.873 1.873 0 0 1 1.116-2.693l.318-.094c.835-.246.835-1.428 0-1.674l-.319-.094a1.873 1.873 0 0 1-1.115-2.692l.16-.292c.415-.764-.42-1.6-1.185-1.184l-.291.159A1.873 1.873 0 0 1 8.93 1.945l-.094-.319zm-2.633-.283c.527-1.79 3.065-1.79 3.592 0l.094.319a.873.873 0 0 0 1.255.52l.292-.16c1.64-.892 3.434.901 2.54 2.541l-.159.292a.873.873 0 0 0 .52 1.255l.319.094c1.79.527 1.79 3.065 0 3.592l-.319.094a.873.873 0 0 0-.52 1.255l.16.292c.893 1.64-.902 3.434-2.541 2.54l-.292-.159a.873.873 0 0 0-1.255.52l-.094.319c-.527 1.79-3.065 1.79-3.592 0l-.094-.319a.873.873 0 0 0-1.255-.52l-.292.16c-1.64.893-3.433-.902-2.54-2.541l.159-.292a.873.873 0 0 0-.52-1.255l-.319-.094c-1.79-.527-1.79-3.065 0-3.592l.319-.094a.873.873 0 0 0 .52-1.255l-.16-.292c-.892-1.64.902-3.433 2.541-2.54l.292.159a.873.873 0 0 0 1.255-.52l.094-.319z"/>
25
                  <path fillRule="evenodd" d="M8 5.754a2.246 2.246 0 1 0 0 4.492 2.246 2.246 0 0 0 0-4.492zM4.754 8a3.246 3.246 0 1 1 6.492 0 3.246 3.246 0 0 1-6.492 0z"/>
26
                  </svg>
27
                </Link>
28
              </li>
29
              :  null }
30
              <li>
31
                <Link to="/logout">
32
                  <svg className="bi bi-power navIcon" width="20px" height="20px" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
33
                    <path fillRule="evenodd" d="M5.578 4.437a5 5 0 1 0 4.922.044l.5-.866a6 6 0 1 1-5.908-.053l.486.875z"/>
34
                    <path fillRule="evenodd" d="M7.5 8V1h1v7h-1z"/>
35
                  </svg>
36
                </Link>
37
              </li>
38
          </ul>
39
        </div>
40
      </nav>
41
    )
42
  }    
37 43

  
38
export default Nav;
39 44

  
40

  
41

  
42
  /*
43
  useEffect(() => {
44
    const data = nactiData();
45
    setName(data.user.name);
46
  }, []);
47

  
48
  function nactiData() {
49
    return {
50
      user: {
51
        name: 'Golstoj Hyhrenciv',
52
      },
53
    };
54
  }
55
  */
45
export default Nav;
client/src/Overview.js
4 4

  
5 5
const OffsAvailable = (props) => {
6 6

  
7
   return (
7
   return props.currentUser === undefined ? null : (
8 8
      <div>
9 9
         <div className="side-content">
10 10
            <div className="side-board column">
......
19 19
                        <th className="th-left">Name</th>
20 20
                        <th>Sick Days</th>
21 21
                        <th>Holiday</th>
22
                     </tr>
22
                     </tr>                     
23 23
                     <tr>
24
                        <td>{props.userName.name}</td>
25
                        <td className="td-center">{props.userName.takenSickday + '/' + props.userName.sickday}</td>
26
                        <td className="td-center">{props.userName.holiday}</td>
24
                        <td>{props.currentUser.name}</td>
25
                        <td className="td-center">{props.currentUser.takenSickday + '/' + props.currentUser.sickday}</td>
26
                        <td className="td-center">{props.currentUser.holiday}</td>
27 27
                     </tr>
28 28
                  </tbody>
29 29
               </table>
30
            </div>
30 31
         </div>
31 32
      </div>
32 33
   </div>
33
   </div>
34 34
   );
35 35
}
36 36

  
client/src/OverviewAdmin.js
13 13
      });
14 14
   }, []);
15 15

  
16
   // states
17
   // const [employees, setEmployees] = useState([
18
   //    {
19
   //       name: 'Sadam',
20
   //       id: 0,
21
   //       sickday: 10,
22
   //       holiday: 10
23
   //    }
24
   // ]);
25

  
26 16
   const [isEdit, setEdit] = useState(false);
27 17
   const [editedUserId, setEditedUserId] = useState();
28 18
   const [prevEdit, setPrevEdit] = useState();
......
98 88
      <div className="side-content">
99 89
         <div className="side-board column">
100 90
            <form className="column side-board-items" onSubmit={(e) => submitEdit(e)}>
101
            {/* <form className="column side-board-items" onSubmit={(e) => submitEdit(e)}> */}
102 91
            <div className="side-board-heading row">
103 92
               <h3>Overview</h3>
104 93
            </div>
client/src/Setting.js
6 6

  
7 7
function Setting() {
8 8

  
9
  const [sickdays, setSickdays] = useState([]);
9
  const [sickdays, setSickdays] = useState();
10 10

  
11 11
  useEffect( () => {
12 12
    api_fetch.getSettingData().then(settingData => {
......
39 39
  function changeSickday(newValue) {
40 40
    setSetting(
41 41
       {sickday: newValue,
42
        holiday: setting.holiday
43
    })
44
  }
45

  
46
  function changeHoliday(newValue) {
47
    setSetting(
48
      {sickday: setting.sickday,
49
       holiday: newValue
42
        holiday: 0
50 43
    })
51 44
  }
52 45

  
53 46
  return (
54 47
    <div className="container">
55 48
      <div className="setting-container column">
56
        <h2>Nastavení</h2>
49
        <h2>Setting</h2>
57 50
        <div className="underline-2"></div>
58 51
        <form onSubmit={(e) => submitSetting(e)} className="setting-form column">
59 52
          <label><h3>Sick days</h3></label>
60 53
          <input onChange={(e) => changeSickday(e.target.value)} value={setting.sickday} type="number" min="0" />
61
          <label><h3>Holiday</h3></label>
62
          <input onChange={(e) => changeHoliday(e.target.value)} value={setting.holiday} type="number" min="0" />
63 54
          <div className="buttons row">
64 55
            <Link to="/"><button className="btn btn-cancel" type="submit" value="Cancel">Cancel</button></Link>
65
            <button className="btn btn-submit" type="submit" value="Submit">Submit</button>
56
            <button className="btn btn-submit" type="submit" value="Submit">Save</button>
66 57
          </div>
67 58
        </form>
68 59
      </div>
client/src/UpcomingRequests.js
2 2
import './App.css';
3 3
import moment from 'moment';
4 4
import * as api_fetch from './api'
5
import convertVacationType from './convertVacationType'
5 6

  
6 7
function UpcomingRequests(props) {
7 8

  
......
14 15
   
15 16
    api_fetch.loadAdminRequests().then((data) => {
16 17
      props.setUser(data.map(request => {
17
      
18
        const a = request.date;
19
        const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
18

  
19
        const convertedStartDate = request.date.split("/").join("-");
20 20
  
21 21
        return (
22 22
          {
23 23
            title: request.firstName + ' ' + request.lastName,
24 24
            id: request.id,
25 25
            type: convertVacationType(request.type),
26
            start: moment(b).format("D.M.YYYY"),
26
            start: moment(convertedStartDate).format("D.M.YYYY"),
27 27
            end: null,
28 28
            status: request.status = request.status.toLowerCase()
29 29
        })
......
33 33
    });
34 34
}
35 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 36

  
47 37
  // send accepted request to server
48 38
  const acceptRequest = async (user) => {
......
57 47
        
58 48
        const userProps = {
59 49
              title: user.title,
60
              id: 0,
61
              type: user.type, 
62
          type: user.type, 
63 50
              type: user.type, 
64 51
              start: user.start
65 52
        }
......
69 56
          props.setUser((pendingRequest) => pendingRequest.filter((item) => item !== user));
70 57
      })
71 58
    } catch (e) {
72
      throw 'error catch GET DATA APP (getCurrentProfile)'
59
      alert(e)
73 60
    }
74 61
  }
75 62

  
......
102 89
      <div className="offs-items column">
103 90
        <div className="offs-item row">
104 91
          <table>
105
            {/* {props.user.length > 0 
106
            ? */}
107 92
            <tbody>
108 93
              <tr>
109 94
                <th>Name</th>
......
122 107
              </tr>
123 108
              ))}
124 109
            </tbody>
125
            {/* :
110
            :
126 111
            <tbody>
127 112
              <p>There are no requests.</p>
128 113
            </tbody>
129
             } */}
130
            
131
          </table>
114
              
115
            </table>
132 116
        </div>
133 117
      </div>
134 118
    </div>
135 119
    )
136 120
  }
137 121

  
138
export default UpcomingRequests;
139

  
140
     
141

  
142

  
143
        // return (shouldRemoveThisItem === true) ? false : true;
144
        //})
145
      //)
146
      // props.setUser((pendingRequest) => pendingRequest.filter(
147
        
148
      //   function(item) {
149
      //   const shouldRemoveThisItem = item === user;
150
        
151
      //   if (shouldRemoveThisItem === true) {
152
      //     return false;
153
      //   } else {
154
      //     return true;
155
      //   }})
156
      // )
122
export default UpcomingRequests;
client/src/YourRequests.js
2 2
import './App.css';
3 3
import moment from 'moment';
4 4
import * as api_fetch from './api'
5
import convertVacationType from './convertVacationType'
5 6

  
6 7
function YourRequests(props) {
7 8

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

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

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

  
17 20
      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('');
21
        const convertedDate = request.date.split("/").join("-");
20 22

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

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

  
46 38
  return (
47 39
    <div className="offs-request column">
48 40
      <h3>Your Requests</h3>
client/src/api.js
7 7
  try {
8 8
    response = await fetch(
9 9
      `${window.config.baseUrl}/users/current/profile`, {
10
        headers: {
11
          Authorization: 1
12

  
13
        },
10
        headers: {},
14 11
        credentials: 'include'
15 12
      }
16 13
    );    
......
27 24
      id: data.id,
28 25
      holiday: data.vacationCount,
29 26
      sickday: data.sickDayCount,
27
      photo: data.photo,
30 28
      takenSickday: data.takenSickDayCount
31 29
    }
32 30
  } else {
33 31
      switch (response.status) {
34 32
        case 401:
35
          window.location.replace("http://localhost:3000/login")
33
          window.location.replace(`/login`)
36 34
          break;
37 35
        case 403:
38
          window.location.replace("http://localhost:3000/login")
36
          window.location.replace(`/login`)
39 37
          break;
40 38
        case 500:
41 39
          throw new Error('Internal server error.')
......
46 44
}
47 45

  
48 46
// ******************** LOAD DATA to CALENDAR - EMPLOYEE ********************
49
export const getUserCalendar = async (userName, fromDate ) => {
47
export const getUserCalendar = async (currentUser, fromDate ) => {
50 48

  
51 49
  let response;
52 50

  
53 51
  try {
54 52
    response = await fetch(
55
      `${window.config.baseUrl}/user/${userName.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
53
      `${window.config.baseUrl}/user/${currentUser.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
56 54
        headers: {
57 55
          'Accept': 'application/json',
58
          Authorization: 6
59 56
        },
60 57
        credentials: 'include',
61 58
        method: 'GET',
......
75 72
    const newDate = day.date.split("/").join("-");
76 73

  
77 74
    return ({
78
      title: userName.name,
75
      title: currentUser.name,
79 76
      start: newDate,
80 77
      backgroundColor: day.status === 'REJECTED' ? 'red' : 'green'
81 78
    })
......
85 82
        case 400:
86 83
          throw new Error('Bad request. Check query parameters.')
87 84
        case 401:
88
          window.location.replace("http://localhost:3000/login")
85
          window.location.replace(`/login`)
89 86
        case 403:
90
          window.location.replace("http://localhost:3000/login")
87
          window.location.replace(`/login`)
91 88
        case 404:
92 89
          throw new Error('User with given ID does not exist.')
93 90
        case 500:
......
109 106
      `${window.config.baseUrl}/users/requests/vacation?status=ACCEPTED`, {
110 107
        headers: {
111 108
          'Accept': 'application/json',
112
          Authorization: 6
113 109
        },
114 110
        credentials: 'include',
115 111
        method: 'GET',
......
136 132
        case 400:
137 133
          throw new Error('Bad request. Check query parameters.')
138 134
        case 401:
139
          window.location.replace("http://localhost:3000/login")
135
          window.location.replace(`/login`)
140 136
        case 403:
141
          window.location.replace("http://localhost:3000/login")
137
          window.location.replace(`/login`)
142 138
        case 500:
143 139
          throw new Error('Internal server error.')
144 140
        default:
......
149 145

  
150 146
// ******************** ADD EVENT to CALENDAR - EMPLOYEE ********************
151 147

  
152
export async function addEventApi(userName, dataAddEventEmployee) {
148
export async function addEventApi(dataAddEventEmployee) {
153 149
  let response;
154 150

  
155 151
  try {
156 152
  // send accepted request to server
157 153
    response = await fetch(`${window.config.baseUrl}/user/calendar/create`, {
158 154
      headers: {
159
        Authorization: 6,
160 155
        'Content-Type': 'application/json',
161 156
      },
162 157
      credentials: 'include',
......
168 163
    throw 'Server is not available'
169 164
  }
170 165

  
171
  if (response.ok) {
172
      
173
    response = await fetch(
174
    `${window.config.baseUrl}/users/requests/vacation?status=PENDING`, {
175
      headers: {
176
        Authorization: 1
177
      },
178
      credentials: 'include',
179
    });
180
    const data = await response.json();
181
      
182
    return data.map(request => {
183
      const a = request.date;
184
      const b = [a.slice(0, 4), "-", a.slice(5, 7), "-", a.slice(8, 10)].join('');
185

  
186
      return (
187
        {
188
          title: request.firstName + ' ' + request.lastName,
189
          id: request.id,
190
          type: request.type,
191
          start: b,
192
          end: null,
193
          status: request.status
194
        })
195
    })
196

  
197
  } else {
166
  if (!response.ok) {
198 167
      switch (response.status) {
199 168
        case 400:
200 169
          throw new Error('Bad request. Check request body.')
201 170
        case 401:
202
          window.location.replace("http://localhost:3000/login")
171
          window.location.replace(`/login`)
203 172
        case 403:
204
          window.location.replace("http://localhost:3000/login")
173
          window.location.replace(`/login`)
205 174
        case 500:
206 175
          throw new Error('Internal server error.')
207 176
        default:
......
219 188
  // send accepted request to server
220 189
    response = await fetch(`${window.config.baseUrl}/user/calendar/create`, {
221 190
      headers: {
222
        Authorization: 1,
223 191
        'Content-Type': 'application/json',
224 192
    },
225 193
    credentials: 'include',
......
236 204
      case 400:
237 205
        throw new Error('Bad request. Check request body.')
238 206
      case 401:
239
        window.location.replace("http://localhost:3000/login")
207
        window.location.replace(`/login`)
240 208
      case 403:
241
        window.location.replace("http://localhost:3000/login")
209
        window.location.replace(`/login`)
242 210
      case 500:
243 211
        throw new Error('Internal server error.')
244 212
      default:
......
255 223
  try {
256 224
  response = await fetch (
257 225
    `${window.config.baseUrl}/users`, {
258
      headers: {
259
        Authorization: 1          
260
      },
261 226
      credentials: 'include',
262 227
    }
263 228
  );
......
284 249
      case 400:
285 250
        throw new Error('Bad request. Check query parameters.')
286 251
      case 401:
287
        window.location.replace("http://localhost:3000/login")
252
        window.location.replace(`/login`)
288 253
      case 403:
289
        window.location.replace("http://localhost:3000/login")
254
        window.location.replace(`/login`)
290 255
      case 500:
291 256
        throw new Error('Internal server error.')
292 257
      default:
......
304 269
    // send accepted request to server
305 270
        response = await fetch(`${window.config.baseUrl}/user/settings`, {
306 271
          headers: {
307
            Authorization: 1,
308 272
            'Content-Type': 'application/json',
309 273
          },
310 274
          credentials: 'include',
......
322 286
      case 400:
323 287
        throw new Error('Bad request. Check query parameters.')
324 288
      case 401:
325
        window.location.replace("http://localhost:3000/login")
289
        window.location.replace(`/login`)
326 290
      case 403:
327
        window.location.replace("http://localhost:3000/login")
291
        window.location.replace(`/login`)
328 292
      case 500:
329 293
        throw new Error('Internal server error.')
330 294
      default:
......
340 304
  try {
341 305
    response = await fetch(
342 306
      `${window.config.baseUrl}/settings`, {
343
        headers: {
344
          Authorization: 1
345
        },
346 307
        credentials: 'include',
347 308
      }
348 309
    );
......
374 335
  try {
375 336
    response = await fetch(`${window.config.baseUrl}/settings`, {
376 337
      headers: {
377
        'Authorization': 1,
378 338
        'Content-Type': 'application/json'
379 339
      },
380 340
      credentials: 'include',
......
388 348
  if (!response.ok) {
389 349
    switch (response.status) {
390 350
      case 401:
391
        window.location.replace("http://localhost:3000/login")
351
        window.location.replace(`/login`)
392 352
      case 403:
393
        window.location.replace("http://localhost:3000/login")
353
        window.location.replace(`/login`)
394 354
      case 500:
395 355
        throw new Error('Internal server error.')
396 356
      default:
......
401 361

  
402 362
// ****************** LOAD DATA to YOUR REQUESTS - EMPLOYEE ******************
403 363

  
404
export async function loadYourRequests(userName) {
364
export async function loadYourRequests(currentUser) {
405 365
  let response;
406 366
  
407 367
  try {
408 368
    response = await fetch(
409
      `${window.config.baseUrl}/user/${userName.id}/calendar?from=2020/06/24&status=PENDING`, {
410
        headers: {
411
          Authorization: 6
412
        },
369
      `${window.config.baseUrl}/user/${currentUser.id}/calendar?from=2020/06/24&status=PENDING`, {
413 370
        credentials: 'include',
414 371
      }
415 372
    );
......
425 382
        case 400:
426 383
          throw new Error('Bad request. Check query parameters.')
427 384
        case 401:
428
          window.location.replace("http://localhost:3000/login")
385
          window.location.replace(`/login`)
429 386
        case 403:
430
          window.location.replace("http://localhost:3000/login")
387
          window.location.replace(`/login`)
431 388
        case 500:
432 389
          throw new Error('Internal server error.')
433 390
        default:
......
443 400
  try {
444 401
    response = await fetch(
445 402
      `${window.config.baseUrl}/users/requests/vacation?status=PENDING`, {
446
        headers: {
447
          Authorization: 1
448
        },
449 403
        credentials: 'include',
450 404
      },
451 405
    );
......
461 415
        case 400:
462 416
          throw new Error('Bad request. Check query parameters.')
463 417
        case 401:
464
          window.location.replace("http://localhost:3000/login")
418
          window.location.replace(`/login`)
465 419
        case 403:
466
          window.location.replace("http://localhost:3000/login")
420
          window.location.replace(`/login`)
467 421
        case 500:
468 422
          throw new Error('Internal server error.')
469 423
        default:
......
480 434
  try {
481 435
    response = await fetch(`${window.config.baseUrl}/user/requests?type=VACATION`, {
482 436
      headers: {
483
        Authorization: 1,
484 437
        'Content-Type': 'application/json',
485 438
      },
486 439
      credentials: 'include',
......
496 449
      case 400:
497 450
        throw new Error('Bad request. Check query parameters and request body.')
498 451
      case 401:
499
        window.location.replace("http://localhost:3000/login")
452
        window.location.replace(`/login`)
500 453
      case 403:
501
        window.location.replace("http://localhost:3000/login")
454
        window.location.replace(`/login`)
502 455
      case 404:
503 456
        throw new Error('Neither vacation nor authorization request with given ID exists.')
504 457
      case 500:
......
517 470
  try {
518 471
    response = await fetch(`${window.config.baseUrl}/user/requests?type=VACATION`, {
519 472
      headers: {
520
        Authorization: 1,
521 473
        'Content-Type': 'application/json',
522 474
      },
523 475
      credentials: 'include',
......
533 485
      case 400:
534 486
        throw new Error('Bad request. Check query parameters and request body.')
535 487
      case 401:
536
        window.location.replace("http://localhost:3000/login")
488
        window.location.replace(`/login`)
537 489
      case 403:
538
        window.location.replace("http://localhost:3000/login")
490
        window.location.replace(`/login`)
539 491
      case 404:
540 492
        throw new Error('Neither vacation nor authorization request with given ID exists.')
541 493
      case 500:
client/src/convertVacationType.js
1
function convertVacationType(vacationType) {
2
    switch (vacationType) {
3
      case 'SICK_DAY' :
4
        return 'sickday';
5
      default:
6
        return 'holiday';
7
    }
8
  }
9
  
10
  export default convertVacationType;

Také k dispozici: Unified diff