Connect Availability to backend

This commit is in a non-working state. To post an availability we need
to have a participant created in db, which is yet to be implemented
This commit is contained in:
rui hildt 2020-08-27 15:51:23 +02:00
parent 714a631896
commit f9193d460a
3 changed files with 44 additions and 48 deletions

View File

@ -25,10 +25,9 @@ export default function App() {
const [possibleDates, setPossibleDates] = useState();
const [currentMeeting, setCurrentMeeting] = useState({
title: '',
description: '',
timezone: '',
duration: 0,
status: 0,
description: '', // optional
duration: 0,
status: 0, // Always 0 when meeting unconfirmed
});
const [authToken, setAuthToken] = useState(existingToken || '');

View File

@ -17,22 +17,23 @@ import {
IntervalSelector,
} from '../components';
import dtToUTC from '../helpers/datetimeToUTC';
import { backend } from '../helpers/http-common';
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',
},
];
// // DEV possibleDates
// const possibleDates = [
// {
// id: 63,
// start: '2020-08-01',
// display: 'background',
// },
// {
// id: 64,
// start: '2020-08-02',
// display: 'background',
// },
// ];
// NOTES:
// Even though Fullcalendar is supposed to work with timezone,
@ -40,7 +41,11 @@ const possibleDates = [
// Possible Dates ID are also striped by custom code.
// That's why timezone and possible dates id are only set when posting an availability.
export default function Availability({ currentUser, currentMeeting }) {
export default function Availability({
currentUser,
currentMeeting,
possibleDates,
}) {
const [availability, setAvailability] = useState([]);
const [timezone, setTimezone] = useState(currentUser.timezone);
const [times, setTimes] = useState({
@ -62,8 +67,6 @@ export default function Availability({ currentUser, currentMeeting }) {
]);
};
// console.log(availability, possibleDates);
const handleSubmit = () => {
// Create list of events to post
const events = availability.map((event) => {
@ -75,7 +78,7 @@ export default function Availability({ currentUser, currentMeeting }) {
);
return {
meeting: currentMeeting.id,
meeting_id: currentMeeting.id,
account_id: currentUser.id,
possible_date_id: date.id,
preference: false, // set to 'true" when implementing preference
@ -84,7 +87,25 @@ export default function Availability({ currentUser, currentMeeting }) {
};
});
console.log(events);
backend
.post('availability', events[0])
.then((response) => {
console.log(response)
})
.catch((error) => {
console.log(error)
});
// // 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) => {

View File

@ -15,7 +15,6 @@ import { useHistory } from 'react-router-dom';
import {
NavBar,
TimezonePicker,
DaySelector,
DurationSelector,
SelectedDates,
@ -149,7 +148,8 @@ export default function Schedule({
history.push('/availability');
})
.catch((error) => {
setError('Failed to add new account.');
setError('Failed to add new meeting.');
console.log(error)
});
const postPossibleDates = ({ meeting_id }) => {
@ -185,27 +185,11 @@ export default function Schedule({
addID(result),
);
console.log('WITH ID', possibleDatesWithID)
setPossibleDates(possibleDatesWithID);
});
};
};
const handleSelectTimezone = (value, item, event) => {
setCurrentMeeting({
...currentMeeting,
timezone: item.timezone,
});
};
const handleClean = (event) => {
setCurrentMeeting({
...currentMeeting,
timezone: '',
});
};
const handleChangeMeeting = (value, evt) => {
setCurrentMeeting({
...currentMeeting,
@ -264,14 +248,6 @@ export default function Schedule({
/>
</FormGroup>
<div className='meeting-options-inline'>
<FormGroup className='meeting-timezone'>
<ControlLabel>Timezone</ControlLabel>
<TimezonePicker
handleSelect={handleSelectTimezone}
handleClean={handleClean}
timezone={currentMeeting.timezone}
/>
</FormGroup>
<FormGroup className='meeting-duration'>
<ControlLabel>Duration</ControlLabel>
<DurationSelector