Removes 'Test Action' button in workflows (#6418)

* comment out test action feature

* code clean up

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
pull/6430/head
Carina Wollendorfer 2023-01-12 11:03:30 -05:00 committed by GitHub
parent 9507138f29
commit e27b1b1bc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 144 additions and 145 deletions

View File

@ -166,7 +166,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
},
});
const testActionMutation = trpc.viewer.workflows.testAction.useMutation({
/* const testActionMutation = trpc.viewer.workflows.testAction.useMutation({
onSuccess: async () => {
showToast(t("notification_sent"), "success");
},
@ -184,7 +184,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
}
showToast(message, "error");
},
});
}); */
//trigger
if (!step) {
@ -630,10 +630,10 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
</div>
</div>
)}
{form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_ATTENDEE && (
{/* {form.getValues(`steps.${step.stepNumber - 1}.action`) !== WorkflowActions.SMS_ATTENDEE && (
<Button
type="button"
className="mt-7 w-full"
className="w-full mt-7"
onClick={() => {
let isEmpty = false;
@ -703,11 +703,11 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
color="secondary">
<div className="w-full">{t("test_action")}</div>
</Button>
)}
)*/}
</div>
</div>
</div>
<Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}>
{/* <Dialog open={confirmationDialogOpen} onOpenChange={setConfirmationDialogOpen}>
<ConfirmationDialogContent
variety="warning"
title={t("test_workflow_action")}
@ -728,7 +728,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
}}>
{t("send_sms_to_number", { number: form.getValues(`steps.${step.stepNumber - 1}.sendTo`) })}
</ConfirmationDialogContent>
</Dialog>
</Dialog> */}
<Dialog open={isAdditionalInputsDialogOpen} onOpenChange={setIsAdditionalInputsDialogOpen}>
<DialogContent type="creation" className="sm:max-w-[610px] md:h-[570px]">
<div className="-m-3 h-[430px] overflow-x-hidden overflow-y-scroll sm:m-0">

View File

@ -832,7 +832,7 @@ export const workflowsRouter = router({
workflow,
};
}),
testAction: authedRateLimitedProcedure({ intervalInMs: 10000, limit: 3 })
/* testAction: authedRateLimitedProcedure({ intervalInMs: 10000, limit: 3 })
.input(
z.object({
step: z.object({
@ -851,151 +851,150 @@ export const workflowsRouter = router({
reminderBody: z.string(),
})
)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.mutation(async ({ ctx, input }) => {
throw new TRPCError({ code: "FORBIDDEN", message: "Test action temporarily disabled" });
// const { user } = ctx;
// const { step, emailSubject, reminderBody } = input;
// const { action, template, sendTo, sender } = step;
.mutation(async ({ ctx, input }) => {
const { user } = ctx;
const { step, emailSubject, reminderBody } = input;
const { action, template, sendTo, sender } = step;
// const senderID = sender || SENDER_ID;
const senderID = sender || SENDER_ID;
// if (action === WorkflowActions.SMS_NUMBER) {
// if (!sendTo) throw new TRPCError({ code: "BAD_REQUEST", message: "Missing sendTo" });
// const verifiedNumbers = await ctx.prisma.verifiedNumber.findFirst({
// where: {
// userId: ctx.user.id,
// phoneNumber: sendTo,
// },
// });
// if (!verifiedNumbers)
// throw new TRPCError({ code: "UNAUTHORIZED", message: "Phone number is not verified" });
// }
if (action === WorkflowActions.SMS_NUMBER) {
if (!sendTo) throw new TRPCError({ code: "BAD_REQUEST", message: "Missing sendTo" });
const verifiedNumbers = await ctx.prisma.verifiedNumber.findFirst({
where: {
userId: ctx.user.id,
phoneNumber: sendTo,
},
});
if (!verifiedNumbers)
throw new TRPCError({ code: "UNAUTHORIZED", message: "Phone number is not verified" });
}
// try {
// const userWorkflow = await ctx.prisma.workflow.findUnique({
// where: {
// id: step.workflowId,
// },
// select: {
// userId: true,
// steps: true,
// },
// });
try {
const userWorkflow = await ctx.prisma.workflow.findUnique({
where: {
id: step.workflowId,
},
select: {
userId: true,
steps: true,
},
});
// if (!userWorkflow || userWorkflow.userId !== user.id) {
// throw new TRPCError({ code: "UNAUTHORIZED" });
// }
if (!userWorkflow || userWorkflow.userId !== user.id) {
throw new TRPCError({ code: "UNAUTHORIZED" });
}
// if (isSMSAction(step.action) /*|| step.action === WorkflowActions.EMAIL_ADDRESS*/) {
// const hasTeamPlan = (await ctx.prisma.membership.count({ where: { userId: user.id } })) > 0;
// if (!hasTeamPlan) {
// throw new TRPCError({ code: "UNAUTHORIZED", message: "Team plan needed" });
// }
// }
if (isSMSAction(step.action) /*|| step.action === WorkflowActions.EMAIL_ADDRESS*/ /*) {
const hasTeamPlan = (await ctx.prisma.membership.count({ where: { userId: user.id } })) > 0;
if (!hasTeamPlan) {
throw new TRPCError({ code: "UNAUTHORIZED", message: "Team plan needed" });
}
}
// const booking = await ctx.prisma.booking.findFirst({
// orderBy: {
// createdAt: "desc",
// },
// where: {
// userId: ctx.user.id,
// },
// include: {
// attendees: true,
// user: true,
// },
// });
const booking = await ctx.prisma.booking.findFirst({
orderBy: {
createdAt: "desc",
},
where: {
userId: ctx.user.id,
},
include: {
attendees: true,
user: true,
},
});
// let evt: BookingInfo;
// if (booking) {
// evt = {
// uid: booking?.uid,
// attendees:
// booking?.attendees.map((attendee) => {
// return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
// }) || [],
// organizer: {
// language: {
// locale: booking?.user?.locale || "",
// },
// name: booking?.user?.name || "",
// email: booking?.user?.email || "",
// timeZone: booking?.user?.timeZone || "",
// },
// startTime: booking?.startTime.toISOString() || "",
// endTime: booking?.endTime.toISOString() || "",
// title: booking?.title || "",
// location: booking?.location || null,
// additionalNotes: booking?.description || null,
// customInputs: booking?.customInputs,
// };
// } else {
// //if no booking exists create an example booking
// evt = {
// attendees: [{ name: "John Doe", email: "john.doe@example.com", timeZone: "Europe/London" }],
// organizer: {
// language: {
// locale: ctx.user.locale,
// },
// name: ctx.user.name || "",
// email: ctx.user.email,
// timeZone: ctx.user.timeZone,
// },
// startTime: dayjs().add(10, "hour").toISOString(),
// endTime: dayjs().add(11, "hour").toISOString(),
// title: "Example Booking",
// location: "Office",
// additionalNotes: "These are additional notes",
// };
// }
let evt: BookingInfo;
if (booking) {
evt = {
uid: booking?.uid,
attendees:
booking?.attendees.map((attendee) => {
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
}) || [],
organizer: {
language: {
locale: booking?.user?.locale || "",
},
name: booking?.user?.name || "",
email: booking?.user?.email || "",
timeZone: booking?.user?.timeZone || "",
},
startTime: booking?.startTime.toISOString() || "",
endTime: booking?.endTime.toISOString() || "",
title: booking?.title || "",
location: booking?.location || null,
additionalNotes: booking?.description || null,
customInputs: booking?.customInputs,
};
} else {
//if no booking exists create an example booking
evt = {
attendees: [{ name: "John Doe", email: "john.doe@example.com", timeZone: "Europe/London" }],
organizer: {
language: {
locale: ctx.user.locale,
},
name: ctx.user.name || "",
email: ctx.user.email,
timeZone: ctx.user.timeZone,
},
startTime: dayjs().add(10, "hour").toISOString(),
endTime: dayjs().add(11, "hour").toISOString(),
title: "Example Booking",
location: "Office",
additionalNotes: "These are additional notes",
};
}
// if (
// action === WorkflowActions.EMAIL_ATTENDEE ||
// action === WorkflowActions.EMAIL_HOST /*||
// action === WorkflowActions.EMAIL_ADDRESS*/
// ) {
// scheduleEmailReminder(
// evt,
// WorkflowTriggerEvents.NEW_EVENT,
// action,
// { time: null, timeUnit: null },
// ctx.user.email,
// emailSubject,
// reminderBody,
// 0,
// template
// );
// return { message: "Notification sent" };
// } else if (action === WorkflowActions.SMS_NUMBER && sendTo) {
// scheduleSMSReminder(
// evt,
// sendTo,
// WorkflowTriggerEvents.NEW_EVENT,
// action,
// { time: null, timeUnit: null },
// reminderBody,
// 0,
// template,
// senderID,
// ctx.user.id
// );
// return { message: "Notification sent" };
// }
// return {
// ok: false,
// status: 500,
// message: "Notification could not be sent",
// };
// } catch (_err) {
// const error = getErrorFromUnknown(_err);
// return {
// ok: false,
// status: 500,
// message: error.message,
// };
// }
}),
if (
action === WorkflowActions.EMAIL_ATTENDEE ||
action === WorkflowActions.EMAIL_HOST /*||
action === WorkflowActions.EMAIL_ADDRESS*/
/*) {
scheduleEmailReminder(
evt,
WorkflowTriggerEvents.NEW_EVENT,
action,
{ time: null, timeUnit: null },
ctx.user.email,
emailSubject,
reminderBody,
0,
template
);
return { message: "Notification sent" };
} else if (action === WorkflowActions.SMS_NUMBER && sendTo) {
scheduleSMSReminder(
evt,
sendTo,
WorkflowTriggerEvents.NEW_EVENT,
action,
{ time: null, timeUnit: null },
reminderBody,
0,
template,
senderID,
ctx.user.id
);
return { message: "Notification sent" };
}
return {
ok: false,
status: 500,
message: "Notification could not be sent",
};
} catch (_err) {
const error = getErrorFromUnknown(_err);
return {
ok: false,
status: 500,
message: error.message,
};
}
}),
*/
activateEventType: authedProcedure
.input(
z.object({