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

Add DeleteMoneyRequest #19095

Merged
merged 95 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
ea05ff8
use deleteMoneyRequest
luacmartins May 17, 2023
b056cf7
resolve conflicts
luacmartins May 19, 2023
d94f105
update display logic
luacmartins May 19, 2023
4426261
refactor chatReports and iouReports into allReports
luacmartins May 19, 2023
3cc573b
optimistically rm create action
luacmartins May 19, 2023
b9a7c44
refactor updateIOUOwnerAndTotal
luacmartins May 19, 2023
69f2621
Merge branch 'main' into cmartins-addDelete
luacmartins May 23, 2023
66885a9
fix updateIOUOwnerAndTotal
luacmartins May 23, 2023
229f293
fix logic to display delete in MoneyRequestHeader
luacmartins May 23, 2023
062bcf1
fix style
luacmartins May 23, 2023
aa1efde
rm chatReportID param
luacmartins May 23, 2023
9e237fc
rm iouReportID param
luacmartins May 23, 2023
3d5dcb7
Merge branch 'main' into cmartins-addDelete
luacmartins May 23, 2023
f68ca85
Merge branch 'main' into cmartins-addDelete
luacmartins May 24, 2023
213270d
resolve conflicts
luacmartins May 24, 2023
2405fe8
resolve conflicts
luacmartins Jun 1, 2023
12d257e
add currency to optimistic transaction
luacmartins Jun 1, 2023
03fd433
update optimistic data
luacmartins Jun 2, 2023
527250f
pass right params to delete command
luacmartins Jun 2, 2023
8197f84
fix iterable error
luacmartins Jun 2, 2023
e55b292
navigate when report is deleted
luacmartins Jun 2, 2023
a7a7548
Merge branch 'main' into cmartins-addDelete
luacmartins Jun 5, 2023
60322cb
rm transaction thread if no comments
luacmartins Jun 5, 2023
ff564f2
add delete logic to iou reports
luacmartins Jun 6, 2023
d854d4d
add logic to delete transaction thread
luacmartins Jun 6, 2023
c1ea776
update optimistic data logic
luacmartins Jun 6, 2023
8fa23b9
use transactionThreadID
luacmartins Jun 6, 2023
22bc9fb
use onyx merge
luacmartins Jun 6, 2023
0cd29e5
update reportPreview message
luacmartins Jun 6, 2023
bf18a54
rm transactions
luacmartins Jun 6, 2023
485cff3
add deleted request copy, update render logic
luacmartins Jun 6, 2023
627457c
update logic to delete iou report
luacmartins Jun 6, 2023
ab68f9f
reuse var
luacmartins Jun 6, 2023
c70efbb
update transaction header for deleted requests
luacmartins Jun 6, 2023
e56bdec
create isDeletedParentAction and refactor code
luacmartins Jun 6, 2023
d81c58b
rm dupe import
luacmartins Jun 6, 2023
eac631a
fix logic to delete transaction thread
luacmartins Jun 6, 2023
3ab5277
refactor new code in reportscreen
luacmartins Jun 6, 2023
58e9cc4
fix navigation
luacmartins Jun 6, 2023
8cc16c9
add successData
luacmartins Jun 6, 2023
0da5178
add failureData
luacmartins Jun 6, 2023
1cfcdd5
add comments
luacmartins Jun 6, 2023
26ece64
update checkmark logic
luacmartins Jun 6, 2023
27f16cc
resolve conflicts
luacmartins Jun 6, 2023
6d32573
fix style
luacmartins Jun 7, 2023
eff8991
Merge branch 'main' into cmartins-addDelete
luacmartins Jun 7, 2023
678c0b0
fix route import, add transactions default
luacmartins Jun 7, 2023
51f48f4
add early return for transactions;
luacmartins Jun 7, 2023
59799e6
fix bad conflict resolution
luacmartins Jun 7, 2023
fbc13f6
update moneyRequestHeader to account for deleted transaction
luacmartins Jun 7, 2023
de2c169
fix styles
luacmartins Jun 7, 2023
476df56
gst
luacmartins Jun 7, 2023
68491fc
move comment
luacmartins Jun 7, 2023
c592af7
refactor MoneyRequestHeader
luacmartins Jun 7, 2023
eaea5f6
update comments
luacmartins Jun 7, 2023
964d5d1
rm reportID prop
luacmartins Jun 8, 2023
7814370
rm IOUAction if IOU report is deleted
luacmartins Jun 8, 2023
7a82cb0
add error messsage
luacmartins Jun 8, 2023
9d71485
resolve conflicts
luacmartins Jun 21, 2023
e57e7d1
Merge branch 'main' into cmartins-addDelete
luacmartins Jun 26, 2023
b3df54c
resolve conflicts
luacmartins Jun 26, 2023
f32559b
use parentReportAction
luacmartins Jun 26, 2023
e33fcf6
rm transaction id
luacmartins Jun 27, 2023
c933847
Merge branch 'main' into cmartins-addDelete
luacmartins Jun 28, 2023
2766e7b
fix transaction header
luacmartins Jun 28, 2023
6d69c2b
rm report actions for transaction thread
luacmartins Jun 28, 2023
d52e138
fix style
luacmartins Jun 28, 2023
27e9eaa
fix calls to isTransactionThread
luacmartins Jun 28, 2023
0d4968d
fix conflicts
luacmartins Jul 4, 2023
3a4f2ab
fix conflict
luacmartins Jul 6, 2023
e46cd94
set isDeletedParentAction=true when reportAction is a parent
luacmartins Jul 6, 2023
8394118
resolve conflicts
luacmartins Jul 10, 2023
fb7c129
add support for null action
luacmartins Jul 11, 2023
60e5edb
fix style
luacmartins Jul 12, 2023
af5b27e
Merge branch 'main' into cmartins-addDelete
luacmartins Jul 12, 2023
07c12b1
fix getLastVisibleMessage
luacmartins Jul 13, 2023
db4a93b
resolve conflicts
luacmartins Jul 13, 2023
ca2f56e
update lastMessageText to getLastVisibleMessage
luacmartins Jul 13, 2023
5bc4688
move header logic to reportScreen
luacmartins Jul 13, 2023
59da0ed
resolve conflicts
luacmartins Jul 14, 2023
73a58fd
update footer logic for deleted action
luacmartins Jul 14, 2023
2ec061f
resolve conflicts
luacmartins Jul 14, 2023
cf11adc
Merge branch 'main' into cmartins-addDelete
luacmartins Jul 18, 2023
64e0486
fix error when deleting from transaction thread
luacmartins Jul 18, 2023
ae14a96
fix navigation issue
luacmartins Jul 18, 2023
e4ddef0
fix conflicts
luacmartins Jul 19, 2023
6677b75
Merge branch 'main' into cmartins-addDelete
luacmartins Jul 19, 2023
9bd7c71
rm param, fix migration
luacmartins Jul 19, 2023
a92a969
rm three button props from moneyreportheader
luacmartins Jul 20, 2023
75b975a
Merge branch 'main' into cmartins-addDelete
luacmartins Jul 20, 2023
86a93ae
resolve conflicts
luacmartins Jul 25, 2023
3efea95
fix undefined reportAction error
luacmartins Jul 25, 2023
d0194b8
resolve conflicts
luacmartins Jul 25, 2023
a0cfe59
fix allReports usage
luacmartins Jul 25, 2023
4bd7481
resolve conflicts
luacmartins Jul 26, 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
11 changes: 0 additions & 11 deletions src/components/MoneyReportHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import lodashGet from 'lodash/get';
import HeaderWithBackButton from './HeaderWithBackButton';
import iouReportPropTypes from '../pages/iouReportPropTypes';
import * as ReportUtils from '../libs/ReportUtils';
import * as Expensicons from './Icon/Expensicons';
import participantPropTypes from './participantPropTypes';
import styles from '../styles/styles';
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions';
Expand All @@ -19,7 +18,6 @@ import ONYXKEYS from '../ONYXKEYS';
import * as IOU from '../libs/actions/IOU';
import * as CurrencyUtils from '../libs/CurrencyUtils';
import reportPropTypes from '../pages/reportPropTypes';
import useLocalize from '../hooks/useLocalize';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -63,22 +61,13 @@ function MoneyReportHeader(props) {
const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport);
const shouldShowPaypal = Boolean(lodashGet(props.personalDetails, [moneyRequestReport.managerID, 'payPalMeAddress']));
const formattedAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.report), props.report.currency);
const {translate} = useLocalize();

return (
<View style={[styles.pt0]}>
<HeaderWithBackButton
shouldShowAvatarWithDisplay
shouldShowPinButton={false}
shouldShowThreeDotsButton={false}
threeDotsMenuItems={[
{
icon: Expensicons.Trashcan,
text: translate('common.delete'),
onSelected: () => {},
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)}
report={props.report}
policies={props.policies}
personalDetails={props.personalDetails}
Expand Down
14 changes: 11 additions & 3 deletions src/components/MoneyRequestHeader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useCallback} from 'react';
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import PropTypes from 'prop-types';
Expand All @@ -16,6 +16,8 @@ import Navigation from '../libs/Navigation/Navigation';
import ROUTES from '../ROUTES';
import * as Policy from '../libs/actions/Policy';
import ONYXKEYS from '../ONYXKEYS';
import * as IOU from '../libs/actions/IOU';
import * as ReportActionsUtils from '../libs/ReportActionsUtils';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -58,6 +60,12 @@ function MoneyRequestHeader(props) {
const report = props.report;
report.ownerAccountID = lodashGet(props, ['parentReport', 'ownerAccountID'], null);
report.ownerEmail = lodashGet(props, ['parentReport', 'ownerEmail'], '');
const parentReportAction = ReportActionsUtils.getParentReportAction(props.report);

const deleteTransaction = useCallback(() => {
IOU.deleteMoneyRequest(parentReportAction.originalMessage.IOUTransactionID, parentReportAction, true);
}, [parentReportAction]);

return (
<View style={[styles.pl0]}>
<HeaderWithBackButton
Expand All @@ -67,8 +75,8 @@ function MoneyRequestHeader(props) {
threeDotsMenuItems={[
{
icon: Expensicons.Trashcan,
text: props.translate('common.delete'),
onSelected: () => {},
text: props.translate('reportActionContextMenu.deleteAction', {action: parentReportAction}),
onSelected: deleteTransaction,
},
]}
threeDotsAnchorPosition={styles.threeDotsPopoverOffsetNoCloseButton(props.windowWidth)}
Expand Down
6 changes: 5 additions & 1 deletion src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as Report from '../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
import refPropTypes from '../refPropTypes';
import RenderHTML from '../RenderHTML';
import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils';
import reportPropTypes from '../../pages/reportPropTypes';

Expand Down Expand Up @@ -124,6 +125,7 @@ function MoneyRequestAction(props) {
};

let shouldShowPendingConversionMessage = false;
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(props.action);
if (
!_.isEmpty(props.iouReport) &&
!_.isEmpty(props.reportActions) &&
Expand All @@ -135,7 +137,9 @@ function MoneyRequestAction(props) {
shouldShowPendingConversionMessage = IOUUtils.isIOUReportPendingCurrencyConversion(props.reportActions, props.iouReport);
}

return (
return isDeletedParentAction ? (
<RenderHTML html={`<comment>${props.translate('parentReportAction.deletedRequest')}</comment>`} />
) : (
<IOUPreview
iouReportID={props.requestReportID}
chatReportID={props.chatReportID}
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ export default {
},
parentReportAction: {
deletedMessage: '[Deleted message]',
deletedRequest: '[Deleted request]',
hiddenMessage: '[Hidden message]',
},
threads: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,7 @@ export default {
},
parentReportAction: {
deletedMessage: '[Mensaje eliminado]',
deletedRequest: '[Pedido eliminado]',
hiddenMessage: '[Mensaje oculto]',
},
threads: {
Expand Down
8 changes: 4 additions & 4 deletions src/libs/IOUUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ function calculateAmount(numberOfParticipants, total, isDefaultUser = false) {
* @param {Number} actorAccountID
* @param {Number} amount
* @param {String} currency
* @param {String} type
* @param {String} isDeleting - whether the user is deleting the request
* @returns {Object}
*/
function updateIOUOwnerAndTotal(iouReport, actorAccountID, amount, currency, type = CONST.IOU.REPORT_ACTION_TYPE.CREATE) {
function updateIOUOwnerAndTotal(iouReport, actorAccountID, amount, currency, isDeleting = false) {
if (currency !== iouReport.currency) {
return iouReport;
}
Expand All @@ -44,9 +44,9 @@ function updateIOUOwnerAndTotal(iouReport, actorAccountID, amount, currency, typ
const iouReportUpdate = {...iouReport};

if (actorAccountID === iouReport.ownerAccountID) {
iouReportUpdate.total += type === CONST.IOU.REPORT_ACTION_TYPE.DELETE ? -amount : amount;
iouReportUpdate.total += isDeleting ? -amount : amount;
} else {
iouReportUpdate.total += type === CONST.IOU.REPORT_ACTION_TYPE.DELETE ? amount : -amount;
iouReportUpdate.total += isDeleting ? amount : -amount;
}

if (iouReportUpdate.total < 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ function getAllReportErrors(report, reportActions) {
const reportsActions = reportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] || {};
const reportActionErrors = _.reduce(
reportsActions,
(prevReportActionErrors, action) => (_.isEmpty(action.errors) ? prevReportActionErrors : _.extend(prevReportActionErrors, action.errors)),
(prevReportActionErrors, action) => (!action || _.isEmpty(action.errors) ? prevReportActionErrors : _.extend(prevReportActionErrors, action.errors)),
{},
);

Expand Down
18 changes: 15 additions & 3 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ function isDeletedAction(reportAction) {
return message.length === 0 || lodashGet(message, [0, 'html']) === '';
}

/**
* @param {Object} reportAction
* @returns {Boolean}
*/
function isDeletedParentAction(reportAction) {
return lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false) && lodashGet(reportAction, 'childVisibleActionCount', 0) > 0;
}

/**
* @param {Object} reportAction
* @returns {Boolean}
Expand Down Expand Up @@ -334,8 +342,7 @@ function shouldReportActionBeVisible(reportAction, key) {
// All other actions are displayed except thread parents, deleted, or non-pending actions
const isDeleted = isDeletedAction(reportAction);
const isPending = !_.isEmpty(reportAction.pendingAction);
const isDeletedParentAction = lodashGet(reportAction, ['message', 0, 'isDeletedParentAction'], false) && lodashGet(reportAction, 'childVisibleActionCount', 0) > 0;
return !isDeleted || isPending || isDeletedParentAction;
return !isDeleted || isPending || isDeletedParentAction(reportAction);
}

/**
Expand All @@ -346,6 +353,10 @@ function shouldReportActionBeVisible(reportAction, key) {
* @returns {Boolean}
*/
function shouldReportActionBeVisibleAsLastAction(reportAction) {
if (!reportAction) {
return false;
}

return shouldReportActionBeVisible(reportAction, reportAction.reportActionID) && !isWhisperAction(reportAction) && !isDeletedAction(reportAction);
}

Expand Down Expand Up @@ -522,7 +533,7 @@ function getMostRecentReportActionLastModified() {
function getReportPreviewAction(chatReportID, iouReportID) {
return _.find(
allReportActions[chatReportID],
(reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lodashGet(reportAction, 'originalMessage.linkedReportID') === iouReportID,
(reportAction) => reportAction && reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW && lodashGet(reportAction, 'originalMessage.linkedReportID') === iouReportID,
);
}

Expand Down Expand Up @@ -574,6 +585,7 @@ export {
isTransactionThread,
getFormattedAmount,
isSentMoneyReportAction,
isDeletedParentAction,
isReportPreviewAction,
getIOUReportIDFromReportActionPreview,
isMessageDeleted,
Expand Down
10 changes: 9 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ function isCurrentUserSubmitter(reportID) {
* @returns {Boolean}
*/
function canDeleteReportAction(reportAction, reportID) {
const isActionOwner = reportAction.actorAccountID === currentUserAccountID;
if (isActionOwner && ReportActionsUtils.isMoneyRequestAction(reportAction) && !isSettled(reportAction.originalMessage.IOUReportID)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to checking if the report is not settled we should have also checked if the report is submitted. In paid policies you can't delete a money request in a submitted report (unless you are the admin).

return true;
}
if (
reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT ||
reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE ||
Expand All @@ -268,7 +272,7 @@ function canDeleteReportAction(reportAction, reportID) {
) {
return false;
}
if (reportAction.actorAccountID === currentUserAccountID) {
if (isActionOwner) {
return true;
}
const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {});
Expand Down Expand Up @@ -1178,6 +1182,10 @@ function getMoneyRequestReportName(report, policy = undefined) {
* @returns {String}
*/
function getTransactionReportName(reportAction) {
if (ReportActionsUtils.isDeletedParentAction(reportAction)) {
return Localize.translateLocal('parentReportAction.deletedRequest');
}

return Localize.translateLocal(ReportActionsUtils.isSentMoneyReportAction(reportAction) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', {
formattedAmount: ReportActionsUtils.getFormattedAmount(reportAction),
comment: lodashGet(reportAction, 'originalMessage.comment'),
Expand Down
Loading
Loading