Skip to content

Commit

Permalink
fix: Minimum fix for N Calendar Invites (#14617)
Browse files Browse the repository at this point in the history
* Remove pushing team member destination calendars

* Only create the event on the first destination calendar

* Only create event on the first destination calendar
  • Loading branch information
joeauyeung committed Apr 16, 2024
1 parent e3e464a commit cebbffe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/app-store/_utils/calendars/processExternalId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { DestinationCalendar } from "@prisma/client";

import { metadata as OutlookMetadata } from "../../office365calendar";

/**
* When inviting attendees to a calendar event, sometimes the external ID is only used for internal purposes
* Need to process the correct external ID for the calendar service
*/
const processExternalId = (destinationCalendar: DestinationCalendar) => {
if (destinationCalendar.integration === OutlookMetadata.type) {
// Primary email should always be present for Outlook
return destinationCalendar.primaryEmail || destinationCalendar.externalId;
}

return destinationCalendar.externalId;
};

export default processExternalId;
4 changes: 4 additions & 0 deletions packages/core/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ export default class EventManager {
};

if (event.destinationCalendar && event.destinationCalendar.length > 0) {
let eventCreated = false;
// Since GCal pushes events to multiple calendars we only want to create one event per booking
let gCalAdded = false;
const destinationCalendars: DestinationCalendar[] = event.destinationCalendar.reduce(
Expand All @@ -554,6 +555,7 @@ export default class EventManager {
[] as DestinationCalendar[]
);
for (const destination of destinationCalendars) {
if (eventCreated) break;
log.silly("Creating Calendar event", JSON.stringify({ destination }));
if (destination.credentialId) {
let credential = this.calendarCredentials.find((c) => c.id === destination.credentialId);
Expand Down Expand Up @@ -582,6 +584,7 @@ export default class EventManager {
const createdEvent = await createEvent(credential, event, destination.externalId);
if (createdEvent) {
createdEvents.push(createdEvent);
eventCreated = true;
}
}
} else {
Expand All @@ -607,6 +610,7 @@ export default class EventManager {
})
);
createdEvents.push(await createEvent(firstCalendarCredential, event));
eventCreated = true;
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { Logger } from "tslog";
import { v5 as uuidv5 } from "uuid";
import z from "zod";

import processExternalId from "@calcom/app-store/_utils/calendars/processExternalId";
import { metadata as GoogleMeetMetadata } from "@calcom/app-store/googlevideo/_metadata";
import type { LocationObject } from "@calcom/app-store/locations";
import {
Expand Down Expand Up @@ -1405,9 +1406,13 @@ async function handler(

// Organizer or user owner of this event type it's not listed as a team member.
const teamMemberPromises = users.slice(1).map(async (user) => {
// TODO: Add back once EventManager tests are ready https://github.com/calcom/cal.com/pull/14610#discussion_r1567817120
// push to teamDestinationCalendars if it's a team event but collective only
if (isTeamEventType && eventType.schedulingType === "COLLECTIVE" && user.destinationCalendar) {
teamDestinationCalendars.push(user.destinationCalendar);
teamDestinationCalendars.push({
...user.destinationCalendar,
externalId: processExternalId(user.destinationCalendar),
});
}

return {
Expand Down

0 comments on commit cebbffe

Please sign in to comment.