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/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>

Také k dispozici: Unified diff