Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow money request deletion #17348

Merged
merged 27 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
99027f8
add delete to iou context menu
luacmartins Apr 12, 2023
9edaa87
update canDeleteReportAction
luacmartins Apr 12, 2023
e6948b0
add isReportSettled prop
luacmartins Apr 12, 2023
b12bf1d
add isReportSettled param to context menu
luacmartins Apr 12, 2023
012f2e5
fix const typo
luacmartins Apr 12, 2023
dc0cb47
create isReportSettled
luacmartins Apr 12, 2023
e86c484
rm isReportSettled props and params
luacmartins Apr 12, 2023
64de99f
get iouReport in isReimbursed
luacmartins Apr 12, 2023
1e45e0f
use lodash
luacmartins Apr 12, 2023
8899cc8
rename method to isSettled, fix bug
luacmartins Apr 12, 2023
7f1af58
update confirmation modal
luacmartins Apr 12, 2023
8299d65
rm reportAction reset on modal hide
luacmartins Apr 12, 2023
bdf32e6
add api callback conditional
luacmartins Apr 12, 2023
3324de7
update tooltip
luacmartins Apr 12, 2023
19c9b59
create isMoneyRequestAction and replace usages of const
luacmartins Apr 14, 2023
556c961
use isMoneyRequestAction in other places
luacmartins Apr 14, 2023
5bacd9c
fix undefined error
luacmartins Apr 14, 2023
13c39d7
resolve conflicts
luacmartins May 13, 2023
a241b2b
resolve conflicts
luacmartins May 13, 2023
f4e505d
resolve conflicts
luacmartins May 13, 2023
eb36561
revert podfile change
luacmartins May 13, 2023
d60a888
add delete call
luacmartins May 13, 2023
3c81f6c
fix function call
luacmartins May 13, 2023
030064b
resolve conflicts
luacmartins May 15, 2023
76efc7c
resolve conflicts
luacmartins May 15, 2023
64e2312
Update src/pages/home/report/ContextMenu/BaseReportActionContextMenu.js
mountiny May 16, 2023
7bf5ba9
Merge branch 'main' into cmartins-allowDeletion
mountiny May 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'}`,
Copy link
Contributor

@eh2077 eh2077 Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change missed a question mark and caused #50290

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: {},
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
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
6 changes: 3 additions & 3 deletions 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 @@ -49,7 +50,6 @@ import personalDetailsPropType from '../../personalDetailsPropType';
import ReportActionItemDraft from './ReportActionItemDraft';
import TaskPreview from '../../../components/ReportActionItem/TaskPreview';
import TaskAction from '../../../components/ReportActionItem/TaskAction';
import * as ReportActionUtils from '../../../libs/ReportActionsUtils';
import Permissions from '../../../libs/Permissions';

const propTypes = {
Expand Down Expand Up @@ -212,7 +212,7 @@ class ReportActionItem extends Component {
isHovered={hovered}
/>
);
} else if (ReportActionUtils.isCreatedTaskReportAction(this.props.action)) {
} else if (ReportActionsUtils.isCreatedTaskReportAction(this.props.action)) {
children = (
<TaskPreview
taskReportID={this.props.action.originalMessage.taskReportID.toString()}
Expand Down Expand Up @@ -367,7 +367,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
Loading