Format availibility to post

This commit is contained in:
rui hildt 2020-08-27 14:51:58 +02:00
parent 850921eb25
commit 714a631896
4 changed files with 48 additions and 14 deletions

View File

@ -82,6 +82,7 @@ export default function App() {
component={Availability} component={Availability}
possibleDates={possibleDates} possibleDates={possibleDates}
currentUser={currentUser} currentUser={currentUser}
currentMeeting={currentMeeting}
/> />
<PrivateRoute path='/invite' component={Invite} /> <PrivateRoute path='/invite' component={Invite} />
</Switch> </Switch>

View File

@ -119,7 +119,6 @@ export default function IntervalSelector({
return ( return (
<FullCalendar <FullCalendar
plugins={[dayGridPlugin, interaction, timeGridPlugin, scrollGrid]} plugins={[dayGridPlugin, interaction, timeGridPlugin, scrollGrid]}
// timeZone={'UTC'}
events={availability} events={availability}
// View props // View props
headerToolbar={{ right: '' }} headerToolbar={{ right: '' }}

View File

@ -0,0 +1,18 @@
import { DateTime } from 'luxon';
const dtToUTC = (datetime, timezone) => {
// Create a date object with the selected timezone
const dt = DateTime.fromObject({
year: datetime.getFullYear(),
month: datetime.getMonth(),
day: datetime.getDate(),
hour: datetime.getHours(),
minute: datetime.getMinutes(),
zone: timezone,
});
// Convert and return a UTC Timestamp
return dt.toUTC().toISO();
};
export default dtToUTC;

View File

@ -1,6 +1,5 @@
import React, { useState, useEffect } from 'react'; import React, { useState } from 'react';
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
import { import {
Panel, Panel,
Form, Form,
@ -17,6 +16,7 @@ import {
TimePicker, TimePicker,
IntervalSelector, IntervalSelector,
} from '../components'; } from '../components';
import dtToUTC from '../helpers/datetimeToUTC';
import './styles/Availability.less'; import './styles/Availability.less';
import './styles/layout.less'; import './styles/layout.less';
@ -34,7 +34,13 @@ const possibleDates = [
}, },
]; ];
export default function Availability({ currentUser }) { // NOTES:
// Even though Fullcalendar is supposed to work with timezone,
// it seems the custom rendering code breaks it.
// 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 }) {
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({
@ -56,19 +62,29 @@ export default function Availability({ currentUser }) {
]); ]);
}; };
// console.log(availability, possibleDates);
const handleSubmit = () => { const handleSubmit = () => {
//TODO post intervals to backend // Create list of events to post
// Post it as UNIX EPOCH TIME const events = availability.map((event) => {
// timezone = UTC always // Format start date to availability
const selectedDate = event.start.toISOString().substring(0, 10);
// Find the date id
const [date] = possibleDates.filter(
(date) => date.start === selectedDate,
);
// Use Map to add id to events return {
// // Find corresponding id meeting: currentMeeting.id,
// const selectedDate = start.toISOString().substring(0, 10); account_id: currentUser.id,
// const [date] = possibleDates.filter( possible_date_id: date.id,
// (date) => date.start === selectedDate, preference: false, // set to 'true" when implementing preference
// ); start_time: dtToUTC(event.start, timezone),
end_time: dtToUTC(event.end, timezone),
};
});
console.log(availability); console.log(events);
}; };
const handleSelectTimezone = (value, item, event) => { const handleSelectTimezone = (value, item, event) => {