* add UI for setting up custom event typ url * extract variables when processing route * remove console.log * fix some UI issues * code clean up * add translation * fix type error * Update packages/app-store/routing-forms/pages/route-builder/[...appPages].tsx Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> * make variable check case insensitive * add function * code clean up * code clean up --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
27 lines
837 B
TypeScript
27 lines
837 B
TypeScript
import slugify from "@calcom/lib/slugify";
|
|
|
|
import type { Response, Route, Field } from "../types/types";
|
|
import getFieldIdentifier from "./getFieldIdentifier";
|
|
|
|
export const substituteVariables = (
|
|
routeValue: Route["action"]["value"],
|
|
response: Response,
|
|
fields: Field[]
|
|
) => {
|
|
const regex = /\{([^\}]+)\}/g;
|
|
const variables: string[] = routeValue.match(regex)?.map((match: string) => match.slice(1, -1)) || [];
|
|
|
|
let eventTypeUrl = routeValue;
|
|
|
|
variables.forEach((variable) => {
|
|
for (const key in response) {
|
|
const identifier = getFieldIdentifier(fields.find((field) => field.id === key));
|
|
if (identifier.toLowerCase() === variable.toLowerCase()) {
|
|
eventTypeUrl = eventTypeUrl.replace(`{${variable}}`, slugify(response[key].value.toString() || ""));
|
|
}
|
|
}
|
|
});
|
|
|
|
return eventTypeUrl;
|
|
};
|