Fixes timezone in reminder templates (workflows) (#3376)
* fix time zone in reminder template * fix timezone in email subject * add missing timezone * fix date in sms reminder template * use organizer time zone if message send to host * fix build error Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Omar López <zomars@me.com>
This commit is contained in:
parent
9162d90504
commit
75b817531e
|
@ -55,16 +55,11 @@ export const scheduleEmailReminder = async (
|
||||||
|
|
||||||
const name = action === WorkflowActions.EMAIL_HOST ? evt.organizer.name : evt.attendees[0].name;
|
const name = action === WorkflowActions.EMAIL_HOST ? evt.organizer.name : evt.attendees[0].name;
|
||||||
const attendeeName = action === WorkflowActions.EMAIL_HOST ? evt.attendees[0].name : evt.organizer.name;
|
const attendeeName = action === WorkflowActions.EMAIL_HOST ? evt.attendees[0].name : evt.organizer.name;
|
||||||
|
const timeZone = action === WorkflowActions.EMAIL_HOST ? evt.organizer.timeZone : evt.attendees[0].timeZone;
|
||||||
|
|
||||||
switch (template) {
|
switch (template) {
|
||||||
case WorkflowTemplates.REMINDER:
|
case WorkflowTemplates.REMINDER:
|
||||||
const emailTemplate = emailReminderTemplate(
|
const emailTemplate = emailReminderTemplate(startTime, evt.title, timeZone, attendeeName, name);
|
||||||
startTime,
|
|
||||||
evt.title,
|
|
||||||
evt.attendees[0].timeZone,
|
|
||||||
attendeeName,
|
|
||||||
name
|
|
||||||
);
|
|
||||||
emailSubject = emailTemplate.subject;
|
emailSubject = emailTemplate.subject;
|
||||||
emailBody = emailTemplate.body;
|
emailBody = emailTemplate.body;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -20,7 +20,7 @@ export enum timeUnitLowerCase {
|
||||||
export type BookingInfo = {
|
export type BookingInfo = {
|
||||||
uid?: string | null;
|
uid?: string | null;
|
||||||
attendees: { name: string; email: string; timeZone: string }[];
|
attendees: { name: string; email: string; timeZone: string }[];
|
||||||
organizer: { name: string; email: string };
|
organizer: { name: string; email: string; timeZone: string };
|
||||||
startTime: string;
|
startTime: string;
|
||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
@ -48,12 +48,12 @@ export const scheduleSMSReminder = async (
|
||||||
|
|
||||||
const name = action === WorkflowActions.SMS_ATTENDEE ? evt.attendees[0].name : "";
|
const name = action === WorkflowActions.SMS_ATTENDEE ? evt.attendees[0].name : "";
|
||||||
const attendeeName = action === WorkflowActions.SMS_ATTENDEE ? evt.organizer.name : evt.attendees[0].name;
|
const attendeeName = action === WorkflowActions.SMS_ATTENDEE ? evt.organizer.name : evt.attendees[0].name;
|
||||||
|
const timeZone =
|
||||||
|
action === WorkflowActions.SMS_ATTENDEE ? evt.attendees[0].timeZone : evt.organizer.timeZone;
|
||||||
|
|
||||||
switch (template) {
|
switch (template) {
|
||||||
case WorkflowTemplates.REMINDER:
|
case WorkflowTemplates.REMINDER:
|
||||||
message =
|
message = smsReminderTemplate(evt.startTime, evt.title, timeZone, attendeeName, name) || message;
|
||||||
smsReminderTemplate(evt.startTime, evt.title, evt.attendees[0].timeZone, attendeeName, name) ||
|
|
||||||
message;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,19 @@ import dayjs from "@calcom/dayjs";
|
||||||
const emailReminderTemplate = (
|
const emailReminderTemplate = (
|
||||||
startTime: string,
|
startTime: string,
|
||||||
eventName: string,
|
eventName: string,
|
||||||
attendeeTimeZone: string,
|
timeZone: string,
|
||||||
attendee: string,
|
attendee: string,
|
||||||
name: string
|
name: string
|
||||||
) => {
|
) => {
|
||||||
const templateSubject = `Reminder: ${eventName} at ${dayjs(startTime).format("YYYY MMM D h:mmA")}`;
|
const templateSubject = `Reminder: ${eventName} at ${dayjs(startTime)
|
||||||
|
.tz(timeZone)
|
||||||
|
.format("YYYY MMM D h:mmA")}`;
|
||||||
|
|
||||||
const templateBody = `Hi ${name},\n\n this is a reminder that your meeting (${eventName}) with ${attendee} is on ${dayjs(
|
const templateBody = `Hi ${name},\n\nThis is a reminder that your meeting (${eventName}) with ${attendee} is on ${dayjs(
|
||||||
startTime
|
startTime
|
||||||
).format("YYYY MMM D")} at ${dayjs(startTime).format("h:mmA")} ${attendeeTimeZone}.`;
|
)
|
||||||
|
.tz(timeZone)
|
||||||
|
.format("YYYY MMM D")} at ${dayjs(startTime).tz(timeZone).format("h:mmA")} ${timeZone}.`;
|
||||||
|
|
||||||
const emailContent = { subject: templateSubject, body: templateBody };
|
const emailContent = { subject: templateSubject, body: templateBody };
|
||||||
|
|
||||||
|
|
|
@ -3,21 +3,21 @@ import dayjs from "@calcom/dayjs";
|
||||||
const smsReminderTemplate = (
|
const smsReminderTemplate = (
|
||||||
startTime: string,
|
startTime: string,
|
||||||
eventName: string,
|
eventName: string,
|
||||||
attendeeTimeZone: string,
|
timeZone: string,
|
||||||
attendee: string,
|
attendee: string,
|
||||||
name?: string
|
name?: string
|
||||||
) => {
|
) => {
|
||||||
const templateOne = `Hi${name ? ` ${name}` : ``}, this is a reminder that your meeting (${eventName}) with
|
const templateOne = `Hi${name ? ` ${name}` : ``}, this is a reminder that your meeting (${eventName}) with
|
||||||
${attendee} is on ${dayjs(startTime).format("MMM D")} at ${dayjs(startTime).format(
|
${attendee} is on ${dayjs(startTime).tz(timeZone).format("MMM D")} at ${dayjs(startTime)
|
||||||
"h:mmA"
|
.tz(timeZone)
|
||||||
)} ${attendeeTimeZone}`;
|
.format("h:mmA")} ${timeZone}`;
|
||||||
|
|
||||||
//Twilio recomments message to be no longer than 320 characters
|
//Twilio recomments message to be no longer than 320 characters
|
||||||
if (templateOne.length <= 320) return templateOne;
|
if (templateOne.length <= 320) return templateOne;
|
||||||
|
|
||||||
const templateTwo = `Hi, this is a reminder that your meeting with ${attendee} is on ${dayjs(
|
const templateTwo = `Hi, this is a reminder that your meeting with ${attendee} is on ${dayjs(startTime)
|
||||||
startTime
|
.tz(timeZone)
|
||||||
).format("MMM D")} at ${dayjs(startTime).format("h:mmA")}`;
|
.format("MMM D")} at ${dayjs(startTime).tz(timeZone).format("h:mmA")} ${timeZone}`;
|
||||||
|
|
||||||
//Twilio supports up to 1600 characters
|
//Twilio supports up to 1600 characters
|
||||||
if (templateTwo.length <= 1600) return templateTwo;
|
if (templateTwo.length <= 1600) return templateTwo;
|
||||||
|
|
|
@ -87,12 +87,17 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
? reminder.booking?.user?.name
|
? reminder.booking?.user?.name
|
||||||
: reminder.booking?.attendees[0].name;
|
: reminder.booking?.attendees[0].name;
|
||||||
|
|
||||||
|
const timeZone =
|
||||||
|
reminder.workflowStep.action === WorkflowActions.EMAIL_ATTENDEE
|
||||||
|
? reminder.booking?.attendees[0].timeZone
|
||||||
|
: reminder.booking?.user?.timeZone;
|
||||||
|
|
||||||
switch (reminder.workflowStep.template) {
|
switch (reminder.workflowStep.template) {
|
||||||
case WorkflowTemplates.REMINDER:
|
case WorkflowTemplates.REMINDER:
|
||||||
emailTemplate = emailReminderTemplate(
|
emailTemplate = emailReminderTemplate(
|
||||||
reminder.booking?.startTime.toISOString() || "",
|
reminder.booking?.startTime.toISOString() || "",
|
||||||
reminder.booking?.eventType?.title || "",
|
reminder.booking?.eventType?.title || "",
|
||||||
reminder.booking?.attendees[0].timeZone || "",
|
timeZone || "",
|
||||||
attendeeName || "",
|
attendeeName || "",
|
||||||
name || ""
|
name || ""
|
||||||
);
|
);
|
||||||
|
|
|
@ -66,13 +66,18 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
? reminder.booking?.user?.name
|
? reminder.booking?.user?.name
|
||||||
: reminder.booking?.attendees[0].name;
|
: reminder.booking?.attendees[0].name;
|
||||||
|
|
||||||
|
const timeZone =
|
||||||
|
reminder.workflowStep.action === WorkflowActions.SMS_ATTENDEE
|
||||||
|
? reminder.booking?.attendees[0].timeZone
|
||||||
|
: reminder.booking?.user?.timeZone;
|
||||||
|
|
||||||
let message: string | null = reminder.workflowStep.reminderBody;
|
let message: string | null = reminder.workflowStep.reminderBody;
|
||||||
switch (reminder.workflowStep.template) {
|
switch (reminder.workflowStep.template) {
|
||||||
case WorkflowTemplates.REMINDER:
|
case WorkflowTemplates.REMINDER:
|
||||||
message = smsReminderTemplate(
|
message = smsReminderTemplate(
|
||||||
reminder.booking?.startTime.toISOString() || "",
|
reminder.booking?.startTime.toISOString() || "",
|
||||||
reminder.booking?.eventType?.title || "",
|
reminder.booking?.eventType?.title || "",
|
||||||
reminder.booking?.attendees[0].timeZone || "",
|
timeZone || "",
|
||||||
attendeeName || "",
|
attendeeName || "",
|
||||||
userName
|
userName
|
||||||
);
|
);
|
||||||
|
|
|
@ -334,8 +334,12 @@ export const workflowsRouter = createProtectedRouter()
|
||||||
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
||||||
}),
|
}),
|
||||||
organizer: booking.user
|
organizer: booking.user
|
||||||
? { name: booking.user.name || "", email: booking.user.email }
|
? {
|
||||||
: { name: "", email: "" },
|
name: booking.user.name || "",
|
||||||
|
email: booking.user.email,
|
||||||
|
timeZone: booking.user.timeZone,
|
||||||
|
}
|
||||||
|
: { name: "", email: "", timeZone: "" },
|
||||||
startTime: booking.startTime.toISOString(),
|
startTime: booking.startTime.toISOString(),
|
||||||
title: booking.title,
|
title: booking.title,
|
||||||
};
|
};
|
||||||
|
@ -485,8 +489,12 @@ export const workflowsRouter = createProtectedRouter()
|
||||||
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
||||||
}),
|
}),
|
||||||
organizer: booking.user
|
organizer: booking.user
|
||||||
? { name: booking.user.name || "", email: booking.user.email }
|
? {
|
||||||
: { name: "", email: "" },
|
name: booking.user.name || "",
|
||||||
|
email: booking.user.email,
|
||||||
|
timeZone: booking.user.timeZone,
|
||||||
|
}
|
||||||
|
: { name: "", email: "", timeZone: "" },
|
||||||
startTime: booking.startTime.toISOString(),
|
startTime: booking.startTime.toISOString(),
|
||||||
title: booking.title,
|
title: booking.title,
|
||||||
};
|
};
|
||||||
|
@ -578,8 +586,12 @@ export const workflowsRouter = createProtectedRouter()
|
||||||
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
return { name: attendee.name, email: attendee.email, timeZone: attendee.timeZone };
|
||||||
}),
|
}),
|
||||||
organizer: booking.user
|
organizer: booking.user
|
||||||
? { name: booking.user.name || "", email: booking.user.email }
|
? {
|
||||||
: { name: "", email: "" },
|
name: booking.user.name || "",
|
||||||
|
email: booking.user.email,
|
||||||
|
timeZone: booking.user.timeZone,
|
||||||
|
}
|
||||||
|
: { name: "", email: "", timeZone: "" },
|
||||||
startTime: booking.startTime.toISOString(),
|
startTime: booking.startTime.toISOString(),
|
||||||
title: booking.title,
|
title: booking.title,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user