chore: Fixing ICS file in workflows & ICS calendar descriptions [CAL-4409] (#16731)

* Remove title and subtitle from ICS calendar description

* Remove unused method

* Use generateIcsString function for workflows

* Type fixes

* Refactor typing of CalEventParser

* WIP

* Type fixes

* Fix test

* Fix tests

* type fixes

* Remove duplicate code before `scheduleEmailReminder`
This commit is contained in:
Joe Au-Yeung authored and GitHub committed 2024-10-07 10:50:50 -04:00
1 parent 44f6f2e320
commit 0d757039f7
25 files changed
+173 -223

No files matched your search

@@ -3,10 +3,12 @@ import type { NextApiRequest, NextApiResponse } from "next";
import { v4 as uuidv4 } from "uuid";
import dayjs from "@calcom/dayjs";
import generateIcsString from "@calcom/emails/lib/generateIcsString";
import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses";
import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server";
import logger from "@calcom/lib/logger";
import { defaultHandler } from "@calcom/lib/server";
import { getTranslation } from "@calcom/lib/server/i18n";
import { getTimeFormatStringFromUserTimeFormat } from "@calcom/lib/timeFormat";
import prisma from "@calcom/prisma";
import { SchedulingType, WorkflowActions, WorkflowMethods, WorkflowTemplates } from "@calcom/prisma/enums";
@@ -18,7 +20,6 @@ import {
getAllRemindersToDelete,
getAllUnscheduledReminders,
} from "../lib/getWorkflowReminders";
import { getiCalEventAsString } from "../lib/getiCalEventAsString";
import {
cancelScheduledEmail,
deleteScheduledSend,
@@ -271,6 +272,37 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
if (emailContent.emailSubject.length > 0 && !emailBodyEmpty && sendTo) {
const batchId = await getBatchId();
const booking = reminder.booking;
const t = await getTranslation(booking.user?.locale ?? "en", "common");
const attendeePromises = [];
for (const attendee of booking.attendees) {
attendeePromises.push(
getTranslation(attendee.locale ?? "en", "common").then((tAttendee) => ({
...attendee,
language: { locale: attendee.locale ?? "en", translate: tAttendee },
}))
);
}
const attendees = await Promise.all(attendeePromises);
const event = {
...booking,
startTime: dayjs(booking.startTime).utc().format(),
endTime: dayjs(booking.endTime).utc().format(),
type: booking.eventType?.slug ?? "",
organizer: {
name: booking.user?.name ?? "",
email: booking.user?.email ?? "",
timeZone: booking.user?.timeZone ?? "",
language: { translate: t, locale: booking.user?.locale ?? "en" },
},
attendees,
};
sendEmailPromises.push(
sendSendgridMail(
{
@@ -283,7 +315,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
attachments: reminder.workflowStep.includeCalendarEvent
? [
{
content: Buffer.from(getiCalEventAsString(reminder.booking) || "").toString("base64"),
content: Buffer.from(
generateIcsString({ event, status: "CONFIRMED" }) || ""
).toString("base64"),
filename: "event.ics",
type: "text/calendar; method=REQUEST",
disposition: "attachment",