DateView.js 1.88 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
2
3
4
import { useEffect, useRef } from "react";
import { useHistory, useParams } from "react-router-dom";
import moment from 'moment';
import FullCalendar from '@fullcalendar/react';
Kim, Subin's avatar
Kim, Subin committed
5
import customViewPlugin from "./CustomView.js";
Kim, Subin's avatar
Kim, Subin committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import bootstrapPlugin from '@fullcalendar/bootstrap';
import '@fortawesome/fontawesome-free/css/all.css';

const DateView = ({ }) => {
    const calendarRef = useRef(null)
    const { date } = useParams()
    const history = useHistory()
    let calendar = null

    useEffect(() => {
        if (calendarRef && calendarRef.current) {
            calendar = calendarRef.current.getApi()
        }
    })

    return (
        <FullCalendar
            ref={calendarRef}
            plugins={[bootstrapPlugin, customViewPlugin]}
Kim, Subin's avatar
Kim, Subin committed
25
26
            initialView="date"
            initialDate={date}
Kim, Subin's avatar
Kim, Subin 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
58
59
60
            headerToolbar={{
                start: 'prev',
                center: 'myCustomButton',
                end: 'next'
            }}
            customButtons={{
                myCustomButton: {
                    text: moment(date).format("MM.DD"),
                    click: () => history.push("/home")
                },
                prev: {
                    icon: "fa-chevron-left",
                    click: () => {
                        calendar.prev()
                        let date = moment(calendar.getDate()).format('YYYY-MM-DD')
                        history.push(`/schedule/${date}`)
                    }
                },
                next: {
                    icon: "fa-chevron-right",
                    click: () => {
                        calendar.next()
                        let date = moment(calendar.getDate()).format('YYYY-MM-DD')
                        history.push(`/schedule/${date}`)
                    }
                }
            }}
            timeZone="local"
            themeSystem='bootstrap'
        />
    )
}

export default DateView