2022-06-06 17:49:56 +00:00
|
|
|
import { createEvent, DateArray, Person } from "ics";
|
|
|
|
|
2022-06-28 20:40:58 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2022-11-29 20:27:29 +00:00
|
|
|
import { getManageLink } from "@calcom/lib/CalEventParser";
|
2023-01-04 22:14:46 +00:00
|
|
|
import { APP_NAME } from "@calcom/lib/constants";
|
2022-07-22 17:27:06 +00:00
|
|
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
2022-06-06 17:49:56 +00:00
|
|
|
|
2022-09-15 01:27:46 +00:00
|
|
|
import { renderEmail } from "..";
|
2022-06-06 17:49:56 +00:00
|
|
|
import OrganizerScheduledEmail from "./organizer-scheduled-email";
|
|
|
|
|
2022-09-15 01:27:46 +00:00
|
|
|
export default class AttendeeWasRequestedToRescheduleEmail extends OrganizerScheduledEmail {
|
2022-06-06 17:49:56 +00:00
|
|
|
private metadata: { rescheduleLink: string };
|
2022-06-10 00:32:34 +00:00
|
|
|
constructor(calEvent: CalendarEvent, metadata: { rescheduleLink: string }) {
|
|
|
|
super(calEvent);
|
2022-06-06 17:49:56 +00:00
|
|
|
this.metadata = metadata;
|
|
|
|
}
|
|
|
|
protected getNodeMailerPayload(): Record<string, unknown> {
|
|
|
|
const toAddresses = [this.calEvent.attendees[0].email];
|
|
|
|
|
|
|
|
return {
|
|
|
|
icalEvent: {
|
|
|
|
filename: "event.ics",
|
|
|
|
content: this.getiCalEventAsString(),
|
|
|
|
},
|
2023-01-04 22:14:46 +00:00
|
|
|
from: `${APP_NAME} <${this.getMailerOptions().from}>`,
|
2022-06-06 17:49:56 +00:00
|
|
|
to: toAddresses.join(","),
|
|
|
|
subject: `${this.t("requested_to_reschedule_subject_attendee", {
|
|
|
|
eventType: this.calEvent.type,
|
|
|
|
name: this.calEvent.attendees[0].name,
|
|
|
|
})}`,
|
2022-09-15 01:27:46 +00:00
|
|
|
html: renderEmail("AttendeeWasRequestedToRescheduleEmail", {
|
2022-06-06 17:49:56 +00:00
|
|
|
calEvent: this.calEvent,
|
|
|
|
attendee: this.calEvent.organizer,
|
|
|
|
metadata: this.metadata,
|
|
|
|
}),
|
|
|
|
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.t("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 `
|
|
|
|
<p style="height: 6px"></p>
|
|
|
|
<div style="line-height: 6px;">
|
|
|
|
<p style="color: #494949;">${this.t("when")}</p>
|
|
|
|
<p style="color: #494949; font-weight: 400; line-height: 24px;text-decoration: line-through;">
|
|
|
|
${this.t(this.getOrganizerStart("dddd").toLowerCase())}, ${this.t(
|
|
|
|
this.getOrganizerStart("MMMM").toLowerCase()
|
|
|
|
)} ${this.getOrganizerStart("D")}, ${this.getOrganizerStart("YYYY")} | ${this.getOrganizerStart(
|
|
|
|
"h:mma"
|
|
|
|
)} - ${this.getOrganizerEnd("h:mma")} <span style="color: #888888">(${this.getTimezone()})</span>
|
|
|
|
</p>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected getTextBody(): string {
|
|
|
|
return `
|
|
|
|
${this.t("request_reschedule_title_attendee")}
|
|
|
|
${this.t("request_reschedule_subtitle", {
|
|
|
|
organizer: this.calEvent.organizer.name,
|
|
|
|
})},
|
|
|
|
${this.getWhen()}
|
|
|
|
${this.t("need_to_reschedule_or_cancel")}
|
2022-11-29 20:27:29 +00:00
|
|
|
${getManageLink(this.calEvent)}
|
2022-06-06 17:49:56 +00:00
|
|
|
`.replace(/(<([^>]+)>)/gi, "");
|
|
|
|
}
|
|
|
|
}
|