chore: Add host default language to workflow reminder weekdays (#18029)

* chore: Add host default language to workflow reminder weekdays

* update
This commit is contained in:
Anik Dhabal Babu authored and GitHub committed 2024-12-06 15:56:03 +00:00
1 parent 6de26b3c43
commit 091400b7d5
15 files changed
+53 -25

No files matched your search

@@ -264,6 +264,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
);
emailContent = emailRatingTemplate({
isEditingMode: true,
locale: reminder.booking.user?.locale || "en",
action: reminder.workflowStep.action || WorkflowActions.EMAIL_ADDRESS,
timeFormat: getTimeFormatStringFromUserTimeFormat(reminder.booking.user?.timeFormat),
startTime: reminder.booking.startTime.toISOString() || "",
@@ -152,6 +152,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
} else if (reminder.workflowStep.template === WorkflowTemplates.REMINDER) {
message = smsReminderTemplate(
false,
reminder.booking.user?.locale || "en",
reminder.workflowStep.action,
getTimeFormatStringFromUserTimeFormat(reminder.booking.user?.timeFormat),
reminder.booking?.startTime.toISOString() || "",
@@ -77,6 +77,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const templateFunction = getWhatsappTemplateFunction(reminder.workflowStep.template);
const message = templateFunction(
false,
reminder.booking.user?.locale || "en",
reminder.workflowStep.action,
getTimeFormatStringFromUserTimeFormat(reminder.booking.user?.timeFormat),
reminder.booking?.startTime.toISOString() || "",
@@ -137,12 +137,12 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
if (isSMSAction(action)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
smsReminderTemplate(true, action, timeFormat)
smsReminderTemplate(true, i18n.language, action, timeFormat)
);
} else if (isWhatsappAction(action)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
whatsappReminderTemplate(true, action, timeFormat)
whatsappReminderTemplate(true, i18n.language, action, timeFormat)
);
} else {
const reminderBodyTemplate = emailReminderTemplate(true, i18n.language, action, timeFormat).emailBody;
@@ -159,7 +159,7 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
form.setValue(`steps.${step.stepNumber - 1}.emailSubject`, subjectTemplate);
}
} else if (step && isWhatsappAction(step.action)) {
const templateBody = getWhatsappTemplateForAction(step.action, step.template, timeFormat);
const templateBody = getWhatsappTemplateForAction(step.action, i18n.language, step.template, timeFormat);
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, templateBody);
}
@@ -516,12 +516,12 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
if (isSMSAction(val.value)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
smsReminderTemplate(true, val.value, timeFormat)
smsReminderTemplate(true, i18n.language, val.value, timeFormat)
);
} else if (isWhatsappAction(val.value)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
whatsappReminderTemplate(true, val.value, timeFormat)
whatsappReminderTemplate(true, i18n.language, val.value, timeFormat)
);
} else {
const emailReminderBody = emailReminderTemplate(
@@ -824,12 +824,12 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
if (isWhatsappAction(action)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
whatsappReminderTemplate(true, action, timeFormat)
whatsappReminderTemplate(true, i18n.language, action, timeFormat)
);
} else if (isSMSAction(action)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
smsReminderTemplate(true, action, timeFormat)
smsReminderTemplate(true, i18n.language, action, timeFormat)
);
} else {
form.setValue(
@@ -844,17 +844,27 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
} else if (val.value === WorkflowTemplates.RATING) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
emailRatingTemplate({ isEditingMode: true, action, timeFormat }).emailBody
emailRatingTemplate({
isEditingMode: true,
locale: i18n.language,
action,
timeFormat,
}).emailBody
);
form.setValue(
`steps.${step.stepNumber - 1}.emailSubject`,
emailRatingTemplate({ isEditingMode: true, action, timeFormat }).emailSubject
emailRatingTemplate({
isEditingMode: true,
locale: i18n.language,
action,
timeFormat,
}).emailSubject
);
} else {
if (isWhatsappAction(action)) {
form.setValue(
`steps.${step.stepNumber - 1}.reminderBody`,
getWhatsappTemplateForAction(action, val.value, timeFormat)
getWhatsappTemplateForAction(action, i18n.language, val.value, timeFormat)
);
} else {
form.setValue(`steps.${step.stepNumber - 1}.reminderBody`, "");
@@ -80,9 +80,10 @@ export function getWhatsappTemplateFunction(template?: WorkflowTemplates): typeo
export function getWhatsappTemplateForAction(
action: WorkflowActions,
locale: string,
template: WorkflowTemplates,
timeFormat: TimeFormat
): string | null {
const templateFunction = getWhatsappTemplateFunction(template);
return templateFunction(true, action, timeFormat);
return templateFunction(true, locale, action, timeFormat);
}
@@ -198,6 +198,7 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) =>
} else if (template === WorkflowTemplates.RATING) {
emailContent = emailRatingTemplate({
isEditingMode: true,
locale: evt.organizer.language.locale,
action,
timeFormat: evt.organizer.timeFormat,
startTime,
@@ -170,6 +170,7 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => {
smsMessage =
smsReminderTemplate(
false,
evt.organizer.language.locale,
action,
evt.organizer.timeFormat,
evt.startTime,
@@ -109,14 +109,14 @@ const customTemplate = (
variable.startsWith("START_TIME_")
) {
const dateFormat = variable.substring(11, text.length);
const formattedDate = variables.eventDate?.format(dateFormat);
const formattedDate = variables.eventDate?.locale(locale).format(dateFormat);
dynamicText = dynamicText.replace(`{${variable}}`, formattedDate || "");
return;
}
if (variable.startsWith("EVENT_END_TIME_")) {
const dateFormat = variable.substring(15, text.length);
const formattedDate = variables.eventEndTime?.format(dateFormat);
const formattedDate = variables.eventEndTime?.locale(locale).format(dateFormat);
dynamicText = dynamicText.replace(`{${variable}}`, formattedDate || "");
return;
}
@@ -5,6 +5,7 @@ import { WorkflowActions } from "@calcom/prisma/enums";
const emailRatingTemplate = ({
isEditingMode,
locale,
action,
timeFormat,
startTime,
@@ -18,6 +19,7 @@ const emailRatingTemplate = ({
noShowUrl,
}: {
isEditingMode: boolean;
locale: string;
action: WorkflowActions;
timeFormat?: TimeFormat;
startTime?: string;
@@ -45,9 +47,9 @@ const emailRatingTemplate = ({
ratingUrl = "{RATING_URL}";
noShowUrl = "{NO_SHOW_URL}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format(dateTimeFormat);
eventDate = dayjs(startTime).tz(timeZone).locale(locale).format(dateTimeFormat);
endTime = dayjs(endTime).tz(timeZone).format(currentTimeFormat);
endTime = dayjs(endTime).tz(timeZone).locale(locale).format(currentTimeFormat);
}
const emailSubject = `How was your recent experience? ${eventName}`;
@@ -4,6 +4,7 @@ import { WorkflowActions } from "@calcom/prisma/enums";
const smsReminderTemplate = (
isEditingMode: boolean,
locale: string,
action?: WorkflowActions,
timeFormat?: TimeFormat,
startTime?: string,
@@ -24,8 +25,8 @@ const smsReminderTemplate = (
attendee = action === WorkflowActions.SMS_ATTENDEE ? "{ORGANIZER}" : "{ATTENDEE}";
name = action === WorkflowActions.SMS_ATTENDEE ? "{ATTENDEE}" : "{ORGANIZER}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).format(currentTimeFormat);
eventDate = dayjs(startTime).tz(timeZone).locale(locale).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).locale(locale).format(currentTimeFormat);
}
const templateOne = `Hi${
@@ -4,6 +4,7 @@ import { WorkflowActions } from "@calcom/prisma/enums";
export const whatsappEventCancelledTemplate = (
isEditingMode: boolean,
locale: string,
action?: WorkflowActions,
timeFormat?: TimeFormat,
startTime?: string,
@@ -25,8 +26,8 @@ export const whatsappEventCancelledTemplate = (
attendee = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ORGANIZER}" : "{ATTENDEE}";
name = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ATTENDEE}" : "{ORGANIZER}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).format(currentTimeFormat);
eventDate = dayjs(startTime).tz(timeZone).locale(locale).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).locale(locale).format(currentTimeFormat);
}
const templateOne = `Hi${
@@ -4,6 +4,7 @@ import { WorkflowActions } from "@calcom/prisma/enums";
export const whatsappEventCompletedTemplate = (
isEditingMode: boolean,
locale: string,
action?: WorkflowActions,
timeFormat?: TimeFormat,
startTime?: string,
@@ -25,8 +26,8 @@ export const whatsappEventCompletedTemplate = (
attendee = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ORGANIZER}" : "{ATTENDEE}";
name = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ATTENDEE}" : "{ORGANIZER}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).format(currentTimeFormat);
eventDate = dayjs(startTime).tz(timeZone).locale(locale).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).locale(locale).format(currentTimeFormat);
}
const templateOne = `Hi${
@@ -4,6 +4,7 @@ import { WorkflowActions } from "@calcom/prisma/enums";
export const whatsappReminderTemplate = (
isEditingMode: boolean,
locale: string,
action?: WorkflowActions,
timeFormat?: TimeFormat,
startTime?: string,
@@ -25,8 +26,8 @@ export const whatsappReminderTemplate = (
attendee = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ORGANIZER}" : "{ATTENDEE}";
name = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ATTENDEE}" : "{ORGANIZER}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).format(currentTimeFormat);
eventDate = dayjs(startTime).tz(timeZone).locale(locale).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).locale(locale).format(currentTimeFormat);
}
const templateOne = `Hi${
@@ -4,6 +4,7 @@ import { WorkflowActions } from "@calcom/prisma/enums";
export const whatsappEventRescheduledTemplate = (
isEditingMode: boolean,
locale: string,
action?: WorkflowActions,
timeFormat?: TimeFormat,
startTime?: string,
@@ -25,8 +26,8 @@ export const whatsappEventRescheduledTemplate = (
attendee = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ORGANIZER}" : "{ATTENDEE}";
name = action === WorkflowActions.WHATSAPP_ATTENDEE ? "{ATTENDEE}" : "{ORGANIZER}";
} else {
eventDate = dayjs(startTime).tz(timeZone).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).format(currentTimeFormat);
eventDate = dayjs(startTime).tz(timeZone).locale(locale).format("YYYY MMM D");
startTime = dayjs(startTime).tz(timeZone).locale(locale).format(currentTimeFormat);
}
const templateOne = `Hi${
@@ -76,6 +76,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
textMessage =
whatsappReminderTemplate(
false,
evt.organizer.language.locale,
action,
evt.organizer.timeFormat,
evt.startTime,
@@ -89,6 +90,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
textMessage =
whatsappEventCancelledTemplate(
false,
evt.organizer.language.locale,
action,
evt.organizer.timeFormat,
evt.startTime,
@@ -102,6 +104,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
textMessage =
whatsappEventRescheduledTemplate(
false,
evt.organizer.language.locale,
action,
evt.organizer.timeFormat,
evt.startTime,
@@ -115,6 +118,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
textMessage =
whatsappEventCompletedTemplate(
false,
evt.organizer.language.locale,
action,
evt.organizer.timeFormat,
evt.startTime,
@@ -128,6 +132,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
textMessage =
whatsappReminderTemplate(
false,
evt.organizer.language.locale,
action,
evt.organizer.timeFormat,
evt.startTime,