2023-03-06 12:14:54 +00:00
|
|
|
import type { TFunction } from "next-i18next";
|
2021-11-08 11:04:12 +00:00
|
|
|
|
2022-08-26 00:48:50 +00:00
|
|
|
import { guessEventLocationType } from "@calcom/app-store/locations";
|
|
|
|
|
2023-02-01 12:10:16 +00:00
|
|
|
export type EventNameObjectType = {
|
2021-11-08 11:04:12 +00:00
|
|
|
attendeeName: string;
|
|
|
|
eventType: string;
|
|
|
|
eventName?: string | null;
|
|
|
|
host: string;
|
2022-06-06 12:48:13 +00:00
|
|
|
location?: string;
|
2021-11-08 11:04:12 +00:00
|
|
|
t: TFunction;
|
|
|
|
};
|
|
|
|
|
2023-02-03 10:20:10 +00:00
|
|
|
export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView = false) {
|
2022-06-06 12:48:13 +00:00
|
|
|
if (!eventNameObj.eventName)
|
|
|
|
return eventNameObj.t("event_between_users", {
|
|
|
|
eventName: eventNameObj.eventType,
|
|
|
|
host: eventNameObj.host,
|
|
|
|
attendeeName: eventNameObj.attendeeName,
|
|
|
|
});
|
|
|
|
|
|
|
|
let eventName = eventNameObj.eventName;
|
2022-08-26 00:48:50 +00:00
|
|
|
let locationString = eventNameObj.location || "";
|
2022-06-06 12:48:13 +00:00
|
|
|
|
2023-02-03 10:20:10 +00:00
|
|
|
if (eventNameObj.eventName.includes("{Location}") || eventNameObj.eventName.includes("{LOCATION}")) {
|
2022-08-26 00:48:50 +00:00
|
|
|
const eventLocationType = guessEventLocationType(eventNameObj.location);
|
|
|
|
if (eventLocationType) {
|
|
|
|
locationString = eventLocationType.label;
|
2022-06-06 12:48:13 +00:00
|
|
|
}
|
2023-02-01 12:10:16 +00:00
|
|
|
eventName = eventName.replace("{Location}", locationString);
|
2023-02-03 10:20:10 +00:00
|
|
|
eventName = eventName.replace("{LOCATION}", locationString);
|
2022-06-06 12:48:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
eventName
|
|
|
|
// Need this for compatibility with older event names
|
2023-02-01 12:10:16 +00:00
|
|
|
.replace("{Event type title}", eventNameObj.eventType)
|
|
|
|
.replace("{Scheduler}", eventNameObj.attendeeName)
|
|
|
|
.replace("{Organiser}", eventNameObj.host)
|
2023-02-03 10:20:10 +00:00
|
|
|
.replace("{USER}", eventNameObj.attendeeName)
|
|
|
|
.replace("{ATTENDEE}", eventNameObj.attendeeName)
|
|
|
|
.replace("{HOST}", eventNameObj.host)
|
|
|
|
.replace("{HOST/ATTENDEE}", forAttendeeView ? eventNameObj.host : eventNameObj.attendeeName)
|
2022-06-06 12:48:13 +00:00
|
|
|
);
|
2021-06-15 15:26:16 +00:00
|
|
|
}
|
2023-03-06 12:14:54 +00:00
|
|
|
|
|
|
|
export const validateCustomEventName = (value: string, message: string) => {
|
|
|
|
const validVariables = ["{Event type title}", "{Organiser}", "{Scheduler}", "{Location}"];
|
|
|
|
const matches = value.match(/\{([^}]+)\}/g);
|
|
|
|
if (matches?.length) {
|
|
|
|
for (const item of matches) {
|
|
|
|
if (!validVariables.includes(item)) {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|