[WEB-2348] fix: allow updating comments with just mentions in them (#5471)

* fix: accept mentions while updating comments

* chore: remove console log

* chore: update empty string helper function
This commit is contained in:
Aaryan Khandelwal 2024-09-02 14:00:41 +05:30 committed by GitHub
parent 03c28a11e8
commit bac5b53ffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 46 additions and 27 deletions

View file

@ -230,9 +230,23 @@ export const checkEmailValidity = (email: string): boolean => {
return isEmailValid;
};
export const isEmptyHtmlString = (htmlString: string) => {
export const isEmptyHtmlString = (htmlString: string, allowedHTMLTags: string[] = []) => {
// Remove HTML tags using regex
const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: ["img"] });
const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: allowedHTMLTags });
// Trim the string and check if it's empty
return cleanText.trim() === "";
};
/**
* @description this function returns whether a comment is empty or not by checking for the following conditions-
* 1. If comment is undefined
* 2. If comment is an empty string
* 3. If comment is "<p></p>"
* @param {string | undefined} comment
* @returns {boolean}
*/
export const isCommentEmpty = (comment: string | undefined): boolean => {
// return true if comment is undefined
if (!comment) return true;
return comment?.trim() === "" || comment === "<p></p>" || isEmptyHtmlString(comment ?? "", ["mention-component"]);
};