import React, { useEffect, useState } from "react"; import TimezoneSelect from "react-timezone-select"; import { TrashIcon } from "@heroicons/react/outline"; import { WeekdaySelect } from "./WeekdaySelect"; import SetTimesModal from "./modal/SetTimesModal"; import Schedule from "../../lib/schedule.model"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; import timezone from "dayjs/plugin/timezone"; dayjs.extend(utc); dayjs.extend(timezone); export const Scheduler = (props) => { const [schedules, setSchedules]: Schedule[] = useState( props.schedules.map((schedule) => { const startDate = schedule.isOverride ? dayjs(schedule.startDate) : dayjs.utc().startOf("day").add(schedule.startTime, "minutes").tz(props.timeZone); return { days: schedule.days, startDate, endDate: startDate.add(schedule.length, "minutes"), }; }) ); const [timeZone, setTimeZone] = useState(props.timeZone); const [editSchedule, setEditSchedule] = useState(-1); useEffect(() => { props.onChange(schedules); }, [schedules]); const addNewSchedule = () => setEditSchedule(schedules.length); const applyEditSchedule = (changed: Schedule) => { const replaceWith = { ...schedules[editSchedule], ...changed, }; schedules.splice(editSchedule, 1, replaceWith); setSchedules([].concat(schedules)); }; const removeScheduleAt = (toRemove: number) => { schedules.splice(toRemove, 1); setSchedules([].concat(schedules)); }; const setWeekdays = (idx: number, days: number[]) => { schedules[idx].days = days; setSchedules([].concat(schedules)); }; return (
    {schedules.map((schedule, idx) => (
  • setWeekdays(idx, days)} />
  • ))}

{/*

Add date overrides

Add dates when your availability changes from your weekly hours

*/}
{editSchedule >= 0 && ( setEditSchedule(-1)} /> )} {/*{showDateOverrideModal && }*/}
); };