From 8e449acde774de11e6da97078d7f21bd5673eb14 Mon Sep 17 00:00:00 2001 From: ayeshoali Date: Mon, 28 Nov 2022 14:09:14 +0500 Subject: [PATCH] refactor: changed deleteconfirm and reportconfirm rename to comfirmAction and made it required --- src/data/constants.js | 9 +++++++++ src/discussions/comments/comment/Comment.jsx | 4 ++-- src/discussions/comments/comment/Reply.jsx | 4 ++-- src/discussions/common/Confirmation.jsx | 19 ++++++++----------- src/discussions/posts/post/Post.jsx | 4 ++-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/data/constants.js b/src/data/constants.js index 357d3b14..5dccef0b 100644 --- a/src/data/constants.js +++ b/src/data/constants.js @@ -13,6 +13,15 @@ export const ThreadType = { DISCUSSION: 'discussion', }; +/** + * Enum for report Confirmation. + * @readonly + * @enum {string} + */ +export const ReportConfirmation = { + Report: 'Report inappropriate content?', +}; + /** * Enum to map between endorsement status and friendly name. * @readonly diff --git a/src/discussions/comments/comment/Comment.jsx b/src/discussions/comments/comment/Comment.jsx index 1b67a8b0..c3adf7b9 100644 --- a/src/discussions/comments/comment/Comment.jsx +++ b/src/discussions/comments/comment/Comment.jsx @@ -76,7 +76,7 @@ function Comment({ title={intl.formatMessage(messages.deleteResponseTitle)} description={intl.formatMessage(messages.deleteResponseDescription)} onClose={hideDeleteConfirmation} - onDelete={() => { + comfirmAction={() => { dispatch(removeComment(comment.id)); hideDeleteConfirmation(); }} @@ -87,7 +87,7 @@ function Comment({ title={intl.formatMessage(messages.reportResponseTitle)} description={intl.formatMessage(messages.reportResponseDescription)} onClose={hideReportConfirmation} - onReport={() => { + comfirmAction={() => { dispatch(editComment(comment.id, { flagged: !comment.abuseFlagged })); hideReportConfirmation(); }} diff --git a/src/discussions/comments/comment/Reply.jsx b/src/discussions/comments/comment/Reply.jsx index bec40d24..ce8a74a4 100644 --- a/src/discussions/comments/comment/Reply.jsx +++ b/src/discussions/comments/comment/Reply.jsx @@ -57,7 +57,7 @@ function Reply({ title={intl.formatMessage(messages.deleteCommentTitle)} description={intl.formatMessage(messages.deleteCommentDescription)} onClose={hideDeleteConfirmation} - onDelete={() => { + comfirmAction={() => { dispatch(removeComment(reply.id)); hideDeleteConfirmation(); }} @@ -68,7 +68,7 @@ function Reply({ title={intl.formatMessage(messages.reportCommentTitle)} description={intl.formatMessage(messages.reportCommentDescription)} onClose={hideReportConfirmation} - onReport={() => { + comfirmAction={() => { dispatch(editComment(reply.id, { flagged: !reply.abuseFlagged })); hideReportConfirmation(); }} diff --git a/src/discussions/common/Confirmation.jsx b/src/discussions/common/Confirmation.jsx index cfdd9221..6db98e89 100644 --- a/src/discussions/common/Confirmation.jsx +++ b/src/discussions/common/Confirmation.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { ActionRow, Button, ModalDialog } from '@edx/paragon'; +import { ReportConfirmation } from '../../data/constants'; import messages from '../messages'; function Confirmation({ @@ -12,9 +13,10 @@ function Confirmation({ title, description, onClose, - onDelete, - onReport, + comfirmAction, }) { + const ifDeleteConfirmation = title === ReportConfirmation.Report || false; + return ( @@ -27,11 +29,11 @@ function Confirmation({ - + {intl.formatMessage(messages.deleteConfirmationCancel)} - @@ -45,14 +47,9 @@ Confirmation.propTypes = { intl: intlShape.isRequired, isOpen: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, - onDelete: PropTypes.func, - onReport: PropTypes.func, + comfirmAction: PropTypes.func.isRequired, title: PropTypes.string.isRequired, description: PropTypes.string.isRequired, }; -Confirmation.defaultProps = { - onDelete: undefined, - onReport: undefined, -}; export default injectIntl(Confirmation); diff --git a/src/discussions/posts/post/Post.jsx b/src/discussions/posts/post/Post.jsx index 3ecd59a1..607b2a1f 100644 --- a/src/discussions/posts/post/Post.jsx +++ b/src/discussions/posts/post/Post.jsx @@ -73,7 +73,7 @@ function Post({ title={intl.formatMessage(messages.deletePostTitle)} description={intl.formatMessage(messages.deletePostDescription)} onClose={hideDeleteConfirmation} - onDelete={() => { + comfirmAction={() => { dispatch(removeThread(post.id)); history.push('.'); hideDeleteConfirmation(); @@ -85,7 +85,7 @@ function Post({ title={intl.formatMessage(messages.reportPostTitle)} description={intl.formatMessage(messages.reportPostDescription)} onClose={hideReportConfirmation} - onReport={() => { + comfirmAction={() => { dispatch(updateExistingThread(post.id, { flagged: !post.abuseFlagged })); hideReportConfirmation(); }}