Files
calendar/packages/app-store/routing-forms/lib/substituteVariables.ts
T
ef11755488 feat: add recurringEvent attribute to api/v2/event-types (#16251)
* feat: added recurringEvent attribute to api/v2/event-types

* changed `recurringEvent` to `recurrence`

* Update CHANGELOG.md

* remove /dist/ import

* change `as` to `satisfies`

* testing some changes

* Revert "testing some changes"

This reverts commit 464d2611ed19dbd6ae390332b4d6dd5884bcae3b.

* Update recurrence.input.ts

* fix: apiv2 tsconfig enums

* Update CHANGELOG.md

* removed dev imports

* Update package.json

* Update api-request.spec.ts

* Update api-request.spec.ts

* added recurrence to update-event-type.input

---------

Co-authored-by: Morgan Vernay <morgan@cal.com>
2024-08-26 11:42:35 +03:00

31 lines
918 B
TypeScript

import slugify from "@calcom/lib/slugify";
import type { FormResponse, Route, Field } from "../types/types";
import getFieldIdentifier from "./getFieldIdentifier";
export const substituteVariables = (
routeValue: Route["action"]["value"],
response: FormResponse,
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 field = fields.find((field) => field.id === key);
if (!field) {
continue;
}
const identifier = getFieldIdentifier(field);
if (identifier.toLowerCase() === variable.toLowerCase()) {
eventTypeUrl = eventTypeUrl.replace(`{${variable}}`, slugify(response[key].value.toString() || ""));
}
}
});
return eventTypeUrl;
};