import dayjs from "dayjs"; import localizedFormat from "dayjs/plugin/localizedFormat"; import timezone from "dayjs/plugin/timezone"; import toArray from "dayjs/plugin/toArray"; import utc from "dayjs/plugin/utc"; import { createEvent, DateArray, Person } from "ics"; import { getCancelLink } from "@calcom/lib/CalEventParser"; import { CalendarEvent } from "@calcom/types/Calendar"; import BaseTemplate from "./base-template"; import { emailHead, emailSchedulingBodyHeader, emailBodyLogo, emailScheduledBodyHeaderContent, emailSchedulingBodyDivider, } from "./common"; dayjs.extend(utc); dayjs.extend(timezone); dayjs.extend(localizedFormat); dayjs.extend(toArray); export default class OrganizerRequestRescheduledEmail extends BaseTemplate { private metadata: { rescheduleLink: string }; constructor(calEvent: CalendarEvent, metadata: { rescheduleLink: string }) { super(calEvent); this.metadata = metadata; } protected getNodeMailerPayload(): Record { const toAddresses = [this.calEvent.organizer.email]; return { icalEvent: { filename: "event.ics", content: this.getiCalEventAsString(), }, from: `Cal.com <${this.getMailerOptions().from}>`, to: toAddresses.join(","), subject: `${this.calEvent.organizer.language.translate("rescheduled_event_type_subject", { eventType: this.calEvent.type, name: this.calEvent.attendees[0].name, date: `${this.getOrganizerStart().format("h:mma")} - ${this.getOrganizerEnd().format( "h:mma" )}, ${this.calEvent.organizer.language.translate( this.getOrganizerStart().format("dddd").toLowerCase() )}, ${this.calEvent.organizer.language.translate( this.getOrganizerStart().format("MMMM").toLowerCase() )} ${this.getOrganizerStart().format("D")}, ${this.getOrganizerStart().format("YYYY")}`, })}`, html: this.getHtmlBody(), text: this.getTextBody(), }; } // @OVERRIDE protected getiCalEventAsString(): string | undefined { const icsEvent = createEvent({ start: dayjs(this.calEvent.startTime) .utc() .toArray() .slice(0, 6) .map((v, i) => (i === 1 ? v + 1 : v)) as DateArray, startInputType: "utc", productId: "calendso/ics", title: this.calEvent.organizer.language.translate("ics_event_title", { eventType: this.calEvent.type, name: this.calEvent.attendees[0].name, }), description: this.getTextBody(), duration: { minutes: dayjs(this.calEvent.endTime).diff(dayjs(this.calEvent.startTime), "minute") }, organizer: { name: this.calEvent.organizer.name, email: this.calEvent.organizer.email }, attendees: this.calEvent.attendees.map((attendee: Person) => ({ name: attendee.name, email: attendee.email, })), status: "CANCELLED", method: "CANCEL", }); if (icsEvent.error) { throw icsEvent.error; } return icsEvent.value; } // @OVERRIDE protected getWhen(): string { return `

${this.calEvent.organizer.language.translate("when")}

${this.calEvent.organizer.language.translate( this.getOrganizerStart().format("dddd").toLowerCase() )}, ${this.calEvent.organizer.language.translate( this.getOrganizerStart().format("MMMM").toLowerCase() )} ${this.getOrganizerStart().format("D")}, ${this.getOrganizerStart().format( "YYYY" )} | ${this.getOrganizerStart().format("h:mma")} - ${this.getOrganizerEnd().format( "h:mma" )} (${this.getTimezone()})

`; } protected getTextBody(): string { return ` ${this.calEvent.organizer.language.translate("request_reschedule_title_organizer", { attendee: this.calEvent.attendees[0].name, })} ${this.calEvent.organizer.language.translate("request_reschedule_subtitle_organizer", { attendee: this.calEvent.attendees[0].name, })}, ${this.getWhat()} ${this.getWhen()} ${this.getLocation()} ${this.getAdditionalNotes()} ${this.calEvent.organizer.language.translate("need_to_reschedule_or_cancel")} ${getCancelLink(this.calEvent)} `.replace(/(<([^>]+)>)/gi, ""); } protected getHtmlBody(): string { const headerContent = this.calEvent.organizer.language.translate("rescheduled_event_type_subject", { eventType: this.calEvent.type, name: this.calEvent.attendees[0].name, date: `${this.getOrganizerStart().format("h:mma")} - ${this.getOrganizerEnd().format( "h:mma" )}, ${this.calEvent.organizer.language.translate( this.getOrganizerStart().format("dddd").toLowerCase() )}, ${this.calEvent.organizer.language.translate( this.getOrganizerStart().format("MMMM").toLowerCase() )} ${this.getOrganizerStart().format("D")}, ${this.getOrganizerStart().format("YYYY")}`, }); return ` ${emailHead(headerContent)}
${emailSchedulingBodyHeader("calendarCircle")} ${emailScheduledBodyHeaderContent( this.calEvent.organizer.language.translate("request_reschedule_title_organizer", { attendee: this.calEvent.attendees[0].name, }), this.calEvent.organizer.language.translate("request_reschedule_subtitle_organizer", { attendee: this.calEvent.attendees[0].name, }) )} ${emailSchedulingBodyDivider()}
${this.getWhat()} ${this.getWhen()} ${this.getWho()} ${this.getAdditionalNotes()}
${emailBodyLogo()}
`; } }