diff --git a/src/App.js b/src/App.js index 2b7a119..6d70383 100644 --- a/src/App.js +++ b/src/App.js @@ -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} /> { 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."); + }); }; };