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
This commit is contained in:
rui hildt 2020-08-27 15:51:23 +02:00
parent 714a631896
commit f9193d460a
3 changed files with 44 additions and 48 deletions

View File

@ -25,10 +25,9 @@ export default function App() {
const [possibleDates, setPossibleDates] = useState(); const [possibleDates, setPossibleDates] = useState();
const [currentMeeting, setCurrentMeeting] = useState({ const [currentMeeting, setCurrentMeeting] = useState({
title: '', title: '',
description: '', description: '', // optional
timezone: '', duration: 0,
duration: 0, status: 0, // Always 0 when meeting unconfirmed
status: 0,
}); });
const [authToken, setAuthToken] = useState(existingToken || ''); const [authToken, setAuthToken] = useState(existingToken || '');

View File

@ -17,22 +17,23 @@ import {
IntervalSelector, IntervalSelector,
} from '../components'; } from '../components';
import dtToUTC from '../helpers/datetimeToUTC'; import dtToUTC from '../helpers/datetimeToUTC';
import { backend } from '../helpers/http-common';
import './styles/Availability.less'; import './styles/Availability.less';
import './styles/layout.less'; import './styles/layout.less';
// DEV possibleDates // // DEV possibleDates
const possibleDates = [ // const possibleDates = [
{ // {
id: 63, // id: 63,
start: '2020-08-01', // start: '2020-08-01',
display: 'background', // display: 'background',
}, // },
{ // {
id: 64, // id: 64,
start: '2020-08-02', // start: '2020-08-02',
display: 'background', // display: 'background',
}, // },
]; // ];
// NOTES: // NOTES:
// Even though Fullcalendar is supposed to work with timezone, // Even though Fullcalendar is supposed to work with timezone,
@ -40,7 +41,11 @@ const possibleDates = [
// Possible Dates ID are also striped by custom code. // Possible Dates ID are also striped by custom code.
// That's why timezone and possible dates id are only set when posting an availability. // 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 [availability, setAvailability] = useState([]);
const [timezone, setTimezone] = useState(currentUser.timezone); const [timezone, setTimezone] = useState(currentUser.timezone);
const [times, setTimes] = useState({ const [times, setTimes] = useState({
@ -62,8 +67,6 @@ export default function Availability({ currentUser, currentMeeting }) {
]); ]);
}; };
// console.log(availability, possibleDates);
const handleSubmit = () => { const handleSubmit = () => {
// Create list of events to post // Create list of events to post
const events = availability.map((event) => { const events = availability.map((event) => {
@ -75,7 +78,7 @@ export default function Availability({ currentUser, currentMeeting }) {
); );
return { return {
meeting: currentMeeting.id, meeting_id: currentMeeting.id,
account_id: currentUser.id, account_id: currentUser.id,
possible_date_id: date.id, possible_date_id: date.id,
preference: false, // set to 'true" when implementing preference 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) => { const handleSelectTimezone = (value, item, event) => {

View File

@ -15,7 +15,6 @@ import { useHistory } from 'react-router-dom';
import { import {
NavBar, NavBar,
TimezonePicker,
DaySelector, DaySelector,
DurationSelector, DurationSelector,
SelectedDates, SelectedDates,
@ -149,7 +148,8 @@ export default function Schedule({
history.push('/availability'); history.push('/availability');
}) })
.catch((error) => { .catch((error) => {
setError('Failed to add new account.'); setError('Failed to add new meeting.');
console.log(error)
}); });
const postPossibleDates = ({ meeting_id }) => { const postPossibleDates = ({ meeting_id }) => {
@ -185,27 +185,11 @@ export default function Schedule({
addID(result), addID(result),
); );
console.log('WITH ID', possibleDatesWithID)
setPossibleDates(possibleDatesWithID); setPossibleDates(possibleDatesWithID);
}); });
}; };
}; };
const handleSelectTimezone = (value, item, event) => {
setCurrentMeeting({
...currentMeeting,
timezone: item.timezone,
});
};
const handleClean = (event) => {
setCurrentMeeting({
...currentMeeting,
timezone: '',
});
};
const handleChangeMeeting = (value, evt) => { const handleChangeMeeting = (value, evt) => {
setCurrentMeeting({ setCurrentMeeting({
...currentMeeting, ...currentMeeting,
@ -264,14 +248,6 @@ export default function Schedule({
/> />
</FormGroup> </FormGroup>
<div className='meeting-options-inline'> <div className='meeting-options-inline'>
<FormGroup className='meeting-timezone'>
<ControlLabel>Timezone</ControlLabel>
<TimezonePicker
handleSelect={handleSelectTimezone}
handleClean={handleClean}
timezone={currentMeeting.timezone}
/>
</FormGroup>
<FormGroup className='meeting-duration'> <FormGroup className='meeting-duration'>
<ControlLabel>Duration</ControlLabel> <ControlLabel>Duration</ControlLabel>
<DurationSelector <DurationSelector