2023-02-16 22:39:57 +00:00
|
|
|
import type { App_RoutingForms_Form } from "@prisma/client";
|
|
|
|
|
2022-11-03 14:40:03 +00:00
|
|
|
import { renderEmail } from "@calcom/emails";
|
|
|
|
import BaseEmail from "@calcom/emails/templates/_base-email";
|
|
|
|
|
2023-09-07 15:22:39 +00:00
|
|
|
import type { OrderedResponses } from "../../types/types";
|
2022-11-03 14:40:03 +00:00
|
|
|
|
|
|
|
type Form = Pick<App_RoutingForms_Form, "id" | "name">;
|
|
|
|
export default class ResponseEmail extends BaseEmail {
|
2023-09-07 15:22:39 +00:00
|
|
|
orderedResponses: OrderedResponses;
|
2022-11-03 14:40:03 +00:00
|
|
|
toAddresses: string[];
|
|
|
|
form: Form;
|
2023-09-07 15:22:39 +00:00
|
|
|
constructor({
|
|
|
|
toAddresses,
|
|
|
|
orderedResponses,
|
|
|
|
form,
|
|
|
|
}: {
|
|
|
|
form: Form;
|
|
|
|
toAddresses: string[];
|
|
|
|
orderedResponses: OrderedResponses;
|
|
|
|
}) {
|
2022-11-03 14:40:03 +00:00
|
|
|
super();
|
|
|
|
this.form = form;
|
2023-09-07 15:22:39 +00:00
|
|
|
this.orderedResponses = orderedResponses;
|
2022-11-03 14:40:03 +00:00
|
|
|
this.toAddresses = toAddresses;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected getNodeMailerPayload(): Record<string, unknown> {
|
|
|
|
const toAddresses = this.toAddresses;
|
|
|
|
const subject = `${this.form.name} has a new response`;
|
|
|
|
return {
|
|
|
|
from: `Cal.com <${this.getMailerOptions().from}>`,
|
|
|
|
to: toAddresses.join(","),
|
|
|
|
subject,
|
|
|
|
html: renderEmail("ResponseEmail", {
|
|
|
|
form: this.form,
|
2023-09-07 15:22:39 +00:00
|
|
|
orderedResponses: this.orderedResponses,
|
2022-11-03 14:40:03 +00:00
|
|
|
subject,
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|