Skip to content

Commit 5c804af

Browse files
JulesssssOSBotify
authored andcommitted
Merge pull request #18981 from Expensify/vit-showIOUPreviewForSendMoneyFlow
Show IOU preview for send money flow (cherry picked from commit 04cddaf)
1 parent 00099f0 commit 5c804af

File tree

7 files changed

+56
-16
lines changed

7 files changed

+56
-16
lines changed

src/components/ReportActionItem/IOUPreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const IOUPreview = (props) => {
146146
const moneyRequestAction = ReportUtils.getMoneyRequestAction(props.action);
147147

148148
// If props.action is undefined then we are displaying within IOUDetailsModal and should use the full report amount
149-
const requestAmount = props.isIOUAction ? moneyRequestAction.total : ReportUtils.getMoneyRequestTotal(props.iouReport);
149+
const requestAmount = props.isIOUAction ? moneyRequestAction.amount : ReportUtils.getMoneyRequestTotal(props.iouReport);
150150
const requestCurrency = props.isIOUAction ? moneyRequestAction.currency : props.iouReport.currency;
151151
const requestComment = Str.htmlDecode(moneyRequestAction.comment).trim();
152152

src/components/ReportActionItem/MoneyRequestAction.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as OptionsListUtils from '../../libs/OptionsListUtils';
1919
import * as ReportUtils from '../../libs/ReportUtils';
2020
import * as Report from '../../libs/actions/Report';
2121
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
22-
import * as CurrencyUtils from '../../libs/CurrencyUtils';
22+
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
2323

2424
const propTypes = {
2525
/** All the data of the action */
@@ -99,8 +99,8 @@ const MoneyRequestAction = (props) => {
9999
const formattedUserLogins = _.map(participants, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase());
100100
const thread = ReportUtils.buildOptimisticChatReport(
101101
formattedUserLogins,
102-
props.translate('iou.threadReportName', {
103-
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(props.action, 'originalMessage.amount', 0), lodashGet(props.action, 'originalMessage.currency', '')),
102+
props.translate(ReportActionsUtils.isSentMoneyReportAction(props.action) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', {
103+
formattedAmount: ReportActionsUtils.getFormattedAmount(props.action),
104104
comment: props.action.originalMessage.comment,
105105
}),
106106
'',

src/languages/en.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,8 @@ export default {
333333
payerSettled: ({amount}) => `settled up ${amount}`,
334334
noReimbursableExpenses: 'This report has an invalid amount',
335335
pendingConversionMessage: "Total will update when you're back online",
336-
threadReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
336+
threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
337+
threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`,
337338
error: {
338339
invalidSplit: 'Split amounts do not equal total amount',
339340
other: 'Unexpected error, please try again later',

src/languages/es.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ export default {
332332
payerSettled: ({amount}) => `pagado ${amount}`,
333333
noReimbursableExpenses: 'El monto de este informe es inválido',
334334
pendingConversionMessage: 'El total se actualizará cuando estés online',
335-
threadReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
335+
threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
336+
threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`,
336337
error: {
337338
invalidSplit: 'La suma de las partes no equivale al monto total',
338339
other: 'Error inesperado, por favor inténtalo más tarde',

src/libs/ReportActionsUtils.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as CollectionUtils from './CollectionUtils';
99
import CONST from '../CONST';
1010
import ONYXKEYS from '../ONYXKEYS';
1111
import Log from './Log';
12+
import * as CurrencyUtils from './CurrencyUtils';
1213
import isReportMessageAttachment from './isReportMessageAttachment';
1314

1415
const allReportActions = {};
@@ -61,16 +62,47 @@ function getParentReportAction(report) {
6162
return lodashGet(allReportActions, [report.parentReportID, report.parentReportActionID], {});
6263
}
6364

65+
/**
66+
* Determines if the given report action is sent money report action by checking for 'pay' type and presence of IOUDetails object.
67+
*
68+
* @param {Object} reportAction
69+
* @returns {Boolean}
70+
*/
71+
function isSentMoneyReportAction(reportAction) {
72+
return (
73+
reportAction &&
74+
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
75+
lodashGet(reportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.PAY &&
76+
_.has(reportAction.originalMessage, 'IOUDetails')
77+
);
78+
}
79+
80+
/**
81+
* Returns the formatted amount of a money request. The request and money sent (from send money flow) have
82+
* currency and amount in IOUDetails object.
83+
*
84+
* @param {Object} reportAction
85+
* @returns {Number}
86+
*/
87+
function getFormattedAmount(reportAction) {
88+
return lodashGet(reportAction, 'originalMessage.type', '') === CONST.IOU.REPORT_ACTION_TYPE.PAY && lodashGet(reportAction, 'originalMessage.IOUDetails', false)
89+
? CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.IOUDetails.amount', 0), lodashGet(reportAction, 'originalMessage.IOUDetails.currency', ''))
90+
: CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.amount', 0), lodashGet(reportAction, 'originalMessage.currency', ''));
91+
}
92+
6493
/**
6594
* Returns whether the thread is a transaction thread, which is any thread with IOU parent
66-
* report action of type create.
95+
* report action from requesting money (type - create) or from sending money (type - pay with IOUDetails field)
6796
*
6897
* @param {Object} parentReportAction
6998
* @returns {Boolean}
7099
*/
71100
function isTransactionThread(parentReportAction) {
101+
const originalMessage = lodashGet(parentReportAction, 'originalMessage', {});
72102
return (
73-
parentReportAction && parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && lodashGet(parentReportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.CREATE
103+
parentReportAction &&
104+
parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
105+
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE || (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage.IOUDetails))
74106
);
75107
}
76108

@@ -371,4 +403,6 @@ export {
371403
isCreatedTaskReportAction,
372404
getParentReportAction,
373405
isTransactionThread,
406+
getFormattedAmount,
407+
isSentMoneyReportAction,
374408
};

src/libs/ReportUtils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,17 +971,17 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport)
971971
*/
972972
function getMoneyRequestAction(reportAction = {}) {
973973
const originalMessage = lodashGet(reportAction, 'originalMessage', {});
974-
let total = originalMessage.amount || 0;
974+
let amount = originalMessage.amount || 0;
975975
let currency = originalMessage.currency || CONST.CURRENCY.USD;
976976
let comment = originalMessage.comment || '';
977977

978978
if (_.has(originalMessage, 'IOUDetails')) {
979-
total = lodashGet(originalMessage, 'IOUDetails.amount', 0);
979+
amount = lodashGet(originalMessage, 'IOUDetails.amount', 0);
980980
currency = lodashGet(originalMessage, 'IOUDetails.currency', CONST.CURRENCY.USD);
981981
comment = lodashGet(originalMessage, 'IOUDetails.comment', '');
982982
}
983983

984-
return {total, currency, comment};
984+
return {amount, currency, comment};
985985
}
986986

987987
/**
@@ -1055,8 +1055,8 @@ function getMoneyRequestReportName(report) {
10551055
* @returns {String}
10561056
*/
10571057
function getTransactionReportName(reportAction) {
1058-
return Localize.translateLocal('iou.threadReportName', {
1059-
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.amount', 0), lodashGet(reportAction, 'originalMessage.currency', '')),
1058+
return Localize.translateLocal(ReportActionsUtils.isSentMoneyReportAction(reportAction) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', {
1059+
formattedAmount: ReportActionsUtils.getFormattedAmount(reportAction),
10601060
comment: lodashGet(reportAction, 'originalMessage.comment'),
10611061
});
10621062
}

src/pages/home/report/ReportActionItem.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,17 @@ class ReportActionItem extends Component {
186186
*/
187187
renderItemContent(hovered = false) {
188188
let children;
189+
const originalMessage = lodashGet(this.props.action, 'originalMessage', {});
190+
// Show the IOUPreview for when request was created, bill was split or money was sent
189191
if (
190192
this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
191-
this.props.action.originalMessage.type !== CONST.IOU.REPORT_ACTION_TYPE.DELETE &&
192-
this.props.action.originalMessage.type !== CONST.IOU.REPORT_ACTION_TYPE.PAY
193+
originalMessage &&
194+
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
195+
originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT ||
196+
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage.IOUDetails))
193197
) {
194198
// There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID
195-
const iouReportID = this.props.action.originalMessage.IOUReportID ? this.props.action.originalMessage.IOUReportID.toString() : '0';
199+
const iouReportID = originalMessage.IOUReportID ? originalMessage.IOUReportID.toString() : '0';
196200

197201
children = (
198202
<MoneyRequestAction

0 commit comments

Comments
 (0)