From 159c026533782d3bcb4825552b0adefdcd615bf5 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Fri, 17 Jun 2022 19:34:41 +0100 Subject: [PATCH] As Google Meet is always installed, this fixes the doubling (#3093) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * As Google Meet is always installed, this fixes the doubling * Make entire Google link clickable, fix extraData * Attempt at type fixing :) * AdditionalInformation for the booking page? * Update packages/emails/src/components/LocationInfo.tsx Being explicit :) * Exclude AdditionalInformation as it is irrelevant here Co-authored-by: Peer Richelsen Co-authored-by: Omar López --- apps/web/pages/api/book/event.ts | 2 +- .../lib/CalendarService.ts | 14 +++-- .../lib/CalendarService.ts | 2 +- .../app-store/googlecalendar/_metadata.ts | 2 - packages/core/CalendarManager.ts | 15 ++++-- packages/core/EventManager.ts | 25 ++++----- packages/core/videoClient.ts | 6 +-- .../emails/src/components/LocationInfo.tsx | 54 ++++++++----------- packages/lib/CalendarService.ts | 11 ++-- packages/types/Calendar.d.ts | 4 +- packages/types/Event.d.ts | 5 +- packages/types/EventManager.d.ts | 6 +-- 12 files changed, 72 insertions(+), 74 deletions(-) diff --git a/apps/web/pages/api/book/event.ts b/apps/web/pages/api/book/event.ts index aea5603d4b..db49907feb 100644 --- a/apps/web/pages/api/book/event.ts +++ b/apps/web/pages/api/book/event.ts @@ -568,7 +568,7 @@ async function handler(req: NextApiRequest) { return prisma.booking.create(createBookingObj); } - let results: EventResult[] = []; + let results: EventResult[] = []; let referencesToCreate: PartialReference[] = []; let user: User | null = null; diff --git a/packages/app-store/exchange2013calendar/lib/CalendarService.ts b/packages/app-store/exchange2013calendar/lib/CalendarService.ts index 19a1554088..35adbf5558 100644 --- a/packages/app-store/exchange2013calendar/lib/CalendarService.ts +++ b/packages/app-store/exchange2013calendar/lib/CalendarService.ts @@ -25,7 +25,13 @@ import { symmetricDecrypt } from "@calcom/lib/crypto"; // Probably don't need // import { CALENDAR_INTEGRATIONS_TYPES } from "@calcom/lib/integrations/calendar/constants/generals"; import logger from "@calcom/lib/logger"; -import { Calendar, CalendarEvent, EventBusyDate, IntegrationCalendar } from "@calcom/types/Calendar"; +import { + Calendar, + CalendarEvent, + EventBusyDate, + IntegrationCalendar, + NewCalendarEventType, +} from "@calcom/types/Calendar"; export default class ExchangeCalendarService implements Calendar { private url = ""; @@ -55,7 +61,7 @@ export default class ExchangeCalendarService implements Calendar { this.exchangeVersion = ExchangeVersion.Exchange2013; } - async createEvent(event: CalendarEvent) { + async createEvent(event: CalendarEvent): Promise { try { const appointment = new Appointment(this.getExchangeService()); // service instance of ExchangeService appointment.Subject = event.title; @@ -76,7 +82,7 @@ export default class ExchangeCalendarService implements Calendar { password: "", type: "", url: "", - additionalInfo: [], + additionalInfo: {}, }; } catch (reason) { this.log.error(reason); @@ -84,7 +90,7 @@ export default class ExchangeCalendarService implements Calendar { } } - async updateEvent(uid: string, event: CalendarEvent) { + async updateEvent(uid: string, event: CalendarEvent): Promise { try { const appointment = await Appointment.Bind( this.getExchangeService(), diff --git a/packages/app-store/exchange2016calendar/lib/CalendarService.ts b/packages/app-store/exchange2016calendar/lib/CalendarService.ts index 93652a4358..c70d2fc8b7 100644 --- a/packages/app-store/exchange2016calendar/lib/CalendarService.ts +++ b/packages/app-store/exchange2016calendar/lib/CalendarService.ts @@ -83,7 +83,7 @@ export default class ExchangeCalendarService implements Calendar { password: "", type: "", url: "", - additionalInfo: [], + additionalInfo: {}, }; } catch (reason) { this.log.error(reason); diff --git a/packages/app-store/googlecalendar/_metadata.ts b/packages/app-store/googlecalendar/_metadata.ts index 6d2aaf673d..445563ba2e 100644 --- a/packages/app-store/googlecalendar/_metadata.ts +++ b/packages/app-store/googlecalendar/_metadata.ts @@ -22,8 +22,6 @@ export const metadata = { url: "https://cal.com/", verified: true, email: "help@cal.com", - locationType: LocationType.GoogleMeet, - locationLabel: "Google Meet", } as App; export default metadata; diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index 126b21c5d7..5400c2cc13 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -7,7 +7,8 @@ import { getUid } from "@calcom/lib/CalEventParser"; import { getErrorFromUnknown } from "@calcom/lib/errors"; import logger from "@calcom/lib/logger"; import notEmpty from "@calcom/lib/notEmpty"; -import type { CalendarEvent, EventBusyDate } from "@calcom/types/Calendar"; +import type { CalendarEvent, EventBusyDate, NewCalendarEventType } from "@calcom/types/Calendar"; +import type { Event } from "@calcom/types/Event"; import type { EventResult } from "@calcom/types/EventManager"; const log = logger.getChildLogger({ prefix: ["CalendarManager"] }); @@ -97,7 +98,10 @@ export const getBusyCalendarTimes = async ( return results.reduce((acc, availability) => acc.concat(availability), []); }; -export const createEvent = async (credential: Credential, calEvent: CalendarEvent): Promise => { +export const createEvent = async ( + credential: Credential, + calEvent: CalendarEvent +): Promise> => { const uid: string = getUid(calEvent); const calendar = getCalendar(credential); let success = true; @@ -130,7 +134,7 @@ export const updateEvent = async ( calEvent: CalendarEvent, bookingRefUid: string | null, externalCalendarId: string | null -): Promise => { +): Promise> => { const uid = getUid(calEvent); const calendar = getCalendar(credential); let success = false; @@ -141,7 +145,10 @@ export const updateEvent = async ( calendar && bookingRefUid ? await calendar .updateEvent(bookingRefUid, calEvent, externalCalendarId) - .then(() => (success = true)) + .then((event) => { + success = true; + return event; + }) .catch((e) => { log.error("updateEvent failed", e, calEvent); return undefined; diff --git a/packages/core/EventManager.ts b/packages/core/EventManager.ts index 261b1dc306..2195c98909 100644 --- a/packages/core/EventManager.ts +++ b/packages/core/EventManager.ts @@ -6,21 +6,14 @@ import { v5 as uuidv5 } from "uuid"; import { FAKE_DAILY_CREDENTIAL } from "@calcom/app-store/dailyvideo/lib/VideoApiAdapter"; import getApps from "@calcom/app-store/utils"; import prisma from "@calcom/prisma"; -import type { AdditionalInformation, CalendarEvent } from "@calcom/types/Calendar"; -import type { - CreateUpdateResult, - EventResult, - PartialBooking, - PartialReference, -} from "@calcom/types/EventManager"; -import type { VideoCallData } from "@calcom/types/VideoApiAdapter"; +import type { AdditionalInformation, CalendarEvent, NewCalendarEventType } from "@calcom/types/Calendar"; +import type { Event } from "@calcom/types/Event"; +import type { CreateUpdateResult, EventResult, PartialBooking } from "@calcom/types/EventManager"; import { createEvent, updateEvent } from "./CalendarManager"; import { LocationType } from "./location"; import { createMeeting, updateMeeting } from "./videoClient"; -export type Event = AdditionalInformation & VideoCallData; - export const isZoom = (location: string): boolean => { return location === "integrations:zoom"; }; @@ -126,7 +119,7 @@ export default class EventManager { const evt = processLocation(event); const isDedicated = evt.location ? isDedicatedIntegration(evt.location) : null; - const results: Array = []; + const results: Array>> = []; // If and only if event type is a dedicated meeting, create a dedicated video meeting. if (isDedicated) { const result = await this.createVideoEvent(evt); @@ -140,7 +133,7 @@ export default class EventManager { // Create the calendar event with the proper video call data results.push(...(await this.createAllCalendarEvents(evt))); - const referencesToCreate: Array = results.map((result: EventResult) => { + const referencesToCreate = results.map((result) => { return { type: result.type, uid: result.createdEvent?.id.toString() ?? "", @@ -214,7 +207,7 @@ export default class EventManager { }); const isDedicated = evt.location ? isDedicatedIntegration(evt.location) : null; - const results: Array = []; + const results: Array> = []; // If and only if event type is a dedicated meeting, update the dedicated video meeting. if (isDedicated) { const result = await this.updateVideoEvent(evt, booking); @@ -285,7 +278,7 @@ export default class EventManager { * @param noMail * @private */ - private async createAllCalendarEvents(event: CalendarEvent): Promise> { + private async createAllCalendarEvents(event: CalendarEvent) { /** Can I use destinationCalendar here? */ /* How can I link a DC to a cred? */ if (event.destinationCalendar) { @@ -341,7 +334,7 @@ export default class EventManager { * @param event * @private */ - private createVideoEvent(event: CalendarEvent): Promise { + private createVideoEvent(event: CalendarEvent) { const credential = this.getVideoCredential(event); if (credential) { @@ -366,7 +359,7 @@ export default class EventManager { private updateAllCalendarEvents( event: CalendarEvent, booking: PartialBooking - ): Promise> { + ): Promise>> { return async.mapLimit(this.calendarCredentials, 5, async (credential: Credential) => { try { // HACK: diff --git a/packages/core/videoClient.ts b/packages/core/videoClient.ts index fb26e69f01..9f6e4e736a 100644 --- a/packages/core/videoClient.ts +++ b/packages/core/videoClient.ts @@ -7,7 +7,7 @@ import { getUid } from "@calcom/lib/CalEventParser"; import logger from "@calcom/lib/logger"; import type { CalendarEvent } from "@calcom/types/Calendar"; import type { EventResult, PartialReference } from "@calcom/types/EventManager"; -import type { VideoApiAdapter, VideoApiAdapterFactory } from "@calcom/types/VideoApiAdapter"; +import type { VideoApiAdapter, VideoApiAdapterFactory, VideoCallData } from "@calcom/types/VideoApiAdapter"; const log = logger.getChildLogger({ prefix: ["[lib] videoClient"] }); @@ -32,7 +32,7 @@ const getBusyVideoTimes = (withCredentials: Credential[]) => results.reduce((acc, availability) => acc.concat(availability), []) ); -const createMeeting = async (credential: Credential, calEvent: CalendarEvent): Promise => { +const createMeeting = async (credential: Credential, calEvent: CalendarEvent) => { const uid: string = getUid(calEvent); if (!credential) { @@ -69,7 +69,7 @@ const updateMeeting = async ( credential: Credential, calEvent: CalendarEvent, bookingRef: PartialReference | null -): Promise => { +): Promise> => { const uid = translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL)); let success = true; diff --git a/packages/emails/src/components/LocationInfo.tsx b/packages/emails/src/components/LocationInfo.tsx index 7926cd9c2b..37afd1ac34 100644 --- a/packages/emails/src/components/LocationInfo.tsx +++ b/packages/emails/src/components/LocationInfo.tsx @@ -30,19 +30,18 @@ export function LocationInfo(props: { calEvent: CalendarEvent; t: TFunction }) { label={t("where")} withSpacer description={ - <> - {providerName} - {meetingUrl && ( - - - - )} - + meetingUrl ? ( + + {providerName} + + ) : ( + <>{t("something_went_wrong")} + ) } extraInfo={ <> @@ -84,26 +83,15 @@ export function LocationInfo(props: { calEvent: CalendarEvent; t: TFunction }) { label={t("where")} withSpacer description={ - <> - {providerName} - {hangoutLink && ( - - - - )} - - } - extraInfo={ - providerName === "Zoom" || providerName === "Google" ? ( -

- <>{t("meeting_url_provided_after_confirmed")} -

- ) : null + + Google + + } /> ); diff --git a/packages/lib/CalendarService.ts b/packages/lib/CalendarService.ts index 64ddda0410..964b228d5e 100644 --- a/packages/lib/CalendarService.ts +++ b/packages/lib/CalendarService.ts @@ -145,7 +145,10 @@ export default abstract class BaseCalendarService implements Calendar { } } - async updateEvent(uid: string, event: CalendarEvent) { + async updateEvent( + uid: string, + event: CalendarEvent + ): Promise { try { const events = await this.getEventsByUID(uid); @@ -166,10 +169,12 @@ export default abstract class BaseCalendarService implements Calendar { this.log.debug("Error creating iCalString"); return { + uid, type: event.type, id: typeof event.uid === "string" ? event.uid : "-1", password: "", url: typeof event.location === "string" ? event.location : "-1", + additionalInfo: {}, }; } @@ -186,7 +191,7 @@ export default abstract class BaseCalendarService implements Calendar { headers: this.headers, }); }) - ).then((p) => p.map((r) => r.json() as unknown as Event)); + ).then((p) => p.map((r) => r.json() as unknown as NewCalendarEventType)); } catch (reason) { this.log.error(reason); @@ -290,7 +295,7 @@ export default abstract class BaseCalendarService implements Calendar { if (vtimezone) { const zone = new ICAL.Timezone(vtimezone); currentEvent.startDate = currentEvent.startDate.convertToZone(zone); - currentEvent.endDate = currentEvent.endDate.convertToZone(zone); + currentEvent.endDate = currentEvent.endDate.convertToZone(zone); } currentStart = dayjs(currentEvent.startDate.toJSDate()); diff --git a/packages/types/Calendar.d.ts b/packages/types/Calendar.d.ts index c8be77934b..16ecd52030 100644 --- a/packages/types/Calendar.d.ts +++ b/packages/types/Calendar.d.ts @@ -34,7 +34,7 @@ export type NewCalendarEventType = { type: string; password: string; url: string; - additionalInfo: Record; + additionalInfo: Record; }; export type CalendarEventType = { @@ -154,7 +154,7 @@ export interface Calendar { uid: string, event: CalendarEvent, externalCalendarId?: string | null - ): Promise; + ): Promise; deleteEvent(uid: string, event: CalendarEvent, externalCalendarId?: string | null): Promise; diff --git a/packages/types/Event.d.ts b/packages/types/Event.d.ts index 6797354e3c..407c34c6df 100644 --- a/packages/types/Event.d.ts +++ b/packages/types/Event.d.ts @@ -1,4 +1,5 @@ -import type { PartialReference } from "./EventManager"; +import type { NewCalendarEventType, AdditionalInformation } from "@calcom/types/Calendar"; + import type { VideoCallData } from "./VideoApiAdapter"; -export type Event = AdditionalInformation & VideoCallData; +export type Event = AdditionalInformation | NewCalendarEventType | VideoCallData; diff --git a/packages/types/EventManager.d.ts b/packages/types/EventManager.d.ts index 4a68f7b968..7e55a08a45 100644 --- a/packages/types/EventManager.d.ts +++ b/packages/types/EventManager.d.ts @@ -11,12 +11,12 @@ export interface PartialReference { externalCalendarId?: string | null; } -export interface EventResult { +export interface EventResult { type: string; success: boolean; uid: string; - createdEvent?: Event; - updatedEvent?: Event | Event[]; + createdEvent?: T; + updatedEvent?: T | T[]; originalEvent: CalendarEvent; }