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 16:38:37 -07:00
committed by GitHub
co-authored by CarinaWolli alannnc
parent 6a8db56dbb
commit c26efcabe4
4 changed files with 28 additions and 18 deletions
@@ -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,
@@ -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) {