improve-delegation-disable-email-communication (#21456)
This commit is contained in:
@@ -840,18 +840,21 @@ export const sendCreditBalanceLimitReachedEmails = async ({
|
||||
export const sendDelegationCredentialDisabledEmail = async ({
|
||||
recipientEmail,
|
||||
recipientName,
|
||||
connectionName,
|
||||
calendarAppName,
|
||||
conferencingAppName,
|
||||
}: {
|
||||
recipientEmail: string;
|
||||
recipientName?: string;
|
||||
connectionName: string;
|
||||
calendarAppName: string;
|
||||
conferencingAppName: string;
|
||||
}) => {
|
||||
await sendEmail(
|
||||
() =>
|
||||
new DelegationCredentialDisabledEmail({
|
||||
recipientEmail,
|
||||
recipientName,
|
||||
connectionName,
|
||||
calendarAppName,
|
||||
conferencingAppName,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
import { EMAIL_FROM_NAME } from "@calcom/lib/constants";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
|
||||
import BaseEmail from "./_base-email";
|
||||
|
||||
export default class DelegationCredentialDisabledEmail extends BaseEmail {
|
||||
recipientEmail: string;
|
||||
recipientName?: string;
|
||||
connectionName: string;
|
||||
calendarAppName: string;
|
||||
conferencingAppName: string;
|
||||
|
||||
constructor({
|
||||
recipientEmail,
|
||||
recipientName,
|
||||
connectionName,
|
||||
calendarAppName,
|
||||
conferencingAppName,
|
||||
}: {
|
||||
recipientEmail: string;
|
||||
recipientName?: string;
|
||||
connectionName: string;
|
||||
calendarAppName: string;
|
||||
conferencingAppName: string;
|
||||
}) {
|
||||
super();
|
||||
this.name = "DELEGATION_CREDENTIAL_DISABLED";
|
||||
this.recipientEmail = recipientEmail;
|
||||
this.recipientName = recipientName;
|
||||
this.connectionName = connectionName;
|
||||
this.calendarAppName = calendarAppName;
|
||||
this.conferencingAppName = conferencingAppName;
|
||||
}
|
||||
|
||||
protected async getNodeMailerPayload(): Promise<Record<string, unknown>> {
|
||||
return {
|
||||
from: `${EMAIL_FROM_NAME} <${this.getMailerOptions().from}>`,
|
||||
to: this.recipientEmail,
|
||||
subject: `You might need to connect your ${this.connectionName} Calendar`,
|
||||
subject: `You might need to connect your ${this.calendarAppName}`,
|
||||
html: await this.getHtml(),
|
||||
text: this.getTextBody(),
|
||||
};
|
||||
@@ -36,20 +41,27 @@ export default class DelegationCredentialDisabledEmail extends BaseEmail {
|
||||
async getHtml() {
|
||||
return `
|
||||
<div style="font-family: Arial, sans-serif;">
|
||||
<h2>Action Required: Connect your ${this.connectionName} Calendar</h2>
|
||||
<h2>Action Required: Connect your ${this.calendarAppName}</h2>
|
||||
<p>
|
||||
${this.recipientName ? `Hi ${this.recipientName},` : "Hello,"}
|
||||
</p>
|
||||
<p>
|
||||
An admin has disabled Delegation Credential for your organization. You may need to connect your <b>${
|
||||
this.connectionName
|
||||
} Calendar</b> manually to continue receiving bookings and updates.
|
||||
this.calendarAppName
|
||||
}</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.
|
||||
</p>
|
||||
<p>
|
||||
Please log in to your Cal.com account and connect your calendar from your settings page.
|
||||
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>.
|
||||
</p>
|
||||
<p>
|
||||
If you have already connected your calendar, you can ignore this message.
|
||||
Additionally, please ensure you have the ${
|
||||
this.conferencingAppName
|
||||
} app installed. You can manage your conferencing apps here: <a href="${WEBAPP_URL}/settings/my-account/conferencing">${WEBAPP_URL}/settings/my-account/conferencing</a>.
|
||||
</p>
|
||||
<p>
|
||||
If you have already connected your calendar and installed ${
|
||||
this.conferencingAppName
|
||||
}, you can ignore this message.
|
||||
</p>
|
||||
<p>
|
||||
Thank you,<br />The Cal.com Team
|
||||
@@ -59,6 +71,6 @@ export default class DelegationCredentialDisabledEmail extends BaseEmail {
|
||||
}
|
||||
|
||||
protected getTextBody(): string {
|
||||
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`;
|
||||
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`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,16 +69,31 @@ export async function toggleDelegationCredentialEnabled(
|
||||
|
||||
if (!shouldBeEnabled) {
|
||||
const affectedMemberships = await getAffectedMembersForDisable({ delegationCredentialId: input.id });
|
||||
const connectionName = currentDelegationCredential.workspacePlatform?.name;
|
||||
if (!connectionName) {
|
||||
log.error(`Delegation credential ${input.id} has no workspace platform name`);
|
||||
const slug = currentDelegationCredential.workspacePlatform?.slug;
|
||||
if (!slug) {
|
||||
log.error(`Delegation credential ${input.id} has no workspace platform slug`);
|
||||
}
|
||||
|
||||
let calendarAppName;
|
||||
let conferencingAppName;
|
||||
|
||||
if (slug === "google") {
|
||||
calendarAppName = "Google Calendar";
|
||||
conferencingAppName = "Google Meet";
|
||||
} else if (slug === "microsoft") {
|
||||
calendarAppName = "Microsoft 365";
|
||||
conferencingAppName = "Microsoft Teams";
|
||||
} else {
|
||||
throw new Error(`Unsupported workspace platform slug: ${slug}`);
|
||||
}
|
||||
|
||||
for (const membership of affectedMemberships) {
|
||||
if (membership.email) {
|
||||
await sendDelegationCredentialDisabledEmail({
|
||||
recipientEmail: membership.email,
|
||||
recipientName: membership.name || undefined,
|
||||
connectionName,
|
||||
calendarAppName,
|
||||
conferencingAppName,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user