Merge branch 'main' into bugfix/unify-email-sending
This commit is contained in:
commit
bd28636af5
13 files changed
+168
-92
No files matched your search
@@ -88,4 +88,13 @@ export default class CalEventParser {
|
||||
eventCopy.description = this.getRichDescriptionHtml();
|
||||
return eventCopy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a calendar event with rich description as plain text.
|
||||
*/
|
||||
public asRichEventPlain(): CalendarEvent {
|
||||
const eventCopy: CalendarEvent = { ...this.calEvent };
|
||||
eventCopy.description = this.getRichDescription();
|
||||
return eventCopy;
|
||||
}
|
||||
}
|
||||
+41
-26
@@ -227,28 +227,38 @@ const MicrosoftOffice365Calendar = (credential): CalendarApiAdapter => {
|
||||
? listCalendars().then((cals) => cals.map((e) => e.externalId))
|
||||
: Promise.resolve(selectedCalendarIds).then((x) => x)
|
||||
).then((ids: string[]) => {
|
||||
const urls = ids.map(
|
||||
(calendarId) =>
|
||||
"https://graph.microsoft.com/v1.0/me/calendars/" + calendarId + "/events" + filter
|
||||
);
|
||||
return Promise.all(
|
||||
urls.map((url) =>
|
||||
fetch(url, {
|
||||
method: "get",
|
||||
headers: {
|
||||
Authorization: "Bearer " + accessToken,
|
||||
Prefer: 'outlook.timezone="Etc/GMT"',
|
||||
},
|
||||
})
|
||||
.then(handleErrorsJson)
|
||||
.then((responseBody) =>
|
||||
responseBody.value.map((evt) => ({
|
||||
start: evt.start.dateTime + "Z",
|
||||
end: evt.end.dateTime + "Z",
|
||||
}))
|
||||
)
|
||||
)
|
||||
).then((results) => results.reduce((acc, events) => acc.concat(events), []));
|
||||
const requests = ids.map((calendarId, id) => ({
|
||||
id,
|
||||
method: "GET",
|
||||
headers: {
|
||||
Prefer: 'outlook.timezone="Etc/GMT"',
|
||||
},
|
||||
url: `/me/calendars/${calendarId}/events${filter}`,
|
||||
}));
|
||||
|
||||
return fetch("https://graph.microsoft.com/v1.0/$batch", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: "Bearer " + accessToken,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ requests }),
|
||||
})
|
||||
.then(handleErrorsJson)
|
||||
.then((responseBody) =>
|
||||
responseBody.responses.reduce(
|
||||
(acc, subResponse) =>
|
||||
acc.concat(
|
||||
subResponse.body.value.map((evt) => {
|
||||
return {
|
||||
start: evt.start.dateTime + "Z",
|
||||
end: evt.end.dateTime + "Z",
|
||||
};
|
||||
})
|
||||
),
|
||||
[]
|
||||
)
|
||||
);
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -357,7 +367,7 @@ const GoogleCalendar = (credential): CalendarApiAdapter => {
|
||||
attendees: event.attendees,
|
||||
reminders: {
|
||||
useDefault: false,
|
||||
overrides: [{ method: "email", minutes: 60 }],
|
||||
overrides: [{ method: "email", minutes: 10 }],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -404,7 +414,7 @@ const GoogleCalendar = (credential): CalendarApiAdapter => {
|
||||
attendees: event.attendees,
|
||||
reminders: {
|
||||
useDefault: false,
|
||||
overrides: [{ method: "email", minutes: 60 }],
|
||||
overrides: [{ method: "email", minutes: 10 }],
|
||||
},
|
||||
};
|
||||
|
||||
@@ -517,7 +527,12 @@ const createEvent = async (
|
||||
): Promise<EventResult> => {
|
||||
const parser: CalEventParser = new CalEventParser(calEvent, maybeUid);
|
||||
const uid: string = parser.getUid();
|
||||
const richEvent: CalendarEvent = parser.asRichEvent();
|
||||
/*
|
||||
* Matching the credential type is a workaround because the office calendar simply strips away newlines (\n and \r).
|
||||
* We need HTML there. Google Calendar understands newlines and Apple Calendar cannot show HTML, so no HTML should
|
||||
* be used for Google and Apple Calendar.
|
||||
*/
|
||||
const richEvent: CalendarEvent = parser.asRichEventPlain();
|
||||
|
||||
let success = true;
|
||||
|
||||
@@ -579,7 +594,7 @@ const updateEvent = async (
|
||||
): Promise<EventResult> => {
|
||||
const parser: CalEventParser = new CalEventParser(calEvent);
|
||||
const newUid: string = parser.getUid();
|
||||
const richEvent: CalendarEvent = parser.asRichEvent();
|
||||
const richEvent: CalendarEvent = parser.asRichEventPlain();
|
||||
|
||||
let success = true;
|
||||
|
||||
|
||||
+13
-4
@@ -1,7 +1,6 @@
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
@@ -119,10 +118,20 @@ const getSlots = ({
|
||||
workingHours,
|
||||
organizerTimeZone,
|
||||
}: GetSlots): Dayjs[] => {
|
||||
const startTime = dayjs().utcOffset(inviteeDate.utcOffset()).isSame(inviteeDate, "day")
|
||||
? inviteeDate.hour() * 60 + inviteeDate.minute() + (minimumBookingNotice || 0)
|
||||
: 0;
|
||||
// current date in invitee tz
|
||||
const currentDate = dayjs().utcOffset(inviteeDate.utcOffset());
|
||||
const startDate = currentDate.add(minimumBookingNotice, "minutes"); // + minimum notice period
|
||||
// when the invitee date is not the same as the current date, reset the date to the start of day
|
||||
if (inviteeDate.date() !== currentDate.date()) {
|
||||
inviteeDate = inviteeDate.startOf("day");
|
||||
}
|
||||
|
||||
const startTime = startDate.isAfter(inviteeDate)
|
||||
? // block out everything when inviteeDate is less than startDate
|
||||
startDate.date() > inviteeDate.date()
|
||||
? 1440
|
||||
: startDate.hour() * 60 + startDate.minute()
|
||||
: 0;
|
||||
const inviteeBounds = inviteeBoundary(startTime, inviteeDate.utcOffset(), frequency);
|
||||
|
||||
return getOverlaps(
|
||||
|
||||
Reference in new issue
Block a user