+10









GitStart
GitHub
gitstart
gitstart
Nitesh Singh
Rafael Toledo
Matheus Benini Ferreira
MuriloAmarals
Murilo Amaral
Rubens Rafael
Thiago Nascimbeni
Rafael
Grace Nshokano
Matheus Muniz
Júlio Piubello da Silva Cabral
Matheus Muniz
C000Ldude
Klinger Matheus
Eman
kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
eae60043bb
Co-authored-by: gitstart <gitstart@users.noreply.github.com> Co-authored-by: gitstart <gitstart@gitstart.com> Co-authored-by: Nitesh Singh <nitesh.singh@gitstart.dev> Co-authored-by: Rafael Toledo <87545086+Toledodev@users.noreply.github.com> Co-authored-by: Matheus Benini Ferreira <88898100+MatheusBeniniF@users.noreply.github.com> Co-authored-by: MuriloAmarals <muralha2000@gmail.com> Co-authored-by: Murilo Amaral <87545137+MuriloAmarals@users.noreply.github.com> Co-authored-by: Rubens Rafael <70234898+RubensRafael@users.noreply.github.com> Co-authored-by: Thiago Nascimbeni <tnascimbeni@gmail.com> Co-authored-by: Rafael <rafael.toledo@engenharia.ufjf.br> Co-authored-by: Grace Nshokano <grace.devolop@gmail.com> Co-authored-by: Matheus Muniz <matheusmuniz100@hotmail.com> Co-authored-by: Júlio Piubello da Silva Cabral <julio.piubello@gitstart.dev> Co-authored-by: Matheus Muniz <87545749+matheusmuniz03@users.noreply.github.com> Co-authored-by: C000Ldude <coolmagnas@gmail.com> Co-authored-by: Klinger Matheus <50892465+KlingerMatheus@users.noreply.github.com> Co-authored-by: Eman <emmanuelgatwech@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
202 lines
5.4 KiB
TypeScript
202 lines
5.4 KiB
TypeScript
import short from "short-uuid";
|
|
import { v5 as uuidv5 } from "uuid";
|
|
|
|
import type { CalendarEvent } from "@calcom/types/Calendar";
|
|
|
|
import { WEBAPP_URL } from "./constants";
|
|
|
|
const translator = short();
|
|
|
|
// The odd indentation in this file is necessary because otherwise the leading tabs will be applied into the event description.
|
|
|
|
export const getWhat = (calEvent: CalendarEvent) => {
|
|
return `
|
|
${calEvent.organizer.language.translate("what")}:
|
|
${calEvent.type}
|
|
`;
|
|
};
|
|
|
|
export const getWhen = (calEvent: CalendarEvent) => {
|
|
return `
|
|
${calEvent.organizer.language.translate("invitee_timezone")}:
|
|
${calEvent.attendees[0].timeZone}
|
|
`;
|
|
};
|
|
|
|
export const getWho = (calEvent: CalendarEvent) => {
|
|
const attendees = calEvent.attendees
|
|
.map((attendee) => {
|
|
return `
|
|
${attendee?.name || calEvent.organizer.language.translate("guest")}
|
|
${attendee.email}
|
|
`;
|
|
})
|
|
.join("");
|
|
|
|
const organizer = `
|
|
${calEvent.organizer.name} - ${calEvent.organizer.language.translate("organizer")}
|
|
${calEvent.organizer.email}
|
|
`;
|
|
|
|
return `
|
|
${calEvent.organizer.language.translate("who")}:
|
|
${organizer + attendees}
|
|
`;
|
|
};
|
|
|
|
export const getAdditionalNotes = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.additionalNotes) {
|
|
return "";
|
|
}
|
|
return `
|
|
${calEvent.organizer.language.translate("additional_notes")}:
|
|
${calEvent.additionalNotes}
|
|
`;
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
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})` : ""}`
|
|
}`
|
|
)}
|
|
`;
|
|
};
|
|
|
|
export const getDescription = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.description) {
|
|
return "";
|
|
}
|
|
return `\n${calEvent.attendees[0].language.translate("description")}
|
|
${calEvent.description}
|
|
`;
|
|
};
|
|
export const getLocation = (calEvent: CalendarEvent) => {
|
|
const meetingUrl = getVideoCallUrl(calEvent);
|
|
if (meetingUrl) {
|
|
return meetingUrl;
|
|
}
|
|
const providerName = getProviderName(calEvent);
|
|
return providerName || calEvent.location || "";
|
|
};
|
|
|
|
export const getProviderName = (calEvent: CalendarEvent): string => {
|
|
// TODO: use getAppName from @calcom/app-store
|
|
if (calEvent.location && calEvent.location.includes("integrations:")) {
|
|
let location = calEvent.location.split(":")[1];
|
|
if (location === "daily") {
|
|
location = "Cal Video";
|
|
}
|
|
return location[0].toUpperCase() + location.slice(1);
|
|
}
|
|
// 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;
|
|
}
|
|
return "";
|
|
};
|
|
|
|
export const getManageLink = (calEvent: CalendarEvent) => {
|
|
return `
|
|
${calEvent.organizer.language.translate("need_to_reschedule_or_cancel")}
|
|
${getCancelLink(calEvent)}
|
|
`;
|
|
};
|
|
|
|
export const getUid = (calEvent: CalendarEvent): string => {
|
|
return calEvent.uid ?? translator.fromUUID(uuidv5(JSON.stringify(calEvent), uuidv5.URL));
|
|
};
|
|
|
|
export const getCancelLink = (calEvent: CalendarEvent): string => {
|
|
return WEBAPP_URL + "/cancel/" + getUid(calEvent);
|
|
};
|
|
|
|
export const getRescheduleLink = (calEvent: CalendarEvent): string => {
|
|
return WEBAPP_URL + "/reschedule/" + getUid(calEvent);
|
|
};
|
|
|
|
export const getRichDescription = (calEvent: CalendarEvent /*, attendee?: Person*/) => {
|
|
return `
|
|
${getCancellationReason(calEvent)}
|
|
${getWhat(calEvent)}
|
|
${getWhen(calEvent)}
|
|
${getWho(calEvent)}
|
|
${calEvent.organizer.language.translate("where")}:
|
|
${getLocation(calEvent)}
|
|
${getDescription(calEvent)}
|
|
${getAdditionalNotes(calEvent)}
|
|
${getCustomInputs(calEvent)}
|
|
${getAppsStatus(calEvent)}
|
|
${
|
|
// TODO: Only the original attendee can make changes to the event
|
|
// Guests cannot
|
|
getManageLink(calEvent)
|
|
}
|
|
${
|
|
calEvent.paymentInfo
|
|
? `
|
|
${calEvent.organizer.language.translate("pay_now")}:
|
|
${calEvent.paymentInfo.link}
|
|
`
|
|
: ""
|
|
}
|
|
`.trim();
|
|
};
|
|
|
|
export const getCancellationReason = (calEvent: CalendarEvent) => {
|
|
if (!calEvent.cancellationReason) return "";
|
|
return `
|
|
${calEvent.organizer.language.translate("cancellation_reason")}:
|
|
${calEvent.cancellationReason}
|
|
`;
|
|
};
|
|
|
|
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 ?? "";
|
|
};
|