import { useState, useEffect, useRef } from "react"; import { useHistory } from "react-router-dom"; import CalendarBtn from "../Buttons/CalendarBtn"; import DatePickerModal from "../Modal/DatePickerModal"; import scheduleApi from "../../apis/schedule.api"; import { useAuth } from "../../utils/context"; import catchErrors from "../../utils/catchErrors"; import moment from 'moment'; import FullCalendar from '@fullcalendar/react'; import dayGridPlugin from '@fullcalendar/daygrid'; import interactionPlugin from "@fullcalendar/interaction"; import bootstrapPlugin from '@fullcalendar/bootstrap'; import '@fortawesome/fontawesome-free/css/all.css'; const Monthly = () => { const { user } = useAuth() console.log("msds==",user) const [initialDate, setInitialDate] = useState(moment().format('YYYY-MM-DD')) const [changeDate, setChangeDate] = useState(moment().format('YYYY-MM-DD')) const [show, setShow] = useState(false) const [scheduleList, setScheduleList] = useState([]) const [error, setError] = useState("") const calendarRef = useRef(null) const calenIconRef = useRef(null) let calendar = null const history = useHistory(); useEffect(() => { if (calendarRef && calendarRef.current) { calendar = calendarRef.current.getApi() } }) useEffect(() => { if (calenIconRef && calenIconRef.current) { calenIconRef.current.addEventListener('click', () => { calendar.today() let date = moment(calendar.getDate()).format('YYYY-MM-DD') setChangeDate(date) }) } return () => { if (calenIconRef && calenIconRef.current) { calenIconRef.current.removeEventListener('click', () => { calendar.today() let date = moment(calendar.getDate()).format('YYYY-MM-DD') setChangeDate(date) }) } } }, [calenIconRef.current]) useEffect(() => { calendar.gotoDate(changeDate) getAll() }, [changeDate]) useEffect(() => { calendar.addEventSource(scheduleList) }, [scheduleList]) async function getAll() { try { setError("") console.log("home user",user) const resList = await scheduleApi.getbyMonth(changeDate, user.id) setScheduleList(resList) } catch (error) { catchErrors(error, setError) } } return ( <> {console.log("user scheduleList==",scheduleList)}