Skip to content

Commit

Permalink
Merge pull request #17348 from Expensify/cmartins-allowDeletion
Browse files Browse the repository at this point in the history
Allow money request deletion

(cherry picked from commit 3119b61)
  • Loading branch information
MariaHCD authored and OSBotify committed May 16, 2023
1 parent 57b855d commit 91d7724
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/languages/en.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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',
},
Expand Down
5 changes: 3 additions & 2 deletions src/languages/es.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CONST from '../CONST';
import * as ReportActionsUtils from '../libs/ReportActionsUtils';

/* eslint-disable max-len */
export default {
Expand Down Expand Up @@ -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',
},
Expand Down
3 changes: 2 additions & 1 deletion src/libs/IOUUtils.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
Expand Down
9 changes: 9 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -332,6 +340,7 @@ export {
getSortedReportActionsForDisplay,
getLastClosedReportAction,
getLatestReportActionFromOnyxData,
isMoneyRequestAction,
getLinkedTransactionID,
isCreatedTaskReportAction,
getParentReportAction,
Expand Down
8 changes: 5 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ function canEditReportAction(reportAction) {
}

/**
* Whether the Money Request report is settled
*
* @param {String} reportID
* @returns {Boolean}
*/
Expand All @@ -192,16 +194,16 @@ 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}
*/
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
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class BaseReportActionContextMenu extends React.Component {
return (
<ContextMenuItem
icon={contextAction.icon}
text={this.props.translate(contextAction.textTranslateKey)}
text={this.props.translate(contextAction.textTranslateKey, {action: this.props.reportAction})}
successIcon={contextAction.successIcon}
successText={contextAction.successTextTranslateKey ? this.props.translate(contextAction.successTextTranslateKey) : undefined}
isMini={this.props.isMini}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export default [
getDescription: () => {},
},
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -249,15 +251,19 @@ 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});
}

hideDeleteModal() {
this.callbackWhenDeleteModalHide = () => (this.onCancelDeleteModal = this.runAndResetCallback(this.onCancelDeleteModal));
this.setState({
reportID: '0',
reportAction: {},
isDeleteCommentConfirmModalVisible: false,
shouldSetModalVisibilityForDeleteConfirmation: true,
isArchivedRoom: false,
Expand Down Expand Up @@ -313,13 +319,13 @@ class PopoverReportActionContextMenu extends React.Component {
/>
</PopoverWithMeasuredContent>
<ConfirmModal
title={this.props.translate('reportActionContextMenu.deleteComment')}
title={this.props.translate('reportActionContextMenu.deleteAction', {action: this.state.reportAction})}
isVisible={this.state.isDeleteCommentConfirmModalVisible}
shouldSetModalVisibility={this.state.shouldSetModalVisibilityForDeleteConfirmation}
onConfirm={this.confirmDeleteAndHideModal}
onCancel={this.hideDeleteModal}
onModalHide={this.callbackWhenDeleteModalHide}
prompt={this.props.translate('reportActionContextMenu.deleteConfirmation')}
prompt={this.props.translate('reportActionContextMenu.deleteConfirmation', {action: this.state.reportAction})}
confirmText={this.props.translate('common.delete')}
cancelText={this.props.translate('common.cancel')}
danger
Expand Down
19 changes: 18 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import * as User from '../../../libs/actions/User';
import * as ReportUtils from '../../../libs/ReportUtils';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import * as ReportActions from '../../../libs/actions/ReportActions';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';
import reportPropTypes from '../../reportPropTypes';
import {ShowContextMenuContext} from '../../../components/ShowContextMenuContext';
import focusTextInputAfterAnimation from '../../../libs/focusTextInputAfterAnimation';
Expand All @@ -48,7 +49,11 @@ import DisplayNames from '../../../components/DisplayNames';
import personalDetailsPropType from '../../personalDetailsPropType';
import ReportActionItemDraft from './ReportActionItemDraft';
import TaskPreview from '../../../components/ReportActionItem/TaskPreview';
<<<<<<< HEAD
import * as ReportActionUtils from '../../../libs/ReportActionsUtils';
=======
import TaskAction from '../../../components/ReportActionItem/TaskAction';
>>>>>>> 3119b61e22 (Merge pull request #17348 from Expensify/cmartins-allowDeletion)
import Permissions from '../../../libs/Permissions';

const propTypes = {
Expand Down Expand Up @@ -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 = (
<TaskAction
taskReportID={this.props.action.originalMessage.taskReportID.toString()}
actionName={this.props.action.actionName}
isHovered={hovered}
/>
);
} else if (ReportActionsUtils.isCreatedTaskReportAction(this.props.action)) {
>>>>>>> 3119b61e22 (Merge pull request #17348 from Expensify/cmartins-allowDeletion)
children = (
<TaskPreview
taskReportID={this.props.action.originalMessage.taskReportID.toString()}
Expand Down Expand Up @@ -358,7 +375,7 @@ class ReportActionItem extends Component {
pendingAction={this.props.draftMessage ? null : this.props.action.pendingAction}
errors={this.props.action.errors}
errorRowStyles={[styles.ml10, styles.mr2]}
needsOffscreenAlphaCompositing={this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU}
needsOffscreenAlphaCompositing={ReportActionsUtils.isMoneyRequestAction(this.props.action)}
>
{isWhisper && (
<View style={[styles.flexRow, styles.pl5, styles.pt2]}>
Expand Down

0 comments on commit 91d7724

Please sign in to comment.