From 2d9064e92f2ea184032ddc20feb309cd8c5e68d9 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Wed, 21 Dec 2022 03:20:20 +0530 Subject: [PATCH] fix: show email in outlook (#5897) * fix: change external id to owner address Signed-off-by: Udit Takkar * feat: add email prop in calendar Signed-off-by: Udit Takkar * fix: only display for outlook Signed-off-by: Udit Takkar * fix: add email for apple calendar Signed-off-by: Udit Takkar * fix: type error and use description Signed-off-by: Udit Takkar * fix: try using email from /me endpoint Signed-off-by: Udit Takkar * fix: fallback to principal name when mail is not there Signed-off-by: Udit Takkar * chore: use empty string for fallback Signed-off-by: Udit Takkar Signed-off-by: Udit Takkar Co-authored-by: Peer Richelsen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> --- apps/web/components/apps/CalendarListContainer.tsx | 3 ++- packages/app-store/googlecalendar/lib/CalendarService.ts | 1 + packages/app-store/larkcalendar/lib/CalendarService.ts | 2 ++ .../app-store/office365calendar/lib/CalendarService.ts | 7 ++++++- .../features/calendars/DestinationCalendarSelector.tsx | 4 +++- packages/lib/CalendarService.ts | 1 + packages/types/Calendar.d.ts | 2 ++ 7 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/web/components/apps/CalendarListContainer.tsx b/apps/web/components/apps/CalendarListContainer.tsx index 39d04eb38d..84911a7959 100644 --- a/apps/web/components/apps/CalendarListContainer.tsx +++ b/apps/web/components/apps/CalendarListContainer.tsx @@ -159,6 +159,7 @@ function ConnectedCalendarsList(props: Props) { if (!data.connectedCalendars.length) { return null; } + return ( {data.connectedCalendars.map((item) => ( @@ -168,7 +169,7 @@ function ConnectedCalendarsList(props: Props) { slug={item.integration.slug} title={item.integration.title} logo={item.integration.logo} - description={item.primary?.externalId || "No external Id"} + description={item.primary?.email ?? item.integration.description} separate={true} actions={
diff --git a/packages/app-store/googlecalendar/lib/CalendarService.ts b/packages/app-store/googlecalendar/lib/CalendarService.ts index 1b81ca52f7..a420bcefc3 100644 --- a/packages/app-store/googlecalendar/lib/CalendarService.ts +++ b/packages/app-store/googlecalendar/lib/CalendarService.ts @@ -372,6 +372,7 @@ export default class GoogleCalendarService implements Calendar { name: cal.summary ?? "No name", primary: cal.primary ?? false, readOnly: !(cal.accessRole === "reader" || cal.accessRole === "owner") && true, + email: cal.id ?? "", }; return calendar; }) || [] diff --git a/packages/app-store/larkcalendar/lib/CalendarService.ts b/packages/app-store/larkcalendar/lib/CalendarService.ts index 9080d0c9b3..5df551a6c9 100644 --- a/packages/app-store/larkcalendar/lib/CalendarService.ts +++ b/packages/app-store/larkcalendar/lib/CalendarService.ts @@ -319,6 +319,7 @@ export default class LarkCalendarService implements Calendar { integration: this.integrationName, name: cal.summary_alias || cal.summary || "No calendar name", primary: cal.type === "primary", + email: cal.calendar_id ?? "", }; return calendar; }); @@ -339,6 +340,7 @@ export default class LarkCalendarService implements Calendar { integration: this.integrationName, name: cal.summary_alias || cal.summary || "No calendar name", primary: cal.type === "primary", + email: cal.calendar_id ?? "", }; return calendar; }); diff --git a/packages/app-store/office365calendar/lib/CalendarService.ts b/packages/app-store/office365calendar/lib/CalendarService.ts index 8287404886..6823ce0823 100644 --- a/packages/app-store/office365calendar/lib/CalendarService.ts +++ b/packages/app-store/office365calendar/lib/CalendarService.ts @@ -1,4 +1,4 @@ -import { Calendar as OfficeCalendar } from "@microsoft/microsoft-graph-types-beta"; +import { Calendar as OfficeCalendar, User } from "@microsoft/microsoft-graph-types-beta"; import { getLocation, getRichDescription } from "@calcom/lib/CalEventParser"; import { handleErrorsJson, handleErrorsRaw } from "@calcom/lib/errors"; @@ -182,6 +182,10 @@ export default class Office365CalendarService implements Calendar { } } + const user = await this.fetcher("/me"); + const userResponseBody = await handleErrorsJson(user); + const email = userResponseBody.mail ?? userResponseBody.userPrincipalName; + return officeCalendars.map((cal: OfficeCalendar) => { const calendar: IntegrationCalendar = { externalId: cal.id ?? "No Id", @@ -189,6 +193,7 @@ export default class Office365CalendarService implements Calendar { name: cal.name ?? "No calendar name", primary: cal.isDefaultCalendar ?? false, readOnly: !cal.canEdit && true, + email: email ?? "", }; return calendar; }); diff --git a/packages/features/calendars/DestinationCalendarSelector.tsx b/packages/features/calendars/DestinationCalendarSelector.tsx index 4d6b5d215b..3efe0f4d28 100644 --- a/packages/features/calendars/DestinationCalendarSelector.tsx +++ b/packages/features/calendars/DestinationCalendarSelector.tsx @@ -102,7 +102,9 @@ const DestinationCalendarSelector = ({ query.data.connectedCalendars.map((selectedCalendar) => ({ key: selectedCalendar.credentialId, label: `${selectedCalendar.integration.title?.replace(/calendar/i, "")} (${ - selectedCalendar.primary?.name + selectedCalendar.primary?.integration === "office365_calendar" + ? selectedCalendar.primary?.email + : selectedCalendar.primary?.name })`, options: (selectedCalendar.calendars ?? []) .filter((cal) => cal.readOnly === false) diff --git a/packages/lib/CalendarService.ts b/packages/lib/CalendarService.ts index 38cf6c6d28..71d9a1736b 100644 --- a/packages/lib/CalendarService.ts +++ b/packages/lib/CalendarService.ts @@ -420,6 +420,7 @@ export default abstract class BaseCalendarService implements Calendar { ? event.destinationCalendar.externalId === calendar.url : false, integration: this.integrationName, + email: this.credentials.username ?? "", }); return newCalendars; }, []); diff --git a/packages/types/Calendar.d.ts b/packages/types/Calendar.d.ts index 2dde1492cb..9141e80e34 100644 --- a/packages/types/Calendar.d.ts +++ b/packages/types/Calendar.d.ts @@ -178,6 +178,8 @@ export interface IntegrationCalendar extends Ensure, " primary?: boolean; name?: string; readOnly?: boolean; + // For displaying the connected email address + email?: string; } export interface Calendar {