From 7912d70388ee65cc4f1fbc73446f189849aaff80 Mon Sep 17 00:00:00 2001 From: ayeshoali Date: Wed, 30 Nov 2022 19:03:30 +0500 Subject: [PATCH] refactor: handled confirm action to functions --- src/discussions/comments/comment/Comment.jsx | 20 +++++++++++------- src/discussions/comments/comment/Reply.jsx | 20 +++++++++++------- src/discussions/posts/post/Post.jsx | 22 ++++++++++++-------- src/index.scss | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/discussions/comments/comment/Comment.jsx b/src/discussions/comments/comment/Comment.jsx index 9be8e7f8..d0d3f840 100644 --- a/src/discussions/comments/comment/Comment.jsx +++ b/src/discussions/comments/comment/Comment.jsx @@ -56,6 +56,16 @@ function Comment({ } }; + const handleDeleteConfirmation = () => { + dispatch(removeComment(comment.id)); + hideDeleteConfirmation(); + }; + + const handleReportConfirmation = () => { + dispatch(editComment(comment.id, { flagged: !comment.abuseFlagged })); + hideReportConfirmation(); + }; + const actionHandlers = { [ContentActions.EDIT_CONTENT]: () => setEditing(true), [ContentActions.ENDORSE]: async () => { @@ -78,10 +88,7 @@ function Comment({ title={intl.formatMessage(messages.deleteResponseTitle)} description={intl.formatMessage(messages.deleteResponseDescription)} onClose={hideDeleteConfirmation} - comfirmAction={() => { - dispatch(removeComment(comment.id)); - hideDeleteConfirmation(); - }} + comfirmAction={handleDeleteConfirmation} closeButtonVaraint="tertiary" confirmButtonText={intl.formatMessage(messages.deleteConfirmationDelete)} /> @@ -91,10 +98,7 @@ function Comment({ title={intl.formatMessage(messages.reportResponseTitle)} description={intl.formatMessage(messages.reportResponseDescription)} onClose={hideReportConfirmation} - comfirmAction={() => { - dispatch(editComment(comment.id, { flagged: !comment.abuseFlagged })); - hideReportConfirmation(); - }} + comfirmAction={handleReportConfirmation} confirmButtonVariant="danger" /> )} diff --git a/src/discussions/comments/comment/Reply.jsx b/src/discussions/comments/comment/Reply.jsx index a59144d5..bece7975 100644 --- a/src/discussions/comments/comment/Reply.jsx +++ b/src/discussions/comments/comment/Reply.jsx @@ -39,6 +39,16 @@ function Reply({ } }; + const handleDeleteConfirmation = () => { + dispatch(removeComment(reply.id)); + hideDeleteConfirmation(); + }; + + const handleReportConfirmation = () => { + dispatch(editComment(reply.id, { flagged: !reply.abuseFlagged })); + hideReportConfirmation(); + }; + const actionHandlers = { [ContentActions.EDIT_CONTENT]: () => setEditing(true), [ContentActions.ENDORSE]: () => dispatch(editComment( @@ -60,10 +70,7 @@ function Reply({ title={intl.formatMessage(messages.deleteCommentTitle)} description={intl.formatMessage(messages.deleteCommentDescription)} onClose={hideDeleteConfirmation} - comfirmAction={() => { - dispatch(removeComment(reply.id)); - hideDeleteConfirmation(); - }} + comfirmAction={handleDeleteConfirmation} closeButtonVaraint="tertiary" confirmButtonText={intl.formatMessage(messages.deleteConfirmationDelete)} /> @@ -73,10 +80,7 @@ function Reply({ title={intl.formatMessage(messages.reportCommentTitle)} description={intl.formatMessage(messages.reportCommentDescription)} onClose={hideReportConfirmation} - comfirmAction={() => { - dispatch(editComment(reply.id, { flagged: !reply.abuseFlagged })); - hideReportConfirmation(); - }} + comfirmAction={handleReportConfirmation} confirmButtonVariant="danger" /> )} diff --git a/src/discussions/posts/post/Post.jsx b/src/discussions/posts/post/Post.jsx index d4f8377a..95e0aa7f 100644 --- a/src/discussions/posts/post/Post.jsx +++ b/src/discussions/posts/post/Post.jsx @@ -45,6 +45,17 @@ function Post({ } }; + const handleDeleteConfirmation = () => { + dispatch(removeThread(post.id)); + history.push('.'); + hideDeleteConfirmation(); + }; + + const handleReportConfirmation = () => { + dispatch(updateExistingThread(post.id, { flagged: !post.abuseFlagged })); + hideReportConfirmation(); + }; + const actionHandlers = { [ContentActions.EDIT_CONTENT]: () => history.push({ ...location, @@ -76,11 +87,7 @@ function Post({ title={intl.formatMessage(messages.deletePostTitle)} description={intl.formatMessage(messages.deletePostDescription)} onClose={hideDeleteConfirmation} - comfirmAction={() => { - dispatch(removeThread(post.id)); - history.push('.'); - hideDeleteConfirmation(); - }} + comfirmAction={handleDeleteConfirmation} closeButtonVaraint="tertiary" confirmButtonText={intl.formatMessage(messages.deleteConfirmationDelete)} /> @@ -90,10 +97,7 @@ function Post({ title={intl.formatMessage(messages.reportPostTitle)} description={intl.formatMessage(messages.reportPostDescription)} onClose={hideReportConfirmation} - comfirmAction={() => { - dispatch(updateExistingThread(post.id, { flagged: !post.abuseFlagged })); - hideReportConfirmation(); - }} + comfirmAction={handleReportConfirmation} confirmButtonVariant="danger" /> )} diff --git a/src/index.scss b/src/index.scss index 34c5ee28..b35a84d3 100755 --- a/src/index.scss +++ b/src/index.scss @@ -242,7 +242,7 @@ header { } .zindex-5000 { - z-index: 5000 ; + z-index: 5000; } #paragon-portal-root .pgn__modal-layer {