Scheduling infrastructure for absolutely everyone.
fix: use destination calendar email (#6886)
Udit Takkar6877d0f693ce
diff --git a/packages/features/calendars/DestinationCalendarSelector.tsx b/packages/features/calendars/DestinationCalendarSelector.tsxindex db63778a01f..d2fb3570fd0 100644--- a/packages/features/calendars/DestinationCalendarSelector.tsx+++ b/packages/features/calendars/DestinationCalendarSelector.tsx@@ -119,7 +119,7 @@ const DestinationCalendarSelector = ({// Get primary calendar, which is shown in the placeholder since this is the calendar that will// be used when no destination calendar is selected.- const primaryCalendar = query.data.connectedCalendars.filter((cal) => Boolean(cal.primary))[0];+ const primaryCalendar = query.data.destinationCalendarEmail;return (<div className="relative" title={`${t("select_destination_calendar")}: ${selectedOption?.label || ""}`}>@@ -130,8 +130,7 @@ const DestinationCalendarSelector = ({`${t("select_destination_calendar")}`) : (<span>- {t("default_calendar_selected")}{" "}- {primaryCalendar?.primary?.externalId && `(${primaryCalendar?.primary?.externalId})`}+ {t("default_calendar_selected")} {primaryCalendar && `(${primaryCalendar})`}</span>)}diff --git a/packages/trpc/server/routers/viewer.tsx b/packages/trpc/server/routers/viewer.tsxindex 23fac562dd6..e3d8d299cf3 100644--- a/packages/trpc/server/routers/viewer.tsx+++ b/packages/trpc/server/routers/viewer.tsx@@ -322,6 +322,9 @@ const loggedInViewerRouter = router({// get all the connected integrations' calendars (from third party)const connectedCalendars = await getConnectedCalendars(calendarCredentials, user.selectedCalendars);+ // store email of the destination calendar to display+ let destinationCalendarEmail = null;+if (connectedCalendars.length === 0) {/* As there are no connected calendars, delete the destination calendar if it exists */if (user.destinationCalendar) {@@ -335,7 +338,7 @@ const loggedInViewerRouter = router({There are connected calendars, but no destination calendarSo create a default destination calendar with the first primary connected calendar*/- const { integration = "", externalId = "", credentialId } = connectedCalendars[0].primary ?? {};+ const { integration = "", externalId = "", credentialId, email } = connectedCalendars[0].primary ?? {};user.destinationCalendar = await ctx.prisma.destinationCalendar.create({data: {userId: user.id,@@ -344,6 +347,7 @@ const loggedInViewerRouter = router({credentialId,},});+ destinationCalendarEmail = email ?? user.destinationCalendar?.externalId;} else {/* There are connected calendars and a destination calendar */@@ -354,6 +358,7 @@ const loggedInViewerRouter = router({cal.externalId === user.destinationCalendar?.externalId &&cal.integration === user.destinationCalendar?.integration);+if (!destinationCal) {// If destinationCalendar is out of date, update it with the first primary connected calendarconst { integration = "", externalId = "" } = connectedCalendars[0].primary ?? {};@@ -365,11 +370,13 @@ const loggedInViewerRouter = router({},});}+ destinationCalendarEmail = destinationCal?.email ?? user.destinationCalendar?.externalId;}return {connectedCalendars,destinationCalendar: user.destinationCalendar,+ destinationCalendarEmail,};}),setDestinationCalendar: authedProcedure