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(ui): fix deletion issue for topmost quick reply #21

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ type QuickRepliesInput = {
minInput?: number;
};


const QuickRepliesInput: FC<QuickRepliesInput> = ({
value,
onChange,
minInput = 1,
minInput = 0,
Osho957 marked this conversation as resolved.
Show resolved Hide resolved
}) => {
const { t } = useTranslation();
const [quickReplies, setQuickReplies] = useState<
Expand All @@ -47,16 +48,11 @@ const QuickRepliesInput: FC<QuickRepliesInput> = ({
const updatedQuickReplies = [...quickReplies];

updatedQuickReplies.splice(index, 1);
// Set updated state only if it's greater than minInput
Osho957 marked this conversation as resolved.
Show resolved Hide resolved
setQuickReplies(
updatedQuickReplies.length
updatedQuickReplies.length > minInput
? updatedQuickReplies
: [
createValueWithId({
content_type: QuickReplyType.text,
title: "",
payload: "",
}),
],
: updatedQuickReplies.length ? updatedQuickReplies : []
);
};
const updateInput = (index: number) => (p: StdQuickReply) => {
Expand All @@ -65,9 +61,18 @@ const QuickRepliesInput: FC<QuickRepliesInput> = ({
};

useEffect(() => {
onChange(quickReplies.map(({ value }) => value));
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]);
}, [quickReplies,onChange]);

Osho957 marked this conversation as resolved.
Show resolved Hide resolved
return (
<Box>
Expand Down