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";
|
2023-03-07 17:50:54 +00:00
|
|
|
import getLabelValueMapFromResponses from "./getLabelValueMapFromResponses";
|
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) => {
|
2023-01-31 21:14:19 +00:00
|
|
|
return calEvent.seatsPerTimeSlot
|
|
|
|
? `
|
|
|
|
${calEvent.organizer.language.translate("organizer_timezone")}:
|
|
|
|
${calEvent.organizer.timeZone}
|
|
|
|
`
|
|
|
|
: `
|
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) => {
|
2023-03-14 04:19:05 +00:00
|
|
|
let attendeesFromCalEvent = [...calEvent.attendees];
|
2023-01-31 21:14:19 +00:00
|
|
|
if (calEvent.seatsPerTimeSlot && !calEvent.seatsShowAttendees) {
|
2023-03-14 04:19:05 +00:00
|
|
|
attendeesFromCalEvent = [];
|
2023-01-31 21:14:19 +00:00
|
|
|
}
|
2023-03-14 04:19:05 +00:00
|
|
|
const attendees = attendeesFromCalEvent
|
2021-12-06 19:34:31 +00:00
|
|
|
.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}
|
|
|
|
`;
|
|
|
|
|
2023-02-27 20:45:40 +00:00
|
|
|
const teamMembers = calEvent.team?.members
|
|
|
|
? calEvent.team.members.map((member) => {
|
|
|
|
return `
|
|
|
|
${member.name} - ${calEvent.organizer.language.translate("team_member")}
|
|
|
|
${member.email}
|
|
|
|
`;
|
|
|
|
})
|
|
|
|
: [];
|
|
|
|
|
2021-12-06 19:34:31 +00:00
|
|
|
return `
|
2022-01-27 20:32:53 +00:00
|
|
|
${calEvent.organizer.language.translate("who")}:
|
2023-02-27 20:45:40 +00:00
|
|
|
${organizer + attendees + teamMembers.join("")}
|
2021-12-06 19:34:31 +00:00
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
2023-03-02 18:15:28 +00:00
|
|
|
export const getUserFieldsResponses = (calEvent: CalendarEvent) => {
|
2023-03-07 17:50:54 +00:00
|
|
|
const labelValueMap = getLabelValueMapFromResponses(calEvent);
|
|
|
|
|
|
|
|
if (!labelValueMap) {
|
2022-05-18 21:05:49 +00:00
|
|
|
return "";
|
|
|
|
}
|
2023-03-07 17:50:54 +00:00
|
|
|
const responsesString = Object.keys(labelValueMap)
|
2022-05-18 21:05:49 +00:00
|
|
|
.map((key) => {
|
2023-03-07 17:50:54 +00:00
|
|
|
if (!labelValueMap) return "";
|
|
|
|
if (labelValueMap[key] !== "") {
|
2022-05-18 21:05:49 +00:00
|
|
|
return `
|
|
|
|
${key}:
|
2023-03-07 17:50:54 +00:00
|
|
|
${labelValueMap[key]}
|
2022-05-18 21:05:49 +00:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.join("");
|
|
|
|
|
2023-03-02 18:15:28 +00:00
|
|
|
return responsesString;
|
2022-05-18 21:05:49 +00:00
|
|
|
};
|
|
|
|
|
2022-10-19 16:11:50 +00:00
|
|
|
export const getAppsStatus = (calEvent: CalendarEvent) => {
|
|
|
|
if (!calEvent.appsStatus) {
|
|
|
|
return "";
|
|
|
|
}
|
2022-12-18 12:36:30 +00:00
|
|
|
return `\n${calEvent.organizer.language.translate("apps_status")}
|
2022-11-22 20:44:08 +00:00
|
|
|
${calEvent.appsStatus.map((app) => {
|
|
|
|
return `\n- ${app.appName} ${
|
|
|
|
app.success >= 1 ? `✅ ${app.success > 1 ? `(x${app.success})` : ""}` : ""
|
|
|
|
}${
|
|
|
|
app.warnings && app.warnings.length >= 1 ? app.warnings.map((warning) => `\n - ${warning}`) : ""
|
|
|
|
} ${app.failures && app.failures >= 1 ? `❌ ${app.failures > 1 ? `(x${app.failures})` : ""}` : ""} ${
|
|
|
|
app.errors && app.errors.length >= 1 ? app.errors.map((error) => `\n - ${error}`) : ""
|
|
|
|
}`;
|
|
|
|
})}
|
2022-10-19 16:11:50 +00:00
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
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-12-18 12:36:30 +00:00
|
|
|
return `\n${calEvent.organizer.language.translate("description")}
|
2022-04-07 18:22:11 +00:00
|
|
|
${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
|
|
|
};
|
|
|
|
|
2022-11-29 20:27:29 +00:00
|
|
|
export const getUid = (calEvent: CalendarEvent): string => {
|
2023-03-14 04:19:05 +00:00
|
|
|
const uid = calEvent.uid;
|
|
|
|
return uid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
|
|
|
};
|
|
|
|
|
|
|
|
const getSeatReferenceId = (calEvent: CalendarEvent): string => {
|
|
|
|
return calEvent.attendeeSeatId ? `seatReferenceUid=${calEvent.attendeeSeatId}` : "";
|
2022-11-29 20:27:29 +00:00
|
|
|
};
|
|
|
|
|
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")}
|
2022-11-29 20:27:29 +00:00
|
|
|
${WEBAPP_URL + "/booking/" + getUid(calEvent) + "?changes=true"}
|
2021-12-06 19:34:31 +00:00
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getCancelLink = (calEvent: CalendarEvent): string => {
|
2022-11-16 19:48:17 +00:00
|
|
|
return (
|
2023-03-14 04:19:05 +00:00
|
|
|
WEBAPP_URL +
|
|
|
|
`/booking/${getUid(
|
|
|
|
calEvent
|
|
|
|
)}?cancel=true&allRemainingBookings=${!!calEvent.recurringEvent}&${getSeatReferenceId}`
|
2022-11-16 19:48:17 +00:00
|
|
|
);
|
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 => {
|
2023-03-14 04:19:05 +00:00
|
|
|
const Uid = getUid(calEvent);
|
|
|
|
const seatUid = getSeatReferenceId(calEvent);
|
|
|
|
|
|
|
|
return `${WEBAPP_URL}/reschedule/${seatUid ? seatUid : Uid}`;
|
2022-10-27 09:13:52 +00:00
|
|
|
};
|
|
|
|
|
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)}
|
2023-03-02 18:15:28 +00:00
|
|
|
${getUserFieldsResponses(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
|
2023-03-14 04:19:05 +00:00
|
|
|
!calEvent.seatsPerTimeSlot && 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 ?? "";
|
|
|
|
};
|