diff --git a/src/App.js b/src/App.js index 70d5ce3..3c1e82b 100644 --- a/src/App.js +++ b/src/App.js @@ -81,6 +81,7 @@ export default function App() { path='/availability' component={Availability} possibleDates={possibleDates} + currentUser={currentUser} /> diff --git a/src/screens/Availability.js b/src/screens/Availability.js index a60b377..5486524 100644 --- a/src/screens/Availability.js +++ b/src/screens/Availability.js @@ -16,9 +16,13 @@ import { NavBar, TimezonePicker, IntervalSelector } from '../components'; import './styles/Availability.less'; import './styles/layout.less'; -export default function Availability({ possibleDates }) { +export default function Availability({ possibleDates, currentUser }) { const [availability, setAvailability] = useState([]); + console.log(currentUser) + console.log(possibleDates) + //TODO post intervals to backend + const handleClear = () => { setAvailability([]); }; @@ -30,11 +34,17 @@ export default function Availability({ possibleDates }) { end: end, }; updatedEvents.push(newAvailability); + + // console.log("NEW AVAILABILITY UNIX EPOCH: ", Math.floor(newAvailability.start / 1000)) setAvailability([...availability, ...updatedEvents]); }; - if(!possibleDates) { - return + const handleSubmit = () => { + console.log(availability); + }; + + if (!possibleDates) { + return ; } return ( @@ -71,6 +81,7 @@ export default function Availability({ possibleDates }) { size='lg' block disabled={availability.length === 0} + onClick={handleSubmit} > Save your availability diff --git a/src/screens/Schedule.js b/src/screens/Schedule.js index c7bb9f4..ae42487 100644 --- a/src/screens/Schedule.js +++ b/src/screens/Schedule.js @@ -136,14 +136,58 @@ export default function Schedule({ // MEETING const handleSchedule = () => { + // ADD THE MEETING backend .post('/meetings', currentMeeting) .then((response) => { + setCurrentMeeting({ + ...currentMeeting, + id: response.data.id, + }); + + postPossibleDates({ meeting_id: response.data.id }); history.push('/availability'); }) .catch((error) => { setError('Failed to add new account.'); }); + + const postPossibleDates = ({ meeting_id }) => { + // Post the possible dates and set add their ID to state + const postPossibleDate = (data) => { + return backend.post('/possible-dates', data); + }; + + const createRequest = ({ start }) => { + let data = { + meeting_id, + possible_date: start, + }; + return postPossibleDate(data); + }; + + const requests = possibleDates.map((possibleDate) => + createRequest(possibleDate), + ); + + // 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', + }; + return possibleDate; + }; + + const possibleDatesWithID = results.map((result) => + addID(result), + ); + + setPossibleDates(possibleDatesWithID); + }); + }; }; const handleSelectTimezone = (value, item, event) => { @@ -254,10 +298,8 @@ export default function Schedule({ > Confirm dates - {error && ( - - )} + {error && }
{datesList.length > 0 && ( <>