Implement availibility to the backend

This commit is contained in:
rui hildt 2020-08-28 11:50:22 +02:00
parent 2aefdefb77
commit 1e85a8423d
2 changed files with 82 additions and 41 deletions

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Redirect } from 'react-router-dom';
import { Redirect, useHistory } from 'react-router-dom';
import {
Panel,
Form,
@ -20,7 +20,6 @@ import dtToUTC from '../helpers/datetimeToUTC';
import { backend } from '../helpers/http-common';
import './styles/Availability.less';
import './styles/layout.less';
// // DEV possibleDates
// const possibleDates = [
// {
@ -52,6 +51,13 @@ export default function Availability({
earliest: currentUser.earliest_time,
latest: currentUser.latest_time,
});
const [status, setStatus] = useState({
error: null,
success: null,
message: '',
});
const history = useHistory();
const handleClear = () => {
setAvailability([]);
@ -68,8 +74,8 @@ export default function Availability({
};
const handleSubmit = () => {
// Create list of events to post
const events = availability.map((event) => {
// Create a list of availability to post
const availabilityList = availability.map((event) => {
// Format start date to availability
const selectedDate = event.start.toISOString().substring(0, 10);
// Find the date id
@ -87,25 +93,32 @@ export default function Availability({
};
});
backend
.post('availability', events[0])
.then((response) => {
console.log(response)
// Create availability post request
const postAvailability = (data) => {
return backend.post('/availability', data);
};
const requests = availabilityList.map((event) =>
postAvailability(event),
);
Promise.all(requests)
.then(function (results) {
// Add confirmation message
setStatus({
success: true,
error: false,
message: 'Your availability has been added to the meeting.',
});
})
.catch((error) => {
console.log(error)
setStatus({
error: true,
success: false,
message:
"Your availability couldn't be added to the meeting.",
});
});
// // Create availability post request
// const postAvailability = (data) => {
// return backend.post('/availability', data);
// };
// const requests = events.map((event) => postAvailability(event));
// Promise.all(requests).then(function (results) {
// console.log('RESULTS: ', results);
// });
};
const handleSelectTimezone = (value, item, event) => {
@ -163,6 +176,7 @@ export default function Availability({
/>
</FormGroup>
<div className='av-controls'>
{!status.success && (
<ButtonGroup justified>
<Button
appearance='ghost'
@ -183,6 +197,34 @@ export default function Availability({
Save your availability
</Button>
</ButtonGroup>
)}
{status.success && (
<ButtonGroup justified>
<Button
appearance='ghost'
size='lg'
block
onClick={() => history.push('dashboard')}
>
Go to dashboard
</Button>
<Button
appearance='primary'
size='lg'
block
onClick={() => history.push('invite')}
>
Invite Participants
</Button>
</ButtonGroup>
)}
{(status.error || status.success) && (
<Message
type={status.success ? 'success' : 'error'}
description={status.message}
/>
)}
</div>
</div>
<div className={'interval-selector'}>

View File

@ -163,7 +163,6 @@ export default function Schedule({
backend
.post('/participants', data)
.then((response) => {
console.log(response);
addPossibleDates({ meeting_id: response.data.meeting_id });
})
.catch((error) => {