Schedule.js 3.25 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";
Kim, Subin's avatar
Kim, Subin committed
6
7
8
9
import moment from 'moment';

function Cal(props) {
  const calendarRef = useRef(null);
Lee Jin Ju's avatar
Lee Jin Ju committed
10
11
12
  const [myTheme, setMyTheme] = useState({
    'common.dayname.color': '#333',
    'common.today.color': '#333',
Kim, Subin's avatar
Kim, Subin committed
13
14
15
    // 'common.creationGuide.color': 'white',
    'common.creationGuide.backgroundColor': 'gray',
    // Theme object to extends default dark theme.
Lee Jin Ju's avatar
Lee Jin Ju committed
16
17
  });

Kim, Subin's avatar
Kim, Subin committed
18
19
20
  function getDataAction(target) {
    return target.dataset ? target.dataset.action : target.getAttribute('data-action');
  }
Kim, Subin's avatar
Kim, Subin committed
21

Kim, Subin's avatar
Kim, Subin committed
22
23
24
  function onClickNavi(e) {
    const cal = calendarRef.current.getInstance();
    const action = getDataAction(e.target);
Kim, Subin's avatar
Kim, Subin committed
25

Kim, Subin's avatar
Kim, Subin committed
26
27
28
29
30
31
32
33
34
35
36
37
38
    switch (action) {
      case 'move-prev':
        cal.prev();
        break;
      case 'move-next':
        cal.next();
        break;
      case 'move-today':
        cal.today();
        break;
      default:
        return;
    }
Kim, Subin's avatar
Kim, Subin committed
39

Kim, Subin's avatar
Kim, Subin committed
40
41
    setRenderRangeText();
  }
Kim, Subin's avatar
Kim, Subin committed
42

Kim, Subin's avatar
Kim, Subin committed
43
44
45
46
47
48
49
50
51
52
53
  function setRenderRangeText() {
    const cal = calendarRef.current.getInstance();
    const renderRange = document.getElementById('renderRange');
    let html = [];
    html.push(moment(cal.getDateRangeStart().getTime()).format('YYYY.MM.DD'));
    html.push(' ~ ');
    html.push(moment(cal.getDateRangeEnd().getTime()).format(' MM.DD'));
    renderRange.innerHTML = html.join('');
    console.log(html)
    // cal.render();
  }
Kim, Subin's avatar
Kim, Subin committed
54

Kim, Subin's avatar
Kim, Subin committed
55
56
57
  useEffect(() => {
    setRenderRangeText()
  }, [])
Lee Jin Ju's avatar
Lee Jin Ju committed
58
59

  return (
Kim, Subin's avatar
Kim, Subin committed
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
110
111
112
113
114
    <div>
      <div id="menu" >
        <span id="menu-navi" onClick={(e) => onClickNavi(e)}>
          <button type="button" className="btn btn-default btn-sm move-today" data-action="move-today">Today</button>
          <button type="button" className="btn btn-default btn-sm move-day" data-action="move-prev">
            <i class="calendar-icon ic-arrow-line-left" data-action="move-prev"></i>
          </button>
          <button type="button" className="btn btn-default btn-sm move-day" data-action="move-next">
            <i className="calendar-icon ic-arrow-line-right" data-action="move-next"></i>
          </button>
        </span>
        <span id="renderRange" className="render-range"></span>
      </div>

      <Calendar
        ref={calendarRef}
        height="100%"
        calendars={[
          {
            id: 'Subject',
            bgColor: '#a9a9a9',
            borderColor: '#a9a9a9',
            isReadOnly: 'true'
          }
        ]}
        view="week"
        disableDblClick={false}
        disableClick={true}
        isReadOnly={true}
        // template={
        //   popupIsAllDay=function {
        //     return display: "none"
        //   }
        // }
        schedules={props.schedules}
        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
        }}
      />
    </div>
Lee Jin Ju's avatar
Lee Jin Ju committed
115
116
117
118
  )
}

export default Cal