Skip to content

Commit d5bd08d

Browse files
improve-delegation-disable-email-communication (calcom#21456)
1 parent 4cc8353 commit d5bd08d

3 files changed

Lines changed: 48 additions & 18 deletions

File tree

packages/emails/email-manager.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,18 +840,21 @@ export const sendCreditBalanceLimitReachedEmails = async ({
840840
export const sendDelegationCredentialDisabledEmail = async ({
841841
recipientEmail,
842842
recipientName,
843-
connectionName,
843+
calendarAppName,
844+
conferencingAppName,
844845
}: {
845846
recipientEmail: string;
846847
recipientName?: string;
847-
connectionName: string;
848+
calendarAppName: string;
849+
conferencingAppName: string;
848850
}) => {
849851
await sendEmail(
850852
() =>
851853
new DelegationCredentialDisabledEmail({
852854
recipientEmail,
853855
recipientName,
854-
connectionName,
856+
calendarAppName,
857+
conferencingAppName,
855858
})
856859
);
857860
};
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
2+
import { WEBAPP_URL } from "@calcom/lib/constants";
23

34
import BaseEmail from "./_base-email";
45

56
export default class DelegationCredentialDisabledEmail extends BaseEmail {
67
recipientEmail: string;
78
recipientName?: string;
8-
connectionName: string;
9+
calendarAppName: string;
10+
conferencingAppName: string;
911

1012
constructor({
1113
recipientEmail,
1214
recipientName,
13-
connectionName,
15+
calendarAppName,
16+
conferencingAppName,
1417
}: {
1518
recipientEmail: string;
1619
recipientName?: string;
17-
connectionName: string;
20+
calendarAppName: string;
21+
conferencingAppName: string;
1822
}) {
1923
super();
2024
this.name = "DELEGATION_CREDENTIAL_DISABLED";
2125
this.recipientEmail = recipientEmail;
2226
this.recipientName = recipientName;
23-
this.connectionName = connectionName;
27+
this.calendarAppName = calendarAppName;
28+
this.conferencingAppName = conferencingAppName;
2429
}
2530

2631
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
2732
return {
2833
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
2934
to: this.recipientEmail,
30-
subject: `You might need to connect your ${this.connectionName} Calendar`,
35+
subject: `You might need to connect your ${this.calendarAppName}`,
3136
html: await this.getHtml(),
3237
text: this.getTextBody(),
3338
};
@@ -36,20 +41,27 @@ export default class DelegationCredentialDisabledEmail extends BaseEmail {
3641
async getHtml() {
3742
return `
3843
<div style="font-family: Arial, sans-serif;">
39-
<h2>Action Required: Connect your ${this.connectionName} Calendar</h2>
44+
<h2>Action Required: Connect your ${this.calendarAppName}</h2>
4045
<p>
4146
${this.recipientName ? `Hi ${this.recipientName},` : "Hello,"}
4247
</p>
4348
<p>
4449
An admin has disabled Delegation Credential for your organization. You may need to connect your <b>${
45-
this.connectionName
46-
} Calendar</b> manually to continue receiving bookings and updates.
50+
this.calendarAppName
51+
}</b> to use Cal.com effectively. Connecting your calendar is crucial as it allows us to check for conflicts to prevent double bookings and automatically add new events to your schedule.
4752
</p>
4853
<p>
49-
Please log in to your Cal.com account and connect your calendar from your settings page.
54+
Please log in to your Cal.com account and connect your calendar from your settings page by visiting: <a href="${WEBAPP_URL}/settings/my-account/calendars">${WEBAPP_URL}/settings/my-account/calendars</a>.
5055
</p>
5156
<p>
52-
If you have already connected your calendar, you can ignore this message.
57+
Additionally, please ensure you have the ${
58+
this.conferencingAppName
59+
} app installed. You can manage your conferencing apps here: <a href="${WEBAPP_URL}/settings/my-account/conferencing">${WEBAPP_URL}/settings/my-account/conferencing</a>.
60+
</p>
61+
<p>
62+
If you have already connected your calendar and installed ${
63+
this.conferencingAppName
64+
}, you can ignore this message.
5365
</p>
5466
<p>
5567
Thank you,<br />The Cal.com Team
@@ -59,6 +71,6 @@ export default class DelegationCredentialDisabledEmail extends BaseEmail {
5971
}
6072

6173
protected getTextBody(): string {
62-
return `Action Required: Connect your ${this.connectionName} Calendar\n\nAn admin has disabled Delegation Credential for your organization. You may need to connect your ${this.connectionName} Calendar manually to continue receiving bookings and updates.\n\nPlease log in to your Cal.com account and connect your calendar from your settings page.\n\nIf you have already connected your calendar, you can ignore this message.\n\nThank you,\nThe Cal.com Team`;
74+
return `Action Required: Connect your ${this.calendarAppName}\n\nAn admin has disabled Delegation Credential for your organization. You may need to connect your ${this.calendarAppName} manually to continue receiving bookings and updates, and to allow Cal.com to check for conflicts to prevent double bookings and automatically add new events to your schedule.\n\nPlease log in to your Cal.com account and connect your calendar from your settings page by visiting: ${WEBAPP_URL}/settings/my-account/calendars.\n\nAdditionally, please ensure you have the ${this.conferencingAppName} app installed. You can manage your conferencing apps here: ${WEBAPP_URL}/settings/my-account/conferencing.\n\nIf you have already connected your calendar and installed ${this.conferencingAppName}, you can ignore this message.\n\nThank you,\nThe Cal.com Team`;
6375
}
6476
}

packages/trpc/server/routers/viewer/delegationCredential/toggleEnabled.handler.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,31 @@ export async function toggleDelegationCredentialEnabled(
6969

7070
if (!shouldBeEnabled) {
7171
const affectedMemberships = await getAffectedMembersForDisable({ delegationCredentialId: input.id });
72-
const connectionName = currentDelegationCredential.workspacePlatform?.name;
73-
if (!connectionName) {
74-
log.error(`Delegation credential ${input.id} has no workspace platform name`);
72+
const slug = currentDelegationCredential.workspacePlatform?.slug;
73+
if (!slug) {
74+
log.error(`Delegation credential ${input.id} has no workspace platform slug`);
7575
}
76+
77+
let calendarAppName;
78+
let conferencingAppName;
79+
80+
if (slug === "google") {
81+
calendarAppName = "Google Calendar";
82+
conferencingAppName = "Google Meet";
83+
} else if (slug === "microsoft") {
84+
calendarAppName = "Microsoft 365";
85+
conferencingAppName = "Microsoft Teams";
86+
} else {
87+
throw new Error(`Unsupported workspace platform slug: ${slug}`);
88+
}
89+
7690
for (const membership of affectedMemberships) {
7791
if (membership.email) {
7892
await sendDelegationCredentialDisabledEmail({
7993
recipientEmail: membership.email,
8094
recipientName: membership.name || undefined,
81-
connectionName,
95+
calendarAppName,
96+
conferencingAppName,
8297
});
8398
}
8499
}

0 commit comments

Comments
 (0)