From 10d9886dccce598a7348e87f01aab11f52d0c953 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Thu, 16 Feb 2023 10:49:32 +0530 Subject: [PATCH] Update packages/features/form-builder/FormBuilder.tsx MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Omar López --- .../features/form-builder/FormBuilder.tsx | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/packages/features/form-builder/FormBuilder.tsx b/packages/features/form-builder/FormBuilder.tsx index 83f1b3ad41..3971948b3d 100644 --- a/packages/features/form-builder/FormBuilder.tsx +++ b/packages/features/form-builder/FormBuilder.tsx @@ -542,25 +542,16 @@ export const ComponentForField = ({ const componentConfig = Components[fieldType]; const isValueOfPropsType = (val: unknown, propsType: typeof componentConfig.propsType) => { - if (propsType === "text") { - return typeof val === "string"; - } - if (propsType === "boolean") { - return typeof val === "boolean"; - } - if (propsType === "textList") { - return val instanceof Array && val.every((v) => typeof v === "string"); - } - if (propsType === "select") { - return typeof val === "string"; - } - if (propsType === "multiselect") { - return val instanceof Array && val.every((v) => typeof v === "string"); - } - if (propsType === "objectiveWithInput") { - return typeof value === "object" && value !== null ? "value" in value : false; - } - throw new Error(`Unknown propsType ${propsType}`); + const propsTypeConditionMap = { + boolean: typeof val === "boolean", + multiselect: val instanceof Array && val.every((v) => typeof v === "string"), + objectiveWithInput: typeof val === "object" && val !== null ? "value" in val : false, + select: typeof val === "string", + text: typeof val === "string", + textList: val instanceof Array && val.every((v) => typeof v === "string"), + } as const; + if (!propsTypeConditionMap[propsType]) throw new Error(`Unknown propsType ${propsType}`); + return propsTypeConditionMap[propsType]; }; // If possible would have wanted `isValueOfPropsType` to narrow the type of `value` and `setValue` accordingly, but can't seem to do it.