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-18 21:05:49 +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-18 21:05:49 +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-10-19 16:11:50 +00:00
|
|
|
export const getAppsStatus = (calEvent: CalendarEvent) => {
|
|
|
|
if (!calEvent.appsStatus) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return `\n${calEvent.attendees[0].language.translate("apps_status")}
|
|
|
|
\n${calEvent.appsStatus.map(
|
|
|
|
(app) =>
|
|
|
|
`\t${app.appName} ${app.success >= 1 && `✅ ${app.success > 1 ? `(x${app.success})` : ""}`} ${
|
|
|
|
app.failures >= 1 && `❌ ${app.failures > 1 ? `(x${app.failures})` : ""}`
|
|
|
|
}`
|
|
|
|
)}
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
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-08-11 00:53:05 +00:00
|
|
|
const meetingUrl = getVideoCallUrl(calEvent);
|
|
|
|
if (meetingUrl) {
|
|
|
|
return meetingUrl;
|
|
|
|
}
|
|
|
|
const providerName = getProviderName(calEvent);
|
|
|
|
return providerName || calEvent.location || "";
|
|
|
|
};
|
2021-12-06 19:34:31 +00:00
|
|
|
|
2022-08-11 00:53:05 +00:00
|
|
|
export const getProviderName = (calEvent: CalendarEvent): string => {
|
|
|
|
// TODO: use getAppName from @calcom/app-store
|
2021-12-06 19:34:31 +00:00
|
|
|
if (calEvent.location && calEvent.location.includes("integrations:")) {
|
2022-09-15 01:27:46 +00:00
|
|
|
let location = calEvent.location.split(":")[1];
|
|
|
|
if (location === "daily") {
|
|
|
|
location = "Cal Video";
|
|
|
|
}
|
2022-08-11 00:53:05 +00:00
|
|
|
return location[0].toUpperCase() + location.slice(1);
|
2021-12-06 19:34:31 +00:00
|
|
|
}
|
2022-08-11 00:53:05 +00:00
|
|
|
// If location its a url, probably we should be validating it with a custom library
|
|
|
|
if (calEvent.location && /^https?:\/\//.test(calEvent.location)) {
|
|
|
|
return calEvent.location;
|
2021-12-06 19:34:31 +00:00
|
|
|
}
|
2022-08-11 00:53:05 +00:00
|
|
|
return "";
|
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-18 21:05:49 +00:00
|
|
|
return WEBAPP_URL + "/cancel/" + getUid(calEvent);
|
2021-11-26 11:03:43 +00:00
|
|
|
};
|
2021-12-06 19:34:31 +00:00
|
|
|
|
2022-10-27 09:13:52 +00:00
|
|
|
export const getRescheduleLink = (calEvent: CalendarEvent): string => {
|
|
|
|
return WEBAPP_URL + "/reschedule/" + getUid(calEvent);
|
|
|
|
};
|
|
|
|
|
2022-06-21 09:14:10 +00:00
|
|
|
export const getRichDescription = (calEvent: CalendarEvent /*, attendee?: Person*/) => {
|
2022-06-06 17:49:56 +00:00
|
|
|
return `
|
|
|
|
${getCancellationReason(calEvent)}
|
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-18 21:05:49 +00:00
|
|
|
${getCustomInputs(calEvent)}
|
2022-10-19 16:11:50 +00:00
|
|
|
${getAppsStatus(calEvent)}
|
2022-06-06 17:49:56 +00:00
|
|
|
${
|
2022-06-21 09:14:10 +00:00
|
|
|
// TODO: Only the original attendee can make changes to the event
|
2022-06-06 17:49:56 +00:00
|
|
|
// Guests cannot
|
2022-06-21 09:14:10 +00:00
|
|
|
getManageLink(calEvent)
|
2022-06-06 17:49:56 +00:00
|
|
|
}
|
|
|
|
${
|
2022-06-21 09:14:10 +00:00
|
|
|
calEvent.paymentInfo
|
|
|
|
? `
|
2022-06-06 17:49:56 +00:00
|
|
|
${calEvent.organizer.language.translate("pay_now")}:
|
|
|
|
${calEvent.paymentInfo.link}
|
|
|
|
`
|
2022-06-21 09:14:10 +00:00
|
|
|
: ""
|
2022-06-06 17:49:56 +00:00
|
|
|
}
|
2021-12-07 15:32:07 +00:00
|
|
|
`.trim();
|
2022-06-06 17:49:56 +00:00
|
|
|
};
|
2021-12-07 15:32:07 +00:00
|
|
|
|
2022-06-06 17:49:56 +00:00
|
|
|
export const getCancellationReason = (calEvent: CalendarEvent) => {
|
|
|
|
if (!calEvent.cancellationReason) return "";
|
2021-12-06 19:34:31 +00:00
|
|
|
return `
|
2022-06-06 17:49:56 +00:00
|
|
|
${calEvent.organizer.language.translate("cancellation_reason")}:
|
|
|
|
${calEvent.cancellationReason}
|
|
|
|
`;
|
2021-12-06 19:34:31 +00:00
|
|
|
};
|
2022-08-11 00:53:05 +00:00
|
|
|
|
|
|
|
export const isDailyVideoCall = (calEvent: CalendarEvent): boolean => {
|
|
|
|
return calEvent?.videoCallData?.type === "daily_video";
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getPublicVideoCallUrl = (calEvent: CalendarEvent): string => {
|
|
|
|
return WEBAPP_URL + "/video/" + getUid(calEvent);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getVideoCallUrl = (calEvent: CalendarEvent): string => {
|
|
|
|
if (calEvent.videoCallData) {
|
|
|
|
if (isDailyVideoCall(calEvent)) {
|
|
|
|
return getPublicVideoCallUrl(calEvent);
|
|
|
|
}
|
|
|
|
return calEvent.videoCallData.url;
|
|
|
|
}
|
|
|
|
if (calEvent.additionalInformation?.hangoutLink) {
|
|
|
|
return calEvent.additionalInformation.hangoutLink;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getVideoCallPassword = (calEvent: CalendarEvent): string => {
|
|
|
|
return isDailyVideoCall(calEvent) ? "" : calEvent?.videoCallData?.password ?? "";
|
|
|
|
};
|