Files
calendar/packages/app-store/routing-forms/lib/substituteVariables.ts
T
654a204878 feat: Attribute based routing from Team Routing Form to Team Event(with assigned users matching the attribute logic) (#16823)
* Initial commit

* routingForm to Booking a particular team member working

* Happy path working

* Fixes

* Fix router query params forwarding

* Add basicConfig within app

* Tests

* More tests

* Update packages/app-store/routing-forms/components/SingleForm.tsx

Co-authored-by: Omar López <zomars@me.com>

---------

Co-authored-by: Omar López <zomars@me.com>
Co-authored-by: Benny Joo <sldisek783@gmail.com>
2024-10-08 21:12:32 +05:30

31 lines
936 B
TypeScript

import slugify from "@calcom/lib/slugify";
import type { FormResponse, NonRouterRoute, Field } from "../types/types";
import getFieldIdentifier from "./getFieldIdentifier";
export const substituteVariables = (
routeValue: NonRouterRoute["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;
};