2022-01-06 17:28:31 +00:00
|
|
|
import { Person } from "ics";
|
2021-06-29 21:43:18 +00:00
|
|
|
import short from "short-uuid";
|
2021-09-22 19:52:38 +00:00
|
|
|
import { v5 as uuidv5 } from "uuid";
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
2021-12-06 19:34:31 +00:00
|
|
|
|
2022-05-23 17:42:29 +00:00
|
|
|
import { WEBAPP_URL } from "./constants";
|
2021-06-29 21:43:18 +00:00
|
|
|
|
|
|
|
const translator = short();
|
|
|
|
|
2021-12-07 15:32:07 +00:00
|
|
|
// The odd indentation in this file is necessary because otherwise the leading tabs will be applied into the event description.
|
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
export const getWhat = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("what")}:
|
2021-12-06 19:34:31 +00:00
|
|
|
${calEvent.type}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getWhen = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("invitee_timezone")}:
|
2021-12-07 15:32:07 +00:00
|
|
|
${calEvent.attendees[0].timeZone}
|
2021-12-06 19:34:31 +00:00
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getWho = (calEvent: CalendarEvent) => {
|
|
|
|
const attendees = calEvent.attendees
|
|
|
|
.map((attendee) => {
|
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${attendee?.name || calEvent.organizer.language.translate("guest")}
|
2021-12-06 19:34:31 +00:00
|
|
|
${attendee.email}
|
|
|
|
`;
|
|
|
|
})
|
|
|
|
.join("");
|
|
|
|
|
|
|
|
const organizer = `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.name} - ${calEvent.organizer.language.translate("organizer")}
|
2021-12-06 19:34:31 +00:00
|
|
|
${calEvent.organizer.email}
|
|
|
|
`;
|
|
|
|
|
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("who")}:
|
2021-12-06 19:34:31 +00:00
|
|
|
${organizer + attendees}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getAdditionalNotes = (calEvent: CalendarEvent) => {
|
2022-04-28 15:05:29 +00:00
|
|
|
if (!calEvent.additionalNotes) {
|
|
|
|
return "";
|
|
|
|
}
|
2021-12-06 19:34:31 +00:00
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("additional_notes")}:
|
2022-04-07 18:22:11 +00:00
|
|
|
${calEvent.additionalNotes}
|
2021-12-06 19:34:31 +00:00
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
2022-05-23 17:42:29 +00:00
|
|
|
export const getCustomInputs = (calEvent: CalendarEvent) => {
|
|
|
|
if (!calEvent.customInputs) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
const customInputsString = Object.keys(calEvent.customInputs)
|
|
|
|
.map((key) => {
|
|
|
|
if (!calEvent.customInputs) return "";
|
|
|
|
if (calEvent.customInputs[key] !== "") {
|
|
|
|
return `
|
|
|
|
${key}:
|
|
|
|
${calEvent.customInputs[key]}
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.join("");
|
|
|
|
|
|
|
|
return customInputsString;
|
|
|
|
};
|
|
|
|
|
2022-04-07 18:22:11 +00:00
|
|
|
export const getDescription = (calEvent: CalendarEvent) => {
|
2022-04-28 15:05:29 +00:00
|
|
|
if (!calEvent.description) {
|
|
|
|
return "";
|
|
|
|
}
|
2022-04-07 18:22:11 +00:00
|
|
|
return `\n${calEvent.attendees[0].language.translate("description")}
|
|
|
|
${calEvent.description}
|
|
|
|
`;
|
|
|
|
};
|
2021-12-06 19:34:31 +00:00
|
|
|
export const getLocation = (calEvent: CalendarEvent) => {
|
2022-03-23 22:00:30 +00:00
|
|
|
let providerName = "";
|
2021-12-06 19:34:31 +00:00
|
|
|
|
|
|
|
if (calEvent.location && calEvent.location.includes("integrations:")) {
|
|
|
|
const location = calEvent.location.split(":")[1];
|
|
|
|
providerName = location[0].toUpperCase() + location.slice(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calEvent.videoCallData) {
|
|
|
|
return calEvent.videoCallData.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calEvent.additionInformation?.hangoutLink) {
|
|
|
|
return calEvent.additionInformation.hangoutLink;
|
|
|
|
}
|
|
|
|
|
2021-12-09 15:51:37 +00:00
|
|
|
return providerName || calEvent.location || "";
|
2021-12-06 19:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getManageLink = (calEvent: CalendarEvent) => {
|
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("need_to_reschedule_or_cancel")}
|
2021-12-06 19:34:31 +00:00
|
|
|
${getCancelLink(calEvent)}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUid = (calEvent: CalendarEvent): string => {
|
2021-11-26 11:03:43 +00:00
|
|
|
return calEvent.uid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
|
|
|
};
|
2021-07-21 12:01:48 +00:00
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
export const getCancelLink = (calEvent: CalendarEvent): string => {
|
2022-05-23 17:42:29 +00:00
|
|
|
return WEBAPP_URL + "/cancel/" + getUid(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
2021-12-06 19:34:31 +00:00
|
|
|
|
2021-12-07 15:32:07 +00:00
|
|
|
export const getRichDescription = (calEvent: CalendarEvent, attendee?: Person) => {
|
|
|
|
// Only the original attendee can make changes to the event
|
|
|
|
// Guests cannot
|
|
|
|
|
|
|
|
if (attendee && attendee === calEvent.attendees[0]) {
|
|
|
|
return `
|
|
|
|
${getWhat(calEvent)}
|
|
|
|
${getWhen(calEvent)}
|
|
|
|
${getWho(calEvent)}
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("where")}:
|
2021-12-07 15:32:07 +00:00
|
|
|
${getLocation(calEvent)}
|
2022-04-07 18:22:11 +00:00
|
|
|
${getDescription(calEvent)}
|
2021-12-07 15:32:07 +00:00
|
|
|
${getAdditionalNotes(calEvent)}
|
2022-05-23 17:42:29 +00:00
|
|
|
${getCustomInputs(calEvent)}
|
2021-12-07 15:32:07 +00:00
|
|
|
`.trim();
|
|
|
|
}
|
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
return `
|
2021-12-07 15:32:07 +00:00
|
|
|
${getWhat(calEvent)}
|
|
|
|
${getWhen(calEvent)}
|
|
|
|
${getWho(calEvent)}
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("where")}:
|
2021-12-07 15:32:07 +00:00
|
|
|
${getLocation(calEvent)}
|
2022-04-07 18:22:11 +00:00
|
|
|
${getDescription(calEvent)}
|
2021-12-07 15:32:07 +00:00
|
|
|
${getAdditionalNotes(calEvent)}
|
2022-05-23 17:42:29 +00:00
|
|
|
${getCustomInputs(calEvent)}
|
2021-12-07 15:32:07 +00:00
|
|
|
${getManageLink(calEvent)}
|
|
|
|
`.trim();
|
2021-12-06 19:34:31 +00:00
|
|
|
};
|