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:
Carina WollendorferandCarinaWolli authored and GitHub committed 2023-05-09 17:08:14 +00:00
1 parent 6fc9e9315d
commit 36d8554fd5
12 files changed
+241 -55

No files matched your search

@@ -5,6 +5,7 @@ import type { NextApiResponse, GetServerSidePropsContext } from "next";
import { stripeDataSchema } from "@calcom/app-store/stripepayment/lib/server";
import updateChildrenEventTypes from "@calcom/features/ee/managed-event-types/lib/handleChildrenEventTypes";
import { validateIntervalLimitOrder } from "@calcom/lib";
import { WorkflowActions, WorkflowTriggerEvents } from "@calcom/prisma/client";
import { SchedulingType } from "@calcom/prisma/enums";
import { TRPCError } from "@trpc/server";
@@ -141,6 +142,44 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
};
}
if (input.metadata?.disableStandardEmails) {
//check if user is allowed to disabled standard emails
const workflows = await ctx.prisma.workflow.findMany({
where: {
activeOn: {
some: {
eventTypeId: input.id,
},
},
trigger: WorkflowTriggerEvents.NEW_EVENT,
},
include: {
steps: true,
},
});
if (input.metadata?.disableStandardEmails.confirmation?.host) {
if (
!workflows.find(
(workflow) => !!workflow.steps.find((step) => step.action === WorkflowActions.EMAIL_HOST)
)
) {
input.metadata.disableStandardEmails.confirmation.host = false;
}
}
if (input.metadata?.disableStandardEmails.confirmation?.attendee) {
if (
!workflows.find(
(workflow) => !!workflow.steps.find((step) => step.action === WorkflowActions.EMAIL_ATTENDEE)
)
) {
input.metadata.disableStandardEmails.confirmation.attendee = false;
}
}
}
if (input?.price || input.metadata?.apps?.stripe?.price) {
data.price = input.price || input.metadata?.apps?.stripe?.price;
const paymentCredential = await ctx.prisma.credential.findFirst({
@@ -237,14 +237,14 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
step.action === WorkflowActions.EMAIL_ATTENDEE /*||
step.action === WorkflowActions.EMAIL_ADDRESS*/
) {
let sendTo = "";
let sendTo: string[] = [];
switch (step.action) {
case WorkflowActions.EMAIL_HOST:
sendTo = bookingInfo.organizer?.email;
sendTo = [bookingInfo.organizer?.email];
break;
case WorkflowActions.EMAIL_ATTENDEE:
sendTo = bookingInfo.attendees[0].email;
sendTo = bookingInfo.attendees.map((attendee) => attendee.email);
break;
/*case WorkflowActions.EMAIL_ADDRESS:
sendTo = step.sendTo || "";*/
@@ -435,14 +435,14 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
newStep.action === WorkflowActions.EMAIL_ATTENDEE /*||
newStep.action === WorkflowActions.EMAIL_ADDRESS*/
) {
let sendTo = "";
let sendTo: string[] = [];
switch (newStep.action) {
case WorkflowActions.EMAIL_HOST:
sendTo = bookingInfo.organizer?.email;
sendTo = [bookingInfo.organizer?.email];
break;
case WorkflowActions.EMAIL_ATTENDEE:
sendTo = bookingInfo.attendees[0].email;
sendTo = bookingInfo.attendees.map((attendee) => attendee.email);
break;
/*case WorkflowActions.EMAIL_ADDRESS:
sendTo = newStep.sendTo || "";*/
@@ -565,14 +565,14 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
step.action === WorkflowActions.EMAIL_HOST /*||
step.action === WorkflowActions.EMAIL_ADDRESS*/
) {
let sendTo = "";
let sendTo: string[] = [];
switch (step.action) {
case WorkflowActions.EMAIL_HOST:
sendTo = bookingInfo.organizer?.email;
sendTo = [bookingInfo.organizer?.email];
break;
case WorkflowActions.EMAIL_ATTENDEE:
sendTo = bookingInfo.attendees[0].email;
sendTo = bookingInfo.attendees.map((attendee) => attendee.email);
break;
/*case WorkflowActions.EMAIL_ADDRESS:
sendTo = step.sendTo || "";*/