diff --git a/frontend/src/components/visual-editor/BlockDialog.tsx b/frontend/src/components/visual-editor/BlockDialog.tsx index 5088621e..247e7fc8 100644 --- a/frontend/src/components/visual-editor/BlockDialog.tsx +++ b/frontend/src/components/visual-editor/BlockDialog.tsx @@ -34,6 +34,7 @@ import { useToast } from "@/hooks/useToast"; import { useTranslate } from "@/hooks/useTranslate"; import { EntityType } from "@/services/types"; import { OutgoingMessageFormat } from "@/types/message.types"; +import { trimObjectValues } from "@/utils/object"; import { IBlockAttributes, IBlock } from "../../types/block.types"; @@ -102,7 +103,7 @@ const BlockDialog: FC = ({ }; const onSubmitForm = async (params: IBlockAttributes) => { if (block) { - updateBlock({ id: block.id, params }); + updateBlock({ id: block.id, params: trimObjectValues(params) }); } }; diff --git a/frontend/src/utils/object.ts b/frontend/src/utils/object.ts index 8c9e4c5e..a56fcc48 100644 --- a/frontend/src/utils/object.ts +++ b/frontend/src/utils/object.ts @@ -39,3 +39,27 @@ export function merge< return output as T & U; } + +export function trimObjectValues(obj) { + if (typeof obj === "object" && obj !== null) { + if (Array.isArray(obj)) { + return obj.map(trimObjectValues); + } + + const trimmedObject = {}; + + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + trimmedObject[key] = trimObjectValues(obj[key]); + } + } + + return trimmedObject; + } + + if (typeof obj === "string") { + return obj.trim(); + } + + return obj; +}