disable standard confirmation emails if workflow exists (#8747)
* add switches to advanced even type settings * only show switches when workflow is enabled * check in event type update handler if user is allowed to disable standard emails * don't send emails if disabled * make sure emails can't be disabled if no workflow exist * send workflow emails to all attendees * code clean up * add translations * always send to all attendees when scheduling reminders * change text --------- Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
1 parent
6fc9e9315d
commit
36d8554fd5
12 files changed
+241
-55
No files matched your search
@@ -33,6 +33,10 @@ import {
|
||||
} from "@calcom/emails";
|
||||
import { getBookingFieldsWithSystemFields } from "@calcom/features/bookings/lib/getBookingFields";
|
||||
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
|
||||
import {
|
||||
allowDisablingAttendeeConfirmationEmails,
|
||||
allowDisablingHostConfirmationEmails,
|
||||
} from "@calcom/features/ee/workflows/lib/allowDisablingStandardEmails";
|
||||
import { deleteScheduledEmailReminder } from "@calcom/features/ee/workflows/lib/reminders/emailReminderManager";
|
||||
import { scheduleWorkflowReminders } from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
|
||||
import { deleteScheduledSMSReminder } from "@calcom/features/ee/workflows/lib/reminders/smsReminderManager";
|
||||
@@ -1966,6 +1970,26 @@ async function handler(
|
||||
videoCallUrl = metadata.hangoutLink || defaultLocationUrl || videoCallUrl;
|
||||
}
|
||||
if (noEmail !== true) {
|
||||
let isHostConfirmationEmailsDisabled = false;
|
||||
let isAttendeeConfirmationEmailDisabled = false;
|
||||
|
||||
const workflows = eventType.workflows.map((workflow) => workflow.workflow);
|
||||
|
||||
if (eventType.workflows) {
|
||||
isHostConfirmationEmailsDisabled =
|
||||
eventType.metadata?.disableStandardEmails?.confirmation?.host || false;
|
||||
isAttendeeConfirmationEmailDisabled =
|
||||
eventType.metadata?.disableStandardEmails?.confirmation?.attendee || false;
|
||||
|
||||
if (isHostConfirmationEmailsDisabled) {
|
||||
isHostConfirmationEmailsDisabled = allowDisablingHostConfirmationEmails(workflows);
|
||||
}
|
||||
|
||||
if (isAttendeeConfirmationEmailDisabled) {
|
||||
isAttendeeConfirmationEmailDisabled = allowDisablingAttendeeConfirmationEmails(workflows);
|
||||
}
|
||||
}
|
||||
|
||||
await sendScheduledEmails(
|
||||
{
|
||||
...evt,
|
||||
@@ -1973,7 +1997,9 @@ async function handler(
|
||||
additionalNotes,
|
||||
customInputs,
|
||||
},
|
||||
eventNameObject
|
||||
eventNameObject,
|
||||
isHostConfirmationEmailsDisabled,
|
||||
isAttendeeConfirmationEmailDisabled
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ const ProfileView = () => {
|
||||
const utils = trpc.useContext();
|
||||
const session = useSession();
|
||||
const [firstRender, setFirstRender] = useState(true);
|
||||
|
||||
|
||||
useLayoutEffect(() => {
|
||||
document.body.focus();
|
||||
}, []);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { Workflow, WorkflowStep } from "@calcom/prisma/client";
|
||||
import { WorkflowTriggerEvents } from "@calcom/prisma/client";
|
||||
import { WorkflowActions } from "@calcom/prisma/enums";
|
||||
|
||||
export function allowDisablingHostConfirmationEmails(
|
||||
workflows: (Workflow & {
|
||||
steps: WorkflowStep[];
|
||||
})[]
|
||||
) {
|
||||
return !!workflows.find(
|
||||
(workflow) =>
|
||||
workflow.trigger === WorkflowTriggerEvents.NEW_EVENT &&
|
||||
!!workflow.steps.find((step) => step.action === WorkflowActions.EMAIL_HOST)
|
||||
);
|
||||
}
|
||||
|
||||
export function allowDisablingAttendeeConfirmationEmails(
|
||||
workflows: (Workflow & {
|
||||
steps: WorkflowStep[];
|
||||
})[]
|
||||
) {
|
||||
return !!workflows.find(
|
||||
(workflow) =>
|
||||
workflow.trigger === WorkflowTriggerEvents.NEW_EVENT &&
|
||||
!!workflow.steps.find((step) => step.action === WorkflowActions.EMAIL_ATTENDEE)
|
||||
);
|
||||
}
|
||||
@@ -134,17 +134,33 @@ export const scheduleEmailReminder = async (
|
||||
triggerEvent === WorkflowTriggerEvents.RESCHEDULE_EVENT
|
||||
) {
|
||||
try {
|
||||
await sgMail.send({
|
||||
to: sendTo,
|
||||
from: {
|
||||
email: senderEmail,
|
||||
name: sender,
|
||||
},
|
||||
subject: emailContent.emailSubject,
|
||||
html: emailContent.emailBody,
|
||||
batchId: batchIdResponse[1].batch_id,
|
||||
replyTo: evt.organizer.email,
|
||||
});
|
||||
if (Array.isArray(sendTo)) {
|
||||
for (const email of sendTo) {
|
||||
await sgMail.send({
|
||||
to: email,
|
||||
from: {
|
||||
email: senderEmail,
|
||||
name: sender,
|
||||
},
|
||||
subject: emailContent.emailSubject,
|
||||
html: emailContent.emailBody,
|
||||
batchId: batchIdResponse[1].batch_id,
|
||||
replyTo: evt.organizer.email,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await sgMail.send({
|
||||
to: sendTo,
|
||||
from: {
|
||||
email: senderEmail,
|
||||
name: sender,
|
||||
},
|
||||
subject: emailContent.emailSubject,
|
||||
html: emailContent.emailBody,
|
||||
batchId: batchIdResponse[1].batch_id,
|
||||
replyTo: evt.organizer.email,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error sending Email");
|
||||
}
|
||||
|
||||
@@ -77,16 +77,19 @@ export const scheduleWorkflowReminders = async (args: ScheduleWorkflowRemindersA
|
||||
step.action === WorkflowActions.EMAIL_ATTENDEE ||
|
||||
step.action === WorkflowActions.EMAIL_HOST
|
||||
) {
|
||||
let sendTo = "";
|
||||
let sendTo: string[] = [];
|
||||
|
||||
switch (step.action) {
|
||||
case WorkflowActions.EMAIL_HOST:
|
||||
sendTo = evt.organizer?.email || "";
|
||||
sendTo = [evt.organizer?.email || ""];
|
||||
break;
|
||||
case WorkflowActions.EMAIL_ATTENDEE:
|
||||
sendTo = !!emailAttendeeSendToOverride
|
||||
? emailAttendeeSendToOverride
|
||||
: evt.attendees?.[0]?.email || "";
|
||||
const attendees = !!emailAttendeeSendToOverride
|
||||
? [emailAttendeeSendToOverride]
|
||||
: evt.attendees?.map((attendee) => attendee.email);
|
||||
|
||||
sendTo = attendees;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user