From 91d77247e24f116ce203074dedd598729fd1e59c Mon Sep 17 00:00:00 2001 From: Maria D'Costa Date: Tue, 16 May 2023 13:50:00 +0400 Subject: [PATCH] Merge pull request #17348 from Expensify/cmartins-allowDeletion Allow money request deletion (cherry picked from commit 3119b61e22862f7004cabfc62613c9b17135ad2d) --- src/languages/en.js | 5 +++-- src/languages/es.js | 5 +++-- src/libs/IOUUtils.js | 3 ++- src/libs/ReportActionsUtils.js | 9 +++++++++ src/libs/ReportUtils.js | 8 +++++--- .../BaseReportActionContextMenu.js | 2 +- .../report/ContextMenu/ContextMenuActions.js | 2 +- .../PopoverReportActionContextMenu.js | 14 ++++++++++---- src/pages/home/report/ReportActionItem.js | 19 ++++++++++++++++++- 9 files changed, 52 insertions(+), 15 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index f9d9eaf23826..c5060da2d03b 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -1,5 +1,6 @@ import {CONST as COMMON_CONST} from 'expensify-common/lib/CONST'; import CONST from '../CONST'; +import * as ReportActionsUtils from '../libs/ReportActionsUtils'; /* eslint-disable max-len */ export default { @@ -253,8 +254,8 @@ export default { copyEmailToClipboard: 'Copy email to clipboard', markAsUnread: 'Mark as unread', editComment: 'Edit comment', - deleteComment: 'Delete comment', - deleteConfirmation: 'Are you sure you want to delete this comment?', + deleteAction: ({action}) => `Delete ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}`, + deleteConfirmation: ({action}) => `Are you sure you want to delete this ${ReportActionsUtils.isMoneyRequestAction(action) ? 'request' : 'comment'}?`, onlyVisible: 'Only visible to', replyInThread: 'Reply in thread', }, diff --git a/src/languages/es.js b/src/languages/es.js index 23114b5bc428..53c8043e4fa0 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -1,4 +1,5 @@ import CONST from '../CONST'; +import * as ReportActionsUtils from '../libs/ReportActionsUtils'; /* eslint-disable max-len */ export default { @@ -252,8 +253,8 @@ export default { copyEmailToClipboard: 'Copiar email al portapapeles', markAsUnread: 'Marcar como no leído', editComment: 'Editar comentario', - deleteComment: 'Eliminar comentario', - deleteConfirmation: '¿Estás seguro de que quieres eliminar este comentario?', + deleteAction: ({action}) => `Eliminar ${ReportActionsUtils.isMoneyRequestAction(action) ? 'pedido' : 'comentario'}`, + deleteConfirmation: ({action}) => `¿Estás seguro de que quieres eliminar este ${ReportActionsUtils.isMoneyRequestAction(action) ? 'pedido' : 'comentario'}`, onlyVisible: 'Visible sólo para', replyInThread: 'Responder en el hilo', }, diff --git a/src/libs/IOUUtils.js b/src/libs/IOUUtils.js index f5ebefbad50c..7224e63f31e0 100644 --- a/src/libs/IOUUtils.js +++ b/src/libs/IOUUtils.js @@ -1,5 +1,6 @@ import _ from 'underscore'; import CONST from '../CONST'; +import * as ReportActionsUtils from './ReportActionsUtils'; /** * Calculates the amount per user given a list of participants @@ -74,7 +75,7 @@ function updateIOUOwnerAndTotal(iouReport, actorEmail, amount, currency, type = */ function getIOUReportActions(reportActions, iouReport, type = '', pendingAction = '', filterRequestsInDifferentCurrency = false) { return _.chain(reportActions) - .filter((action) => action.originalMessage && action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && (!_.isEmpty(type) ? action.originalMessage.type === type : true)) + .filter((action) => action.originalMessage && ReportActionsUtils.isMoneyRequestAction(action) && (!_.isEmpty(type) ? action.originalMessage.type === type : true)) .filter((action) => action.originalMessage.IOUReportID.toString() === iouReport.reportID.toString()) .filter((action) => (!_.isEmpty(pendingAction) ? action.pendingAction === pendingAction : true)) .filter((action) => (filterRequestsInDifferentCurrency ? action.originalMessage.currency !== iouReport.currency : true)) diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 558afca9904e..098282639975 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -40,6 +40,14 @@ function isDeletedAction(reportAction) { return message.length === 0 || lodashGet(message, [0, 'html']) === ''; } +/** + * @param {Object} reportAction + * @returns {Boolean} + */ +function isMoneyRequestAction(reportAction) { + return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.IOU; +} + /** * Returns the parentReportAction if the given report is a thread. * @@ -332,6 +340,7 @@ export { getSortedReportActionsForDisplay, getLastClosedReportAction, getLatestReportActionFromOnyxData, + isMoneyRequestAction, getLinkedTransactionID, isCreatedTaskReportAction, getParentReportAction, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8fa24c8fb75c..11979433607a 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -184,6 +184,8 @@ function canEditReportAction(reportAction) { } /** + * Whether the Money Request report is settled + * * @param {String} reportID * @returns {Boolean} */ @@ -192,7 +194,7 @@ function isSettled(reportID) { } /** - * Can only delete if it's an ADDCOMMENT, the author is this user. + * Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report * * @param {Object} reportAction * @returns {Boolean} @@ -200,8 +202,8 @@ function isSettled(reportID) { function canDeleteReportAction(reportAction) { return ( reportAction.actorEmail === sessionEmail && - reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && - !ReportActionsUtils.isCreatedTaskReportAction(reportAction) && + ((reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportActionsUtils.isCreatedTaskReportAction(reportAction)) || + (ReportActionsUtils.isMoneyRequestAction(reportAction) && !isSettled(reportAction.originalMessage.IOUReportID))) && reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ); } diff --git a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js index 8467cc574370..d307d06b7984 100755 --- a/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js @@ -90,7 +90,7 @@ class BaseReportActionContextMenu extends React.Component { return ( {}, }, { - textTranslateKey: 'reportActionContextMenu.deleteComment', + textTranslateKey: 'reportActionContextMenu.deleteAction', icon: Expensicons.Trashcan, shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) => // Until deleting parent threads is supported in FE, we will prevent the user from deleting a thread parent diff --git a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js index 708e534d71c8..dfdf559e79c7 100644 --- a/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js +++ b/src/pages/home/report/ContextMenu/PopoverReportActionContextMenu.js @@ -8,6 +8,8 @@ import PopoverWithMeasuredContent from '../../../../components/PopoverWithMeasur import BaseReportActionContextMenu from './BaseReportActionContextMenu'; import ConfirmModal from '../../../../components/ConfirmModal'; import CONST from '../../../../CONST'; +import * as ReportActionsUtils from '../../../../libs/ReportActionsUtils'; +import * as IOU from '../../../../libs/actions/IOU'; const propTypes = { ...withLocalizePropTypes, @@ -249,7 +251,12 @@ class PopoverReportActionContextMenu extends React.Component { confirmDeleteAndHideModal() { this.callbackWhenDeleteModalHide = () => (this.onComfirmDeleteModal = this.runAndResetCallback(this.onComfirmDeleteModal)); - Report.deleteReportComment(this.state.reportID, this.state.reportAction); + + if (ReportActionsUtils.isMoneyRequestAction(this.state.reportAction)) { + IOU.deleteMoneyRequest(this.state.reportID, this.state.reportAction.originalMessage.IOUReportID, this.state.reportAction, true); + } else { + Report.deleteReportComment(this.state.reportID, this.state.reportAction); + } this.setState({isDeleteCommentConfirmModalVisible: false}); } @@ -257,7 +264,6 @@ class PopoverReportActionContextMenu extends React.Component { this.callbackWhenDeleteModalHide = () => (this.onCancelDeleteModal = this.runAndResetCallback(this.onCancelDeleteModal)); this.setState({ reportID: '0', - reportAction: {}, isDeleteCommentConfirmModalVisible: false, shouldSetModalVisibilityForDeleteConfirmation: true, isArchivedRoom: false, @@ -313,13 +319,13 @@ class PopoverReportActionContextMenu extends React.Component { /> >>>>>> 3119b61e22 (Merge pull request #17348 from Expensify/cmartins-allowDeletion) import Permissions from '../../../libs/Permissions'; const propTypes = { @@ -203,7 +208,19 @@ class ReportActionItem extends Component { checkIfContextMenuActive={this.checkIfContextMenuActive} /> ); +<<<<<<< HEAD } else if (ReportActionUtils.isCreatedTaskReportAction(this.props.action)) { +======= + } else if (this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED) { + children = ( + + ); + } else if (ReportActionsUtils.isCreatedTaskReportAction(this.props.action)) { +>>>>>>> 3119b61e22 (Merge pull request #17348 from Expensify/cmartins-allowDeletion) children = ( {isWhisper && (