* Add handlePaste function and integrate it with options fields * Prevents function running if user does not paste a list, allows list items to be pasted without deleting following items * Subs useState for rhf useWatch to fix issues with multiple form fields * Sets options array as optional property in zod schema * Assigns default value to options array to fix possibly undefined type errors * Sets placedholder property as optional * maps selectText to options on mount * Removes comma & semicolon delimiting for pasted lists (new line only) & defines regex as a constant * Sets default value of placeholder to empty string, provides default fallback for component text field if placeholder is omitted. * Fix type error on placeholder * Extracts handlePaste to service function & tests thoroughly * Some improvements and tests arent needed * More fixes * Fix reporting as well * TS fixes * Do transforms to and fro from label * Add unit tests * Unit test reporting * Test Improvements * Self review feedback addressed --------- Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com>
31 lines
917 B
TypeScript
31 lines
917 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;
|
|
};
|