Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix#220 Trimmed the data before submitting #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/components/visual-editor/BlockDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -102,7 +103,7 @@ const BlockDialog: FC<BlockDialogProps> = ({
};
const onSubmitForm = async (params: IBlockAttributes) => {
if (block) {
updateBlock({ id: block.id, params });
updateBlock({ id: block.id, params: trimObjectValues(params) });
}
};

Expand Down
24 changes: 24 additions & 0 deletions frontend/src/utils/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}