2021-11-08 11:04:12 +00:00
|
|
|
import { TFunction } from "next-i18next";
|
|
|
|
|
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-01 12:10:16 +00:00
|
|
|
export function getEventName(eventNameObj: EventNameObjectType) {
|
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-01 12:10:16 +00:00
|
|
|
if (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);
|
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)
|
2022-06-06 12:48:13 +00:00
|
|
|
);
|
2021-06-15 15:26:16 +00:00
|
|
|
}
|