From f9193d460a365c81af0509f7985c3bdc9c6b3db9 Mon Sep 17 00:00:00 2001 From: rui hildt Date: Thu, 27 Aug 2020 15:51:23 +0200 Subject: [PATCH] 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 --- src/App.js | 7 ++--- src/screens/Availability.js | 57 +++++++++++++++++++++++++------------ src/screens/Schedule.js | 28 ++---------------- 3 files changed, 44 insertions(+), 48 deletions(-) diff --git a/src/App.js b/src/App.js index 25a5936..2b7a119 100644 --- a/src/App.js +++ b/src/App.js @@ -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 || ''); diff --git a/src/screens/Availability.js b/src/screens/Availability.js index 29d0538..74456df 100644 --- a/src/screens/Availability.js +++ b/src/screens/Availability.js @@ -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) => { diff --git a/src/screens/Schedule.js b/src/screens/Schedule.js index 5810ef0..db9ee02 100644 --- a/src/screens/Schedule.js +++ b/src/screens/Schedule.js @@ -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({ />
- - Timezone - - Duration