fix: customTemplate() function fails when no locale is given (#10201)

* fallback to en for locale

* remove console.log

* Fix nit changes

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: alannnc <alannnc@gmail.com>
This commit is contained in:
Carina Wollendorfer 2023-07-17 19:38:37 -04:00 committed by GitHub
parent 6a8db56dbb
commit c26efcabe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 18 deletions

View File

@ -191,22 +191,24 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
cancelLink: `/booking/${reminder.booking.uid}?cancel=true`,
rescheduleLink: `/${reminder.booking.user?.username}/${reminder.booking.eventType?.slug}?rescheduleUid=${reminder.booking.uid}`,
};
const emailLocale = locale || "en";
const emailSubject = customTemplate(
reminder.workflowStep.emailSubject || "",
variables,
locale || "",
emailLocale,
!!reminder.booking.user?.hideBranding
).text;
emailContent.emailSubject = emailSubject;
emailContent.emailBody = customTemplate(
reminder.workflowStep.reminderBody || "",
variables,
locale || "",
emailLocale,
!!reminder.booking.user?.hideBranding
).html;
emailBodyEmpty =
customTemplate(reminder.workflowStep.reminderBody || "", variables, locale || "").text.length === 0;
customTemplate(reminder.workflowStep.reminderBody || "", variables, emailLocale).text.length ===
0;
} else if (reminder.workflowStep.template === WorkflowTemplates.REMINDER) {
emailContent = emailReminderTemplate(
false,

View File

@ -116,7 +116,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const customMessage = customTemplate(
reminder.workflowStep.reminderBody || "",
variables,
locale || ""
locale || "en"
);
message = customMessage.text;
} else if (reminder.workflowStep.template === WorkflowTemplates.REMINDER) {

View File

@ -155,6 +155,7 @@ export const activateEventTypeHandler = async ({ ctx, input }: ActivateEventType
});
for (const booking of bookingsForReminders) {
const defaultLocale = "en";
const bookingInfo = {
uid: booking.uid,
attendees: booking.attendees.map((attendee) => {
@ -162,7 +163,7 @@ export const activateEventTypeHandler = async ({ ctx, input }: ActivateEventType
name: attendee.name,
email: attendee.email,
timeZone: attendee.timeZone,
language: { locale: attendee.locale || "" },
language: { locale: attendee.locale || defaultLocale },
};
}),
organizer: booking.user
@ -170,13 +171,13 @@ export const activateEventTypeHandler = async ({ ctx, input }: ActivateEventType
name: booking.user.name || "",
email: booking.user.email,
timeZone: booking.user.timeZone,
language: { locale: booking.user.locale || "" },
language: { locale: booking.user.locale || defaultLocale },
}
: { name: "", email: "", timeZone: "", language: { locale: "" } },
startTime: booking.startTime.toISOString(),
endTime: booking.endTime.toISOString(),
title: booking.title,
language: { locale: booking?.user?.locale || "" },
language: { locale: booking?.user?.locale || defaultLocale },
eventType: {
slug: booking.eventType?.slug,
},

View File

@ -257,9 +257,13 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
});
steps.forEach(async (step) => {
if (step.action !== WorkflowActions.SMS_ATTENDEE && step.action !== WorkflowActions.WHATSAPP_ATTENDEE) {
if (
step.action !== WorkflowActions.SMS_ATTENDEE &&
step.action !== WorkflowActions.WHATSAPP_ATTENDEE
) {
//as we do not have attendees phone number (user is notified about that when setting this action)
bookingsForReminders.forEach(async (booking) => {
const defaultLocale = "en";
const bookingInfo = {
uid: booking.uid,
attendees: booking.attendees.map((attendee) => {
@ -267,12 +271,12 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
name: attendee.name,
email: attendee.email,
timeZone: attendee.timeZone,
language: { locale: attendee.locale || "" },
language: { locale: attendee.locale || defaultLocale },
};
}),
organizer: booking.user
? {
language: { locale: booking.user.locale || "" },
language: { locale: booking.user.locale || defaultLocale },
name: booking.user.name || "",
email: booking.user.email,
timeZone: booking.user.timeZone,
@ -281,7 +285,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
startTime: booking.startTime.toISOString(),
endTime: booking.endTime.toISOString(),
title: booking.title,
language: { locale: booking?.user?.locale || "" },
language: { locale: booking?.user?.locale || defaultLocale },
eventType: {
slug: booking.eventType?.slug,
},
@ -482,6 +486,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
},
});
bookingsOfEventTypes.forEach(async (booking) => {
const defaultLocale = "en";
const bookingInfo = {
uid: booking.uid,
attendees: booking.attendees.map((attendee) => {
@ -489,12 +494,12 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
name: attendee.name,
email: attendee.email,
timeZone: attendee.timeZone,
language: { locale: attendee.locale || "" },
language: { locale: attendee.locale || defaultLocale },
};
}),
organizer: booking.user
? {
language: { locale: booking.user.locale || "" },
language: { locale: booking.user.locale || defaultLocale },
name: booking.user.name || "",
email: booking.user.email,
timeZone: booking.user.timeZone,
@ -503,7 +508,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
startTime: booking.startTime.toISOString(),
endTime: booking.endTime.toISOString(),
title: booking.title,
language: { locale: booking?.user?.locale || "" },
language: { locale: booking?.user?.locale || defaultLocale },
eventType: {
slug: booking.eventType?.slug,
},
@ -610,7 +615,8 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
if (
(trigger === WorkflowTriggerEvents.BEFORE_EVENT || trigger === WorkflowTriggerEvents.AFTER_EVENT) &&
eventTypesToCreateReminders &&
step.action !== WorkflowActions.SMS_ATTENDEE && step.action !== WorkflowActions.WHATSAPP_ATTENDEE
step.action !== WorkflowActions.SMS_ATTENDEE &&
step.action !== WorkflowActions.WHATSAPP_ATTENDEE
) {
const bookingsForReminders = await ctx.prisma.booking.findMany({
where: {
@ -627,6 +633,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
},
});
for (const booking of bookingsForReminders) {
const defaultLocale = "en";
const bookingInfo = {
uid: booking.uid,
attendees: booking.attendees.map((attendee) => {
@ -634,7 +641,7 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
name: attendee.name,
email: attendee.email,
timeZone: attendee.timeZone,
language: { locale: attendee.locale || "" },
language: { locale: attendee.locale || defaultLocale },
};
}),
organizer: booking.user
@ -642,13 +649,13 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
name: booking.user.name || "",
email: booking.user.email,
timeZone: booking.user.timeZone,
language: { locale: booking.user.locale || "" },
language: { locale: booking.user.locale || defaultLocale },
}
: { name: "", email: "", timeZone: "", language: { locale: "" } },
startTime: booking.startTime.toISOString(),
endTime: booking.endTime.toISOString(),
title: booking.title,
language: { locale: booking?.user?.locale || "" },
language: { locale: booking?.user?.locale || defaultLocale },
eventType: {
slug: booking.eventType?.slug,
},