frontend/src/screens/Availability.js

110 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-08-14 11:54:36 +00:00
import React, { useState } from 'react';
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
export default function Availability({ possibleDates, currentUser }) {
const [availability, setAvailability] = useState([]);
2020-06-09 14:07:07 +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);
// 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
};
const handleSubmit = () => {
console.log(availability);
};
if (!possibleDates) {
return <Redirect to='/schedule' />;
}
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}
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'
description='Select your availability on the calendar.'
2020-06-03 09:14:04 +00:00
/>
<IntervalSelector
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>
</>
);
}