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 14 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
4 changes: 2 additions & 2 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,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: ({actionName}) => `Delete ${actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? 'request' : 'comment'}`,
deleteConfirmation: ({actionName}) => `Are you sure you want to delete this ${actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? 'request' : 'comment'}?`,
},
emojiReactions: {
addReactionTooltip: 'Add reaction',
Expand Down
4 changes: 2 additions & 2 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,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: ({actionName}) => `Eliminar ${actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? 'pedido' : 'comentario'}`,
deleteConfirmation: ({actionName}) => `¿Estás seguro de que quieres eliminar este ${actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? 'pedido' : 'comentario'}`,
},
emojiReactions: {
addReactionTooltip: 'Añadir una reacción',
Expand Down
16 changes: 14 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,25 @@ function canEditReportAction(reportAction) {
}

/**
* Can only delete if it's an ADDCOMMENT, the author is this user.
* Whether the Money Request report has been reimbursed
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {String} reportID
* @returns {Boolean}
*/
function isSettled(reportID) {
return !lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'hasOutstandingIOU']);
}

/**
* 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
&& (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT
|| (reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && !isSettled(reportAction.originalMessage.IOUReportID)))
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
&& reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
}

Expand Down Expand Up @@ -1770,4 +1781,5 @@ export {
getSmallSizeAvatar,
getMoneyRequestOptions,
canRequestMoney,
isSettled,
};
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, {actionName: this.props.reportAction.actionName})}
successIcon={contextAction.successIcon}
successText={contextAction.successTextTranslateKey
? this.props.translate(contextAction.successTextTranslateKey)
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 @@ -235,7 +235,7 @@ export default [
getDescription: () => {},
},
{
textTranslateKey: 'reportActionContextMenu.deleteComment',
textTranslateKey: 'reportActionContextMenu.deleteAction',
icon: Expensicons.Trashcan,
shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) => type === CONTEXT_MENU_TYPES.REPORT_ACTION
&& ReportUtils.canDeleteReportAction(reportAction) && !isArchivedRoom && !isChronosReport,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,19 @@ class PopoverReportActionContextMenu extends React.Component {

confirmDeleteAndHideModal() {
this.callbackWhenDeleteModalHide = () => this.onComfirmDeleteModal = this.runAndResetCallback(this.onComfirmDeleteModal);
Report.deleteReportComment(this.state.reportID, this.state.reportAction);

if (this.state.reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU) {
// @TODO: Implement new DeleteMoneyRequest API command from issue https://github.com/Expensify/Expensify/issues/270502
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
} 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 @@ -324,13 +328,13 @@ class PopoverReportActionContextMenu extends React.Component {
/>
</PopoverWithMeasuredContent>
<ConfirmModal
title={this.props.translate('reportActionContextMenu.deleteComment')}
title={this.props.translate('reportActionContextMenu.deleteAction', {actionName: this.state.reportAction.actionName})}
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', {actionName: this.state.reportAction.actionName})}
confirmText={this.props.translate('common.delete')}
cancelText={this.props.translate('common.cancel')}
danger
Expand Down