refactor: handled confirm action to functions

This commit is contained in:
ayeshoali
2022-11-30 19:03:30 +05:00
parent 42f1efd0a0
commit 7912d70388
4 changed files with 38 additions and 26 deletions

View File

@@ -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"
/>
)}