From 8ac62d796f71b624f050731efb3f94b40bcb9cc0 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Wed, 27 Nov 2024 14:48:28 +0100 Subject: [PATCH] fix: code syntax --- .../form/inputs/triggers/PatternInput.tsx | 4 ++-- .../{PostbackInputV2.tsx => PostbackInput.tsx} | 17 +++++------------ 2 files changed, 7 insertions(+), 14 deletions(-) rename frontend/src/components/visual-editor/form/inputs/triggers/{PostbackInputV2.tsx => PostbackInput.tsx} (95%) diff --git a/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx b/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx index 3e7f3ed..1f63454 100644 --- a/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx @@ -23,7 +23,7 @@ import { PayloadPattern, } from "@/types/block.types"; -import { PostbackInputV2 } from "./PostbackInputV2"; +import { PostbackInput } from "./PostbackInput"; const isRegex = (str: Pattern) => { return typeof str === "string" && str.startsWith("/") && str.endsWith("/"); @@ -150,7 +150,7 @@ const PatternInput: FC = ({ /> )} {["payload", "content", "menu"].includes(patternType) ? ( - { payload && setPattern(payload); }} diff --git a/frontend/src/components/visual-editor/form/inputs/triggers/PostbackInputV2.tsx b/frontend/src/components/visual-editor/form/inputs/triggers/PostbackInput.tsx similarity index 95% rename from frontend/src/components/visual-editor/form/inputs/triggers/PostbackInputV2.tsx rename to frontend/src/components/visual-editor/form/inputs/triggers/PostbackInput.tsx index 68dccd1..a326dd1 100644 --- a/frontend/src/components/visual-editor/form/inputs/triggers/PostbackInputV2.tsx +++ b/frontend/src/components/visual-editor/form/inputs/triggers/PostbackInput.tsx @@ -30,18 +30,12 @@ type PayloadOption = { group?: string; }; -type ContentPayloadOption = { - id: string; - label: string; - group?: string; -}; - type PostbackInputProps = { value?: string | null; onChange: (pattern: PayloadPattern) => void; }; -export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => { +export const PostbackInput = ({ value, onChange }: PostbackInputProps) => { const block = useBlock(); const getBlockFromCache = useGetFromCache(EntityType.BLOCK); const { data: menu } = useFind( @@ -176,7 +170,7 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => { return acc; }, payloads); - }, [] as ContentPayloadOption[]); + }, [] as PayloadOption[]); }) .flat(), [block?.previousBlocks, contents, getBlockFromCache], @@ -189,9 +183,9 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => { ...menuOptions, ...contentOptions, ]; - const existOption = options.find((e) => e.id === value); + const isOptionsReady = options.find((e) => e.id === value); - if (!existOption) { + if (!isOptionsReady) { return ( ); @@ -206,7 +200,7 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => { label={t("label.postback")} multiple={false} onChange={(_e, content) => { - if (content) { + content && onChange({ label: content.label, value: content.id, @@ -214,7 +208,6 @@ export const PostbackInputV2 = ({ value, onChange }: PostbackInputProps) => { ? content.group : undefined, } as PayloadPattern); - } }} groupBy={(option) => { return option.group ?? t("label.other");