Skip to content

Scheduling infrastructure for absolutely everyone.

Fix possible 404 when obtaining calendar busy lists (#3345)

alannnc4c2f6df94d47
diff --git a/apps/web/components/integrations/CalendarListContainer.tsx b/apps/web/components/integrations/CalendarListContainer.tsx
index 323c7119113..ffb1819f0c9 100644
--- a/apps/web/components/integrations/CalendarListContainer.tsx
+++ b/apps/web/components/integrations/CalendarListContainer.tsx
@@ -153,6 +153,7 @@ function ConnectedCalendarsList(props: Props) {
actions={
<DisconnectIntegration
id={item.credentialId}
+ externalId={item.primary?.externalId}
render={(btnProps) => (
<Button {...btnProps} color="warn" data-testid="integration-connection-button">
{t("disconnect")}
diff --git a/apps/web/components/integrations/DisconnectIntegration.tsx b/apps/web/components/integrations/DisconnectIntegration.tsx
index c4aabc705ca..9568aac2779 100644
--- a/apps/web/components/integrations/DisconnectIntegration.tsx
+++ b/apps/web/components/integrations/DisconnectIntegration.tsx
@@ -13,10 +13,11 @@ import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogCont
export default function DisconnectIntegration(props: {
/** Integration credential id */
id: number;
+ externalId?: string;
render: (renderProps: ButtonBaseProps) => JSX.Element;
onOpenChange: (isOpen: boolean) => unknown | Promise<unknown>;
}) {
- const { id } = props;
+ const { id, externalId = "" } = props;
const { t } = useLocale();
const [modalOpen, setModalOpen] = useState(false);
@@ -42,7 +43,7 @@ export default function DisconnectIntegration(props: {
confirmBtnText={t("yes_remove_app")}
cancelBtnText="Cancel"
onConfirm={() => {
- mutation.mutate({ id });
+ mutation.mutate({ id, externalId });
}}>
{t("are_you_sure_you_want_to_remove_this_app")}
</ConfirmationDialogContent>
diff --git a/apps/web/server/routers/viewer.tsx b/apps/web/server/routers/viewer.tsx
index b0e27f6e113..4bd77a66d98 100644
--- a/apps/web/server/routers/viewer.tsx
+++ b/apps/web/server/routers/viewer.tsx
@@ -991,9 +991,10 @@ const loggedInViewerRouter = createProtectedRouter()
.mutation("deleteCredential", {
input: z.object({
id: z.number(),
+ externalId: z.string().optional(),
}),
async resolve({ input, ctx }) {
- const { id } = input;
+ const { id, externalId } = input;
const credential = await prisma.credential.findFirst({
where: {
@@ -1060,14 +1061,41 @@ const loggedInViewerRouter = createProtectedRouter()
}
}
- // If it's a calendar, remove the destination claendar from the event type
+ // If it's a calendar, remove the destination calendar from the event type
if (credential.app?.categories.includes(AppCategories.calendar)) {
if (eventType.destinationCalendar?.integration === credential.type) {
- await prisma.destinationCalendar.delete({
+ const destinationCalendar = await prisma.destinationCalendar.findFirst({
where: {
- id: eventType.destinationCalendar.id,
+ id: eventType.destinationCalendar?.id,
},
});
+ if (destinationCalendar) {
+ await prisma.destinationCalendar.delete({
+ where: {
+ id: destinationCalendar.id,
+ },
+ });
+ }
+ }
+
+ if (externalId) {
+ const existingSelectedCalendar = await prisma.selectedCalendar.findFirst({
+ where: {
+ externalId: externalId,
+ },
+ });
+ // @TODO: SelectedCalendar doesn't have unique ID so we should only delete one item
+ if (existingSelectedCalendar) {
+ await prisma.selectedCalendar.delete({
+ where: {
+ userId_integration_externalId: {
+ userId: existingSelectedCalendar.userId,
+ externalId: existingSelectedCalendar.externalId,
+ integration: existingSelectedCalendar.integration,
+ },
+ },
+ });
+ }
}
}
diff --git a/packages/app-store/office365calendar/lib/CalendarService.ts b/packages/app-store/office365calendar/lib/CalendarService.ts
index 90279163db3..cfab5e584f7 100644
--- a/packages/app-store/office365calendar/lib/CalendarService.ts
+++ b/packages/app-store/office365calendar/lib/CalendarService.ts
@@ -140,16 +140,18 @@ export default class Office365CalendarService implements Calendar {
});
const responseBody = await handleErrorsJson(response);
return responseBody.responses.reduce(
- (acc: BufferedBusyTime[], subResponse: { body: { value: any[] } }) =>
+ (acc: BufferedBusyTime[], subResponse: { body: { value?: any[] } }) =>
acc.concat(
- subResponse.body.value
- .filter((evt) => evt.showAs !== "free" && evt.showAs !== "workingElsewhere")
- .map((evt) => {
- return {
- start: evt.start.dateTime + "Z",
- end: evt.end.dateTime + "Z",
- };
- })
+ subResponse.body?.value
+ ? subResponse.body.value
+ .filter((evt) => evt.showAs !== "free" && evt.showAs !== "workingElsewhere")
+ .map((evt) => {
+ return {
+ start: evt.start.dateTime + "Z",
+ end: evt.end.dateTime + "Z",
+ };
+ })
+ : []
),
[]
);