From 5c089f0223b1b9697ecb53ea6918a97ae99a18c8 Mon Sep 17 00:00:00 2001 From: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:11:35 +0530 Subject: [PATCH] [WEB-496] fix: issue comment (#3796) * fix: issue comment empty string and on enter functionality * fix: empty html tag validation added * fix: purifying dom contents before saving comments --------- Co-authored-by: sriram veeraghanta --- .../comments/comment-create.tsx | 30 +++++++++++-------- web/helpers/string.helper.ts | 16 +++++++--- web/package.json | 2 ++ yarn.lock | 16 ++++++++-- 4 files changed, 45 insertions(+), 19 deletions(-) diff --git a/web/components/issues/issue-detail/issue-activity/comments/comment-create.tsx b/web/components/issues/issue-detail/issue-activity/comments/comment-create.tsx index f7bce3edc..f666b6c1d 100644 --- a/web/components/issues/issue-detail/issue-activity/comments/comment-create.tsx +++ b/web/components/issues/issue-detail/issue-activity/comments/comment-create.tsx @@ -11,6 +11,8 @@ import { TIssueComment } from "@plane/types"; // icons import { Globe2, Lock } from "lucide-react"; import { useMention, useWorkspace } from "hooks/store"; +// helpers +import { isEmptyHtmlString } from "helpers/string.helper"; const fileService = new FileService(); @@ -51,10 +53,10 @@ export const IssueCommentCreate: FC = (props) => { const { handleSubmit, control, + watch, formState: { isSubmitting }, reset, - watch, - } = useForm>({ defaultValues: { comment_html: "" } }); + } = useForm>({ defaultValues: { comment_html: "

" } }); const onSubmit = async (formData: Partial) => { await activityOperations.createComment(formData).finally(() => { @@ -63,14 +65,19 @@ export const IssueCommentCreate: FC = (props) => { }); }; + const isEmpty = + watch("comment_html") === "" || + watch("comment_html")?.trim() === "" || + watch("comment_html") === "

" || + isEmptyHtmlString(watch("comment_html") ?? ""); + return (
{ - // if (e.key === "Enter" && !e.shiftKey) { - // e.preventDefault(); - // // handleSubmit(onSubmit)(e); - // } - // }} + onKeyDown={(e) => { + if (e.key === "Enter" && !e.shiftKey && !isEmpty) { + handleSubmit(onSubmit)(e); + } + }} > = (props) => { control={control} render={({ field: { value, onChange } }) => ( { - handleSubmit(onSubmit)(e); - }} cancelUploadImage={fileService.cancelUpload} uploadFile={fileService.getUploadFileFunction(workspaceSlug as string)} deleteFile={fileService.getDeleteImageFunction(workspaceId)} restoreFile={fileService.getRestoreImageFunction(workspaceId)} ref={editorRef} - value={value ?? ""} + value={!value ? "

" : value} customClassName="p-2" editorContentCustomClassNames="min-h-[35px]" debouncedUpdatesEnabled={false} @@ -105,7 +109,7 @@ export const IssueCommentCreate: FC = (props) => { } submitButton={