Additional fields as variables for custom event name (#7454)
* feat: add custom validate name util * refactor: separate custom event type modal into a different component * feat: add validation to zod * chore: add i18n key * feat: add dynamic imports * fix: padding * Omit cache-hit exit 1, assuming it'll fail regardless * allow custom inputs as variables in event name * fix ui for adding custom inputs * show edited event name in modal * code clean up * merge fixes * includes new booking fields logic * fix event name with custom booking fields * code clean up * Update apps/web/public/static/locales/en/common.json Co-authored-by: Alex van Andel <[email protected]> * fix type error * remove old reqbody variable --------- Co-authored-by: nafees nazik <[email protected]> Co-authored-by: Alex van Andel <[email protected]> Co-authored-by: CarinaWolli <[email protected]>
This commit is contained in:
7 files changed
+82
-21
No files matched your search
+50
-13
@@ -1,6 +1,7 @@
|
||||
import type { TFunction } from "next-i18next";
|
||||
|
||||
import { guessEventLocationType } from "@calcom/app-store/locations";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
|
||||
export type EventNameObjectType = {
|
||||
attendeeName: string;
|
||||
@@ -8,6 +9,7 @@ export type EventNameObjectType = {
|
||||
eventName?: string | null;
|
||||
host: string;
|
||||
location?: string;
|
||||
bookingFields?: Prisma.JsonObject;
|
||||
t: TFunction;
|
||||
};
|
||||
|
||||
@@ -31,21 +33,56 @@ export function getEventName(eventNameObj: EventNameObjectType, forAttendeeView
|
||||
eventName = eventName.replace("{LOCATION}", locationString);
|
||||
}
|
||||
|
||||
return (
|
||||
eventName
|
||||
// Need this for compatibility with older event names
|
||||
.replace("{Event type title}", eventNameObj.eventType)
|
||||
.replace("{Scheduler}", eventNameObj.attendeeName)
|
||||
.replace("{Organiser}", eventNameObj.host)
|
||||
.replace("{USER}", eventNameObj.attendeeName)
|
||||
.replace("{ATTENDEE}", eventNameObj.attendeeName)
|
||||
.replace("{HOST}", eventNameObj.host)
|
||||
.replace("{HOST/ATTENDEE}", forAttendeeView ? eventNameObj.host : eventNameObj.attendeeName)
|
||||
);
|
||||
let dynamicEventName = eventName
|
||||
// Need this for compatibility with older event names
|
||||
.replaceAll("{Event type title}", eventNameObj.eventType)
|
||||
.replaceAll("{Scheduler}", eventNameObj.attendeeName)
|
||||
.replaceAll("{Organiser}", eventNameObj.host)
|
||||
.replaceAll("{USER}", eventNameObj.attendeeName)
|
||||
.replaceAll("{ATTENDEE}", eventNameObj.attendeeName)
|
||||
.replaceAll("{HOST}", eventNameObj.host)
|
||||
.replaceAll("{HOST/ATTENDEE}", forAttendeeView ? eventNameObj.host : eventNameObj.attendeeName);
|
||||
|
||||
const customInputvariables = dynamicEventName.match(/\{(.+?)}/g)?.map((variable) => {
|
||||
return variable.replace("{", "").replace("}", "");
|
||||
});
|
||||
|
||||
customInputvariables?.forEach((variable) => {
|
||||
if (eventNameObj.bookingFields) {
|
||||
Object.keys(eventNameObj.bookingFields).forEach((bookingField) => {
|
||||
if (variable === bookingField) {
|
||||
let fieldValue;
|
||||
if (eventNameObj.bookingFields) {
|
||||
fieldValue =
|
||||
eventNameObj.bookingFields[bookingField as keyof typeof eventNameObj.bookingFields]?.toString();
|
||||
}
|
||||
dynamicEventName = dynamicEventName.replace(`{${variable}}`, fieldValue || "");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return dynamicEventName;
|
||||
}
|
||||
|
||||
export const validateCustomEventName = (value: string, message: string) => {
|
||||
const validVariables = ["{Event type title}", "{Organiser}", "{Scheduler}", "{Location}"];
|
||||
export const validateCustomEventName = (
|
||||
value: string,
|
||||
message: string,
|
||||
bookingFields?: Prisma.JsonObject
|
||||
) => {
|
||||
let customInputVariables: string[] = [];
|
||||
if (bookingFields) {
|
||||
customInputVariables = Object.keys(bookingFields).map((customInput) => {
|
||||
return `{${customInput}}`;
|
||||
});
|
||||
}
|
||||
|
||||
const validVariables = customInputVariables.concat([
|
||||
"{Event type title}",
|
||||
"{Organiser}",
|
||||
"{Scheduler}",
|
||||
"{Location}",
|
||||
]);
|
||||
const matches = value.match(/\{([^}]+)\}/g);
|
||||
if (matches?.length) {
|
||||
for (const item of matches) {
|
||||
|
||||
Reference in new issue
Block a user