From ce70656e2fafd51ea8e282c6d5bcbb93094ec0a9 Mon Sep 17 00:00:00 2001 From: Osho957 Date: Mon, 16 Sep 2024 20:53:41 +0530 Subject: [PATCH 1/6] fix(ui): fix deletion issue for topmost quick reply --- .../form/inputs/message/QuickRepliesInput.tsx | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx index c8a7c175..a17fb9bc 100644 --- a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx @@ -24,6 +24,7 @@ type QuickRepliesInput = { minInput?: number; }; + const QuickRepliesInput: FC = ({ value, onChange, @@ -47,7 +48,17 @@ const QuickRepliesInput: FC = ({ const updatedQuickReplies = [...quickReplies]; updatedQuickReplies.splice(index, 1); - setQuickReplies(updatedQuickReplies.length ? updatedQuickReplies : []); + setQuickReplies( + updatedQuickReplies.length + ? updatedQuickReplies + : [ + createValueWithId({ + content_type: QuickReplyType.text, + title: "", + payload: "", + }), + ], + ); }; const updateInput = (index: number) => (p: StdQuickReply) => { quickReplies[index].value = p; @@ -55,7 +66,15 @@ const QuickRepliesInput: FC = ({ }; useEffect(() => { - onChange(quickReplies.map(({ value }) => value)); + if ( + quickReplies.length === 1 && + quickReplies[0]?.value?.title?.trim() === "" && + quickReplies[0]?.value?.payload?.trim() === "" + ) { + onChange([]); + } else { + onChange(quickReplies.map(({ value }) => value)); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [quickReplies]); From 438e908b6fce9013a5138337ab576daefd282a66 Mon Sep 17 00:00:00 2001 From: Osho957 Date: Tue, 17 Sep 2024 15:07:23 +0530 Subject: [PATCH 2/6] fix(ui): fix deletion issue for topmost quick reply --- .../form/inputs/message/QuickRepliesInput.tsx | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx index a17fb9bc..0691b87c 100644 --- a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx @@ -28,7 +28,7 @@ type QuickRepliesInput = { const QuickRepliesInput: FC = ({ value, onChange, - minInput = 1, + minInput = 0, }) => { const { t } = useTranslation(); const [quickReplies, setQuickReplies] = useState< @@ -48,16 +48,11 @@ const QuickRepliesInput: FC = ({ const updatedQuickReplies = [...quickReplies]; updatedQuickReplies.splice(index, 1); + // Set updated state only if it's greater than minInput setQuickReplies( - updatedQuickReplies.length + updatedQuickReplies.length > minInput ? updatedQuickReplies - : [ - createValueWithId({ - content_type: QuickReplyType.text, - title: "", - payload: "", - }), - ], + : updatedQuickReplies.length ? updatedQuickReplies : [] ); }; const updateInput = (index: number) => (p: StdQuickReply) => { @@ -67,16 +62,17 @@ const QuickRepliesInput: FC = ({ useEffect(() => { if ( - quickReplies.length === 1 && + quickReplies.length === 0 || + (quickReplies.length === 1 && quickReplies[0]?.value?.title?.trim() === "" && - quickReplies[0]?.value?.payload?.trim() === "" + quickReplies[0]?.value?.payload?.trim() === "") ) { onChange([]); } else { onChange(quickReplies.map(({ value }) => value)); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [quickReplies]); + }, [quickReplies,onChange]); return ( From 1ef4127aa266d4439ea40f78d148f1e889d563b6 Mon Sep 17 00:00:00 2001 From: Osho957 Date: Wed, 18 Sep 2024 08:14:00 +0530 Subject: [PATCH 3/6] fix(ui): fix deletion issue for topmost quick reply --- .../visual-editor/form/inputs/message/QuickRepliesInput.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx index 0691b87c..aa966a4e 100644 --- a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx @@ -28,7 +28,7 @@ type QuickRepliesInput = { const QuickRepliesInput: FC = ({ value, onChange, - minInput = 0, + minInput = 1, }) => { const { t } = useTranslation(); const [quickReplies, setQuickReplies] = useState< @@ -50,7 +50,7 @@ const QuickRepliesInput: FC = ({ updatedQuickReplies.splice(index, 1); // Set updated state only if it's greater than minInput setQuickReplies( - updatedQuickReplies.length > minInput + updatedQuickReplies.length >= minInput ? updatedQuickReplies : updatedQuickReplies.length ? updatedQuickReplies : [] ); From 55081803c7b043e682205d17b6f7eefa180c945a Mon Sep 17 00:00:00 2001 From: Osho957 Date: Wed, 18 Sep 2024 20:57:42 +0530 Subject: [PATCH 4/6] fix(ui): fix deletion issue for topmost quick reply #21 --- .../form/inputs/message/QuickRepliesInput.tsx | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx index aa966a4e..280276b9 100644 --- a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx @@ -50,9 +50,7 @@ const QuickRepliesInput: FC = ({ updatedQuickReplies.splice(index, 1); // Set updated state only if it's greater than minInput setQuickReplies( - updatedQuickReplies.length >= minInput - ? updatedQuickReplies - : updatedQuickReplies.length ? updatedQuickReplies : [] + updatedQuickReplies ); }; const updateInput = (index: number) => (p: StdQuickReply) => { @@ -61,18 +59,10 @@ const QuickRepliesInput: FC = ({ }; useEffect(() => { - if ( - quickReplies.length === 0 || - (quickReplies.length === 1 && - quickReplies[0]?.value?.title?.trim() === "" && - quickReplies[0]?.value?.payload?.trim() === "") - ) { - onChange([]); - } else { + onChange(quickReplies.map(({ value }) => value)); - } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [quickReplies,onChange]); + }, [quickReplies]); return ( From fe8e4e7b944273811bd9cca5185730c4cba087d2 Mon Sep 17 00:00:00 2001 From: Osho957 Date: Sun, 22 Sep 2024 21:34:25 +0530 Subject: [PATCH 5/6] fix(ui): fix deletion issue for topmost quick reply #21 --- .../visual-editor/form/inputs/message/QuickRepliesInput.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx index 280276b9..bcf32efe 100644 --- a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx @@ -48,7 +48,6 @@ const QuickRepliesInput: FC = ({ const updatedQuickReplies = [...quickReplies]; updatedQuickReplies.splice(index, 1); - // Set updated state only if it's greater than minInput setQuickReplies( updatedQuickReplies ); From a0fa0b544300d2bf7e881ccf5154e0052ad8cc87 Mon Sep 17 00:00:00 2001 From: Osho957 Date: Sun, 22 Sep 2024 21:35:13 +0530 Subject: [PATCH 6/6] fix(ui): fix deletion issue for topmost quick reply #21 --- .../visual-editor/form/inputs/message/QuickRepliesInput.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx index bcf32efe..62e610f2 100644 --- a/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/message/QuickRepliesInput.tsx @@ -58,7 +58,6 @@ const QuickRepliesInput: FC = ({ }; useEffect(() => { - onChange(quickReplies.map(({ value }) => value)); // eslint-disable-next-line react-hooks/exhaustive-deps }, [quickReplies]);