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(VE-5055): add validations in textarea #347

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const CommentTextArea: React.FC<ICommentTextArea> = React.memo(
const target = event.target as HTMLTextAreaElement | null;
if (!target) return;
const newPlainTextValue = target.value;
const trimmedValue = newPlainTextValue.trim();

// TODO mentions will be handled in upcoming PRs this is a zombie code for now
// const to_users = [...state.to_users];
Expand All @@ -196,7 +197,7 @@ const CommentTextArea: React.FC<ICommentTextArea> = React.memo(
state.toUsers ?? []
);
setError({
hasError: errorMessage !== "",
hasError: errorMessage !== "" || trimmedValue === "",
message: errorMessage,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ const ThreadFooter = ({
>
Cancel
</Button>
{isDisabled}
pratyushbiswas marked this conversation as resolved.
Show resolved Hide resolved
{loading}
<Button
type="button"
buttonType="primary"
onClick={onSubmit}
testId={"thread-save-btn"}
disabled={isDisabled}
disabled={isDisabled || loading}
>
{editComment === "" ? "Post" : "Update"}
</Button>
Expand Down
15 changes: 15 additions & 0 deletions src/visualBuilder/utils/__test__/collabUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ describe("Utility Functions", () => {
expect(result.message).toBe("Hello {{1}}");
expect(result.toUsers).toEqual(["1"]);
});

it("should trim the message and replace multiple spaces with a single space", () => {
const state = {
message: " Hello @JohnDoe and @JaneDoe ",
toUsers: [
{ id: "1", display: "@JohnDoe" },
{ id: "2", display: "@JaneDoe" },
],
createdBy: "1",
author: "[email protected]",
};
const result = getCommentBody(state);
expect(result.message).toBe("Hello {{1}} and {{2}}");
expect(result.toUsers).toEqual(["1", "2"]);
});
});

describe("getThreadTitle", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/visualBuilder/utils/collabUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const sanitizeData = (dirty: any): string => {
* @returns {Object} The comment body containing the sanitized message and mentioned users.
*/
export const getCommentBody = (state: ICommentState): ICommentState => {
let finalMessage = state.message;
let finalMessage = state.message.trim().replace(/\s+/g, " ");
const comment = {
message: finalMessage,
toUsers: [],
Expand Down
Loading