2020-08-14 11:54:36 +00:00
|
|
|
import React, { useState } 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,
|
|
|
|
FormControl,
|
|
|
|
ControlLabel,
|
|
|
|
Button,
|
|
|
|
ButtonGroup,
|
|
|
|
Message,
|
|
|
|
FormGroup,
|
|
|
|
} from 'rsuite';
|
|
|
|
|
2020-08-21 23:08:18 +00:00
|
|
|
import { NavBar, TimezonePicker, IntervalSelector } from '../components';
|
|
|
|
import './styles/Availability.less';
|
|
|
|
import './styles/layout.less';
|
2020-06-03 09:14:04 +00:00
|
|
|
|
2020-08-23 14:30:25 +00:00
|
|
|
export default function Availability({ possibleDates, currentUser }) {
|
2020-08-22 22:28:05 +00:00
|
|
|
const [availability, setAvailability] = useState([]);
|
2020-06-09 14:07:07 +00:00
|
|
|
|
2020-08-23 14:30:25 +00:00
|
|
|
console.log(currentUser)
|
|
|
|
console.log(possibleDates)
|
|
|
|
//TODO post intervals to backend
|
|
|
|
|
2020-06-03 09:14:04 +00:00
|
|
|
const handleClear = () => {
|
|
|
|
setAvailability([]);
|
|
|
|
};
|
|
|
|
|
2020-06-09 14:07:07 +00:00
|
|
|
const handleSelect = ({ start, end }) => {
|
|
|
|
let updatedEvents = [];
|
|
|
|
let newAvailability = {
|
|
|
|
start: start,
|
|
|
|
end: end,
|
|
|
|
};
|
|
|
|
updatedEvents.push(newAvailability);
|
2020-08-23 14:30:25 +00:00
|
|
|
|
|
|
|
// console.log("NEW AVAILABILITY UNIX EPOCH: ", Math.floor(newAvailability.start / 1000))
|
2020-06-09 14:07:07 +00:00
|
|
|
setAvailability([...availability, ...updatedEvents]);
|
2020-06-03 09:14:04 +00:00
|
|
|
};
|
|
|
|
|
2020-08-23 14:30:25 +00:00
|
|
|
const handleSubmit = () => {
|
|
|
|
console.log(availability);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!possibleDates) {
|
|
|
|
return <Redirect to='/schedule' />;
|
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>
|
|
|
|
<FormControl name='earliest-time' type='text' />
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup>
|
|
|
|
<ControlLabel>Latest time</ControlLabel>
|
|
|
|
<FormControl name='latest-time' type='text' />
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup className='av-timezone'>
|
|
|
|
<ControlLabel>Timezone</ControlLabel>
|
|
|
|
<TimezonePicker />
|
|
|
|
</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}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Form>
|
|
|
|
</Panel>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|