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

View File

@ -28,6 +28,7 @@ export default function Schedule({
setPossibleDates,
currentMeeting,
setCurrentMeeting,
currentUser,
}) {
const [eventsList, setEventsList] = useState([]);
const [datesList, setDatesList] = useState(eventsToDates(eventsList));
@ -144,15 +145,35 @@ export default function Schedule({
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');
})
.catch((error) => {
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
const postPossibleDate = (data) => {
return backend.post('/possible-dates', data);
@ -171,22 +192,26 @@ export default function Schedule({
);
// Perform concurrent requests and update possible dates with id
Promise.all(requests).then(function (results) {
const addID = ({ data }) => {
let possibleDate = {
id: data.id,
start: data.possible_date.substring(0, 10),
display: 'background',
Promise.all(requests)
.then(function (results) {
const addID = ({ data }) => {
let possibleDate = {
id: data.id,
start: data.possible_date.substring(0, 10),
display: 'background',
};
return possibleDate;
};
return possibleDate;
};
const possibleDatesWithID = results.map((result) =>
addID(result),
);
const possibleDatesWithID = results.map((result) =>
addID(result),
);
setPossibleDates(possibleDatesWithID);
});
setPossibleDates(possibleDatesWithID);
})
.catch((error) => {
setError("Couldn't add possible dates to the meeting.");
});
};
};