import React, { useState, useEffect } from 'react'; import { Redirect } from 'react-router-dom'; import { Panel, Form, ControlLabel, Button, ButtonGroup, Message, FormGroup, } from 'rsuite'; import { NavBar, TimezonePicker, TimePicker, IntervalSelector, } from '../components'; import './styles/Availability.less'; import './styles/layout.less'; // DEV possibleDates const possibleDates = [ { id: 63, start: '2020-08-01', display: 'background', }, { id: 64, start: '2020-08-02', display: 'background', }, ]; export default function Availability({ currentUser }) { const [availability, setAvailability] = useState([]); const [timezone, setTimezone] = useState(currentUser.timezone); const [times, setTimes] = useState({ earliest: currentUser.earliest_time, latest: currentUser.latest_time, }); const handleClear = () => { setAvailability([]); }; const handleSelect = ({ start, end }) => { setAvailability([ ...availability, { start: start, end: end, }, ]); }; const handleSubmit = () => { //TODO post intervals to backend // Post it as UNIX EPOCH TIME // timezone = UTC always // Use Map to add id to events // // Find corresponding id // const selectedDate = start.toISOString().substring(0, 10); // const [date] = possibleDates.filter( // (date) => date.start === selectedDate, // ); console.log(availability); }; const handleSelectTimezone = (value, item, event) => { setTimezone(item.timezone); }; const handleClearTimezone = () => { setTimezone(currentUser.timezone); }; const handleEarliest = (value, item, event) => { setTimes({ ...times, earliest: value, }); }; const handleLatest = (value, item, event) => { setTimes({ ...times, latest: value, }); }; if (!possibleDates) { return ; } return ( <> Earliest time Latest time Timezone handleClear()} > Clear selection Save your availability > ); }