fix: removing the default app should remove the default badge from the appCard (#15243)

This commit is contained in:
Amit Sharma authored and GitHub committed 2024-05-29 15:10:45 +00:00
1 parent 17f328fc5e
commit 5fb5081faa
1 file changed
+18
@@ -11,6 +11,7 @@ import { getTranslation } from "@calcom/lib/server/i18n";
import { bookingMinimalSelect, prisma } from "@calcom/prisma";
import { AppCategories, BookingStatus } from "@calcom/prisma/enums";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
import { userMetadata } from "@calcom/prisma/zod-utils";
import { EventTypeMetaDataSchema } from "@calcom/prisma/zod-utils";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
@@ -339,6 +340,23 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
});
}
let metadata = userMetadata.parse(user.metadata);
if (credential.app?.slug === metadata?.defaultConferencingApp?.appSlug) {
metadata = {
...metadata,
defaultConferencingApp: undefined,
};
await prisma.user.update({
where: {
id: user.id,
},
data: {
metadata,
},
});
}
// Backwards compatibility. Selected calendars cascade on delete when deleting a credential
// If it's a calendar remove it from the SelectedCalendars
if (credential.app?.categories.includes(AppCategories.calendar)) {