Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add destination calendar name to DestinationCalendarSelector #6701

Merged
merged 7 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const DestinationCalendarSelector = ({
) : (
<span>
{t("default_calendar_selected")} {primaryCalendar && `(${primaryCalendar})`}
{`(${query.data.destinationCalendar.name || primaryCalendar?.primary?.externalId})`}
</span>
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/features/tips/Tips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const tips = [
title: "Automate Workflows",
description: "Make time work for you and automate tasks",
href: "https://go.cal.com/workflows",
},
},
];

export default function Tips() {
Expand Down
19 changes: 17 additions & 2 deletions packages/trpc/server/routers/viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppCategories, BookingStatus, IdentityProvider, Prisma } from "@prisma/client";
import { AppCategories, BookingStatus, DestinationCalendar, IdentityProvider, Prisma } from "@prisma/client";
import _ from "lodash";
import { authenticator } from "otplib";
import z from "zod";
Expand Down Expand Up @@ -374,9 +374,24 @@ const loggedInViewerRouter = router({
destinationCalendarEmail = destinationCal?.email ?? user.destinationCalendar?.externalId;
}

let destinationCalendarName = undefined;

for (const integration of connectedCalendars) {
if (integration?.calendars) {
for (const calendar of integration?.calendars) {
if (calendar.externalId === user.destinationCalendar?.externalId)
destinationCalendarName = calendar.name;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I smell a code smell here. We're traversing everything just to attach a calendar name. I think we can do better here. Can we include this from the initial prisma query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't store the calendar name in the DB. I was thinking about saving the calendar name to the DB, but it could change anytime. By grabbing the calendar name in the connected calendars call, we can always ensure that the calendar name is up to date.

Although looking at this now, we should only traverse through the connected calendars if they are the same integration as the destination calendar.


return {
connectedCalendars,
destinationCalendar: user.destinationCalendar,
// destinationCalendar: user.destinationCalendar,
destinationCalendar: {
...user.destinationCalendar,
...(destinationCalendarName && { name: destinationCalendarName }),
} as DestinationCalendar & { name?: string | undefined },
destinationCalendarEmail,
};
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/trpc/server/routers/viewer/bookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export const bookingsRouter = router({

const recurringInfo = recurringInfoBasic.map(
(
info: (typeof recurringInfoBasic)[number]
info: typeof recurringInfoBasic[number]
): {
recurringEventId: string | null;
count: number;
Expand Down