2020-08-26 18:13:12 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2020-08-22 22:28:05 +00:00
|
|
|
import { Redirect } from 'react-router-dom';
|
|
|
|
|
2020-06-03 09:14:04 +00:00
|
|
|
import {
|
|
|
|
Panel,
|
|
|
|
Form,
|
|
|
|
ControlLabel,
|
|
|
|
Button,
|
|
|
|
ButtonGroup,
|
|
|
|
Message,
|
|
|
|
FormGroup,
|
|
|
|
} from 'rsuite';
|
|
|
|
|
2020-08-26 18:13:12 +00:00
|
|
|
import {
|
|
|
|
NavBar,
|
|
|
|
TimezonePicker,
|
|
|
|
TimePicker,
|
|
|
|
IntervalSelector,
|
|
|
|
} from '../components';
|
2020-08-21 23:08:18 +00:00
|
|
|
import './styles/Availability.less';
|
|
|
|
import './styles/layout.less';
|
2020-06-03 09:14:04 +00:00
|
|
|
|
2020-08-26 18:13:12 +00:00
|
|
|
// DEV possibleDates
|
|
|
|
const possibleDates = [
|
|
|
|
{
|
|
|
|
id: 63,
|
|
|
|
start: '2020-08-01',
|
|
|
|
display: 'background',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 64,
|
|
|
|
start: '2020-08-02',
|
|
|
|
display: 'background',
|
|
|
|
},
|
|
|
|
];
|
2020-06-09 14:07:07 +00:00
|
|
|
|
2020-08-26 18:13:12 +00:00
|
|
|
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,
|
|
|
|
});
|
2020-08-23 14:30:25 +00:00
|
|
|
|
2020-06-03 09:14:04 +00:00
|
|
|
const handleClear = () => {
|
|
|
|
setAvailability([]);
|
|
|
|
};
|
|
|
|
|
2020-06-09 14:07:07 +00:00
|
|
|
const handleSelect = ({ start, end }) => {
|
2020-08-26 18:13:12 +00:00
|
|
|
setAvailability([
|
|
|
|
...availability,
|
|
|
|
{
|
|
|
|
start: start,
|
|
|
|
end: end,
|
|
|
|
},
|
|
|
|
]);
|
2020-06-03 09:14:04 +00:00
|
|
|
};
|
|
|
|
|
2020-08-23 14:30:25 +00:00
|
|
|
const handleSubmit = () => {
|
2020-08-26 18:13:12 +00:00
|
|
|
//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,
|
|
|
|
// );
|
|
|
|
|
2020-08-23 14:30:25 +00:00
|
|
|
console.log(availability);
|
|
|
|
};
|
|
|
|
|
2020-08-26 18:13:12 +00:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-08-23 14:30:25 +00:00
|
|
|
if (!possibleDates) {
|
2020-08-26 18:13:12 +00:00
|
|
|
return <Redirect to='/dashboard' />;
|
2020-08-22 22:28:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 09:14:04 +00:00
|
|
|
return (
|
|
|
|
<>
|
2020-08-19 18:04:52 +00:00
|
|
|
<NavBar title='Add your availability' />
|
2020-08-21 23:08:18 +00:00
|
|
|
<Panel className={'app-container'}>
|
2020-06-03 09:14:04 +00:00
|
|
|
<Form className={'av-container'}>
|
|
|
|
<div className={'av-details'}>
|
|
|
|
<FormGroup>
|
|
|
|
<ControlLabel>Earliest time</ControlLabel>
|
2020-08-26 18:13:12 +00:00
|
|
|
<TimePicker
|
|
|
|
time={times.earliest}
|
|
|
|
handleSelect={handleEarliest}
|
|
|
|
/>
|
2020-06-03 09:14:04 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<ControlLabel>Latest time</ControlLabel>
|
2020-08-26 18:13:12 +00:00
|
|
|
<TimePicker
|
|
|
|
time={times.latest}
|
|
|
|
handleSelect={handleLatest}
|
|
|
|
/>
|
2020-06-03 09:14:04 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup className='av-timezone'>
|
|
|
|
<ControlLabel>Timezone</ControlLabel>
|
2020-08-26 18:13:12 +00:00
|
|
|
<TimezonePicker
|
|
|
|
timezone={timezone}
|
|
|
|
handleSelect={handleSelectTimezone}
|
|
|
|
handleClean={handleClearTimezone}
|
|
|
|
/>
|
2020-06-03 09:14:04 +00:00
|
|
|
</FormGroup>
|
|
|
|
<div className='av-controls'>
|
|
|
|
<ButtonGroup justified>
|
|
|
|
<Button
|
|
|
|
appearance='ghost'
|
|
|
|
block
|
|
|
|
size='lg'
|
|
|
|
disabled={availability.length === 0}
|
|
|
|
onClick={() => handleClear()}
|
|
|
|
>
|
|
|
|
Clear selection
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
appearance='primary'
|
|
|
|
size='lg'
|
|
|
|
block
|
|
|
|
disabled={availability.length === 0}
|
2020-08-23 14:30:25 +00:00
|
|
|
onClick={handleSubmit}
|
2020-06-03 09:14:04 +00:00
|
|
|
>
|
|
|
|
Save your availability
|
|
|
|
</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={'interval-selector'}>
|
|
|
|
<Message
|
|
|
|
showIcon
|
|
|
|
type='info'
|
2020-08-22 22:28:05 +00:00
|
|
|
description='Select your availability on the calendar.'
|
2020-06-03 09:14:04 +00:00
|
|
|
/>
|
|
|
|
<IntervalSelector
|
2020-08-22 22:28:05 +00:00
|
|
|
selectedDates={possibleDates}
|
2020-06-09 14:07:07 +00:00
|
|
|
availability={availability}
|
|
|
|
setAvailability={setAvailability}
|
2020-06-03 09:14:04 +00:00
|
|
|
handleSelect={handleSelect}
|
|
|
|
handleClear={handleClear}
|
2020-08-26 18:13:12 +00:00
|
|
|
slotMinTime={times.earliest}
|
|
|
|
slotMaxTime={times.latest}
|
2020-06-03 09:14:04 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</Panel>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|