Post participant as part of creating a new meeting

This commit is contained in:
rui hildt 2020-08-27 16:31:09 +02:00
parent f9193d460a
commit 2aefdefb77
2 changed files with 43 additions and 17 deletions

View File

@ -26,7 +26,7 @@ export default function App() {
const [currentMeeting, setCurrentMeeting] = useState({ const [currentMeeting, setCurrentMeeting] = useState({
title: '', title: '',
description: '', // optional description: '', // optional
duration: 0, duration: 0,
status: 0, // Always 0 when meeting unconfirmed status: 0, // Always 0 when meeting unconfirmed
}); });
@ -75,6 +75,7 @@ export default function App() {
setPossibleDates={setPossibleDates} setPossibleDates={setPossibleDates}
currentMeeting={currentMeeting} currentMeeting={currentMeeting}
setCurrentMeeting={setCurrentMeeting} setCurrentMeeting={setCurrentMeeting}
currentUser={currentUser}
/> />
<PrivateRoute <PrivateRoute
path='/availability' path='/availability'

View File

@ -28,6 +28,7 @@ export default function Schedule({
setPossibleDates, setPossibleDates,
currentMeeting, currentMeeting,
setCurrentMeeting, setCurrentMeeting,
currentUser,
}) { }) {
const [eventsList, setEventsList] = useState([]); const [eventsList, setEventsList] = useState([]);
const [datesList, setDatesList] = useState(eventsToDates(eventsList)); const [datesList, setDatesList] = useState(eventsToDates(eventsList));
@ -144,15 +145,35 @@ export default function Schedule({
id: response.data.id, id: response.data.id,
}); });
postPossibleDates({ meeting_id: response.data.id }); addParticipant({
account_id: currentUser.id,
meeting_id: response.data.id,
quorum: 0, // 'false' while functionality not implemented
mandatory: 0, // 'false' while functionality not implemented
host: 1,
answered: 0,
});
history.push('/availability'); history.push('/availability');
}) })
.catch((error) => { .catch((error) => {
setError('Failed to add new meeting.'); setError('Failed to add new meeting.');
console.log(error)
}); });
const postPossibleDates = ({ meeting_id }) => { const addParticipant = (data) => {
backend
.post('/participants', data)
.then((response) => {
console.log(response);
addPossibleDates({ meeting_id: response.data.meeting_id });
})
.catch((error) => {
setError(
"Current user couldn't be set as participant to the meeting.",
);
});
};
const addPossibleDates = ({ meeting_id }) => {
// Post the possible dates and set add their ID to state // Post the possible dates and set add their ID to state
const postPossibleDate = (data) => { const postPossibleDate = (data) => {
return backend.post('/possible-dates', data); return backend.post('/possible-dates', data);
@ -171,22 +192,26 @@ export default function Schedule({
); );
// Perform concurrent requests and update possible dates with id // Perform concurrent requests and update possible dates with id
Promise.all(requests).then(function (results) { Promise.all(requests)
const addID = ({ data }) => { .then(function (results) {
let possibleDate = { const addID = ({ data }) => {
id: data.id, let possibleDate = {
start: data.possible_date.substring(0, 10), id: data.id,
display: 'background', start: data.possible_date.substring(0, 10),
display: 'background',
};
return possibleDate;
}; };
return possibleDate;
};
const possibleDatesWithID = results.map((result) => const possibleDatesWithID = results.map((result) =>
addID(result), addID(result),
); );
setPossibleDates(possibleDatesWithID); setPossibleDates(possibleDatesWithID);
}); })
.catch((error) => {
setError("Couldn't add possible dates to the meeting.");
});
}; };
}; };