Schedule.js 7.18 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
Lee Jin Ju's avatar
Lee Jin Ju committed
2
3
4
5
import Calendar from '@toast-ui/react-calendar';
import "tui-calendar/dist/tui-calendar.css";
import "tui-date-picker/dist/tui-date-picker.css";
import "tui-time-picker/dist/tui-time-picker.css";
6
<<<<<<< HEAD
Lee Jin Ju's avatar
   
Lee Jin Ju committed
7

Kim, Subin's avatar
Kim, Subin committed
8
function Cal(calledday) {
9
=======
CHAERIN KIM's avatar
CHAERIN KIM committed
10
11
12
import axios from 'axios';

function Cal(props) {
13
>>>>>>> origin/cherry
Kim, Subin's avatar
Kim, Subin committed
14
  const calendarRef = useRef();
CHAERIN KIM's avatar
CHAERIN KIM committed
15
16
17
  const [reserve, setReserve] = useState([]);
  // const [day, setDay] = useState(props.calledday);
  const [day, setDay] = useState(props.day);
Lee Jin Ju's avatar
Lee Jin Ju committed
18
19
20
  const [myTheme, setMyTheme] = useState({
    'common.dayname.color': '#333',
    'common.today.color': '#333',
Kim, Subin's avatar
Kim, Subin committed
21
22
23
    // 'common.creationGuide.color': 'white',
    'common.creationGuide.backgroundColor': 'gray',
    // Theme object to extends default dark theme.
Lee Jin Ju's avatar
Lee Jin Ju committed
24
25
  });

26
<<<<<<< HEAD
Lee Jin Ju's avatar
   
Lee Jin Ju committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  function getDataAction(target) {
    return target.dataset ? target.dataset.action : target.getAttribute('data-action');
  }

  function onClickNavi(e) {
    const cal = calendarRef.current.getInstance();
    const action = getDataAction(e.target);
  
    switch (action) {
      case 'move-prev':
        cal.prev();
        break;
      case 'move-next':
        cal.next();
        break;
      case 'move-today':
        cal.today();
        break;
      default:
        return;
    }
  
    // setRenderRangeText();
    // setSchedules();
  }

  function useday(day) {
    const cal = calendarRef.current.getInstance();
    cal.setDate(new Date(day));
    cal.changeView('week', true);
    cal.today(new Date(day));
58
=======
CHAERIN KIM's avatar
CHAERIN KIM committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
  const yj = [
    {
      id: 'a',
      calendarId: 'Subject',
      category: 'time',
      start: '2020-10-27T11:00:00',
      end: '2020-10-27T12:00:00',
    },
    {
      id: 'b',
      calendarId: 'Subject',
      category: 'time',
      start: '2020-10-28T10:00:00',
      end: '2020-10-28T11:00:00',
    },
    {
      id: '3',
      calendarId: 'Subject',
      category: 'time',
      start: '2020-10-29T11:00:00',
      end: '2020-10-29T15:00:00',
    }
  ]

  function getReserve(room) {
    console.log("room", room)
    // setReserve({
    //   id: room,
    //   calendarId: 'Subject',
    //   category: 'time',
    // })

    axios.get(`/reserves/room/${room}`, {
      headers: { authorization: localStorage.getItem('token') },
    })
      .then(res => {
        const reserves = res.data.map(item => ({
          id: item._id,
          start: item.start,
          end: item.end,
          calendarId: 'Subject',
          category: 'time',
        }))
        console.log("room list", res.data);

        setReserve(reserves);
        // console.log("room list",res.data);
      })
      .catch(err => {
        alert(err.error)
      });
110
>>>>>>> origin/cherry
Lee Jin Ju's avatar
   
Lee Jin Ju committed
111
112
  }

Kim, Subin's avatar
Kim, Subin committed
113
  useEffect(() => {
Lee Jin Ju's avatar
오앙    
Lee Jin Ju committed
114
115
116
    // const cal = calendarRef.current.getInstance();
    // cal.setDate(new Date(day));
    // cal.changeView('week', false);
Kim, Subin's avatar
Kim, Subin committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    // cal.today(new Date(day));

    // calendar.on('clickSchedule', function (event) {
    //   const schedule = event.schedule;

    //   if (lastClickSchedule) {
    //     calendar.updateSchedule(lastClickSchedule.id, lastClickSchedule.calendarId, {
    //       isFocused: false,
    //     });
    //   }
    //   calendar.updateSchedule(schedule.id, schedule.calendarId, {
    //     isFocused: true,
    //   });

    //   lastClickSchedule = schedule;
    //   // open detail view

    //   return (console.log(isFocused))
    // });

CHAERIN KIM's avatar
CHAERIN KIM committed
137
138
139
140
141
142
143
144
145
146
    // setReserve([
    //   {
    //         id: '3',
    //         calendarId: 'Subject',
    //         category: 'time',
    //         start: '2020-10-29T11:00:00',
    //         end: '2020-10-29T15:00:00',
    //       }
    // ])
    getReserve(props.room);
Kim, Subin's avatar
Kim, Subin committed
147
  }, [day])
Lee Jin Ju's avatar
Lee Jin Ju committed
148
149

  return (
150
<<<<<<< HEAD
Lee Jin Ju's avatar
   
Lee Jin Ju committed
151
152
153
154
155
156
157
    <div className="container mt-3">
    <div class="tui-datepicker-input tui-datetime-input tui-has-focus">
    <input type="text" id="datepicker-input" aria-label="Date-Time"></input>
    <span class="tui-ico-date"></span>
</div>
<div id="wrapper" style="margin-top: -1px;"></div>

Lee Jin Ju's avatar
Lee Jin Ju committed
158
    <Calendar
Lee Jin Ju's avatar
   
Lee Jin Ju committed
159
      ref={calendarRef}
Lee Jin Ju's avatar
Lee Jin Ju committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
      height="100%"
      calendars={[
        {
          id: 'Subject',
          bgColor: '#a9a9a9',
          borderColor: '#a9a9a9',
          isReadOnly: 'true'
        }
      ]}
      
      view="week"
      disableDblClick={false}
      disableClick={true}
      isReadOnly={false}
174
            // template={
Kim, Subin's avatar
Kim, Subin committed
175
176
177
178
      //   popupIsAllDay=function {
      //     return display: "none"
      //   }
      // }
Lee Jin Ju's avatar
Lee Jin Ju committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
      schedules={[
        {
          id: '1',
          calendarId: 'Subject',
          category: 'time',
          start: '2020-10-05T11:00:00',
          end: '2020-10-05T12:00:00',
        },
        {
          id: '2',
          calendarId: 'Subject',
          category: 'time',
          start: '2020-10-09T10:00:00',
          end: '2020-10-09T11:00:00',
        },
        {
          id: '3',
          calendarId: 'Subject',
          category: 'time',
          start: '2020-10-08T11:00:00',
          end: '2020-10-08T15:00:00',
        }
      ]}
      scheduleView={['time']}
      taskView={false}
      theme={myTheme}
      timezones={[
        {
          timezoneOffset: 540,
          displayLabel: 'GMT+09:00',
          tooltip: 'Seoul'
        },
      ]}
      useDetailPopup
      useCreationPopup
Kim, Subin's avatar
Kim, Subin committed
214
      view={"week"}
Lee Jin Ju's avatar
Lee Jin Ju committed
215
      week={{
Kim, Subin's avatar
Kim, Subin committed
216
        workweek: true,
Lee Jin Ju's avatar
Lee Jin Ju committed
217
        hourStart: 8,
Kim, Subin's avatar
Kim, Subin committed
218
        hourEnd: 23
Lee Jin Ju's avatar
Lee Jin Ju committed
219
220
      }}
    />
221
=======
CHAERIN KIM's avatar
CHAERIN KIM committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    <div>{
      console.log("reserve", reserve)}
      <Calendar
        height="100%"
        calendars={[
          {
            id: 'Subject',
            bgColor: '#a9a9a9',
            borderColor: '#a9a9a9',
            isReadOnly: 'true'
          }
        ]}

        view="week"
        disableDblClick={false}
        disableClick={true}
        isReadOnly={false}
        // template={
        //   popupIsAllDay=function {
        //     return display: "none"
        //   }
        // }
        schedules={ reserve
          // reserve.map(item=>({id: item._id,
          //   start: item.start,
          //   end: item.end,
          //   calendarId: 'Subject',
          //   category: 'time',}))
          // [
          //   {
          //     id: 'a',
          //     calendarId: 'Subject',
          //     category: 'time',
          //     start: '2020-10-27T11:00:00',
          //     end: '2020-10-27T12:00:00',
          //   },
          //   {
          //     id: 'b',
          //     calendarId: 'Subject',
          //     category: 'time',
          //     start: '2020-10-28T10:00:00',
          //     end: '2020-10-28T11:00:00',
          //   },
          //   {
          //     id: '3',
          //     calendarId: 'Subject',
          //     category: 'time',
          //     start: '2020-10-29T11:00:00',
          //     end: '2020-10-29T15:00:00',
          //   }
          // ]
Lee Jin Ju's avatar
Lee Jin Ju committed
273
        }
CHAERIN KIM's avatar
CHAERIN KIM committed
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
        scheduleView={['time']}
        taskView={false}
        theme={myTheme}
        timezones={[
          {
            timezoneOffset: 540,
            displayLabel: 'GMT+09:00',
            tooltip: 'Seoul'
          },
        ]}
        useDetailPopup
        useCreationPopup
        view={"week"}
        week={{
          workweek: true,
          hourStart: 8,
          hourEnd: 23
        }}
      />
293
>>>>>>> origin/cherry
Lee Jin Ju's avatar
   
Lee Jin Ju committed
294
    </div>
Lee Jin Ju's avatar
Lee Jin Ju committed
295
296
297
298
  )
}

export default Cal