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

Fix Copying Sent Money Report Action text copies a wrong text #27889

41 changes: 41 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3592,6 +3592,46 @@ function getReportPreviewDisplayTransactions(reportPreviewAction) {
);
}

/**
* Return iou report action display message
*
* @param {Object} reportAction report action
* @returns {String}
*/
function getIouReportActionDisplayMessage(reportAction) {
rayane-djouah marked this conversation as resolved.
Show resolved Hide resolved
const originalMessage = _.get(reportAction, 'originalMessage', {});
let displayMessage;
if (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
rayane-djouah marked this conversation as resolved.
Show resolved Hide resolved
const {amount, currency, IOUReportID} = originalMessage;
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #29441

The REPORT_ACTION_TYPE.PAY action type is used for both fulfilling existing requests and sending money. To differentiate between these two scenarios, we should have checked if the originalMessage contains the IOUDetails property. If it does, it indicates that this is a 'Send money' action.

const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency);
const iouReport = getReport(IOUReportID);
const payerName = isExpenseReport(iouReport) ? getPolicyName(iouReport) : getDisplayNameForParticipant(iouReport.managerID);
let translationKey;
switch (originalMessage.paymentType) {
case CONST.IOU.PAYMENT_TYPE.ELSEWHERE:
translationKey = 'iou.paidElsewhereWithAmount';
break;
case CONST.IOU.PAYMENT_TYPE.EXPENSIFY:
case CONST.IOU.PAYMENT_TYPE.VBBA:
translationKey = 'iou.paidUsingExpensifyWithAmount';
break;
default:
translationKey = '';
break;
}
displayMessage = Localize.translateLocal(translationKey, {amount: formattedAmount, payer: payerName});
} else {
const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID);
rayane-djouah marked this conversation as resolved.
Show resolved Hide resolved
const {amount, currency, comment} = getTransactionDetails(transaction);
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency);
displayMessage = Localize.translateLocal('iou.requestedAmount', {
rayane-djouah marked this conversation as resolved.
Show resolved Hide resolved
formattedAmount,
comment,
});
}
return displayMessage;
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand Down Expand Up @@ -3733,4 +3773,5 @@ export {
getReportPreviewDisplayTransactions,
getTransactionsWithReceipts,
hasMissingSmartscanFields,
getIouReportActionDisplayMessage,
};
14 changes: 2 additions & 12 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickE
import Navigation from '../../../../libs/Navigation/Navigation';
import ROUTES from '../../../../ROUTES';
import * as Task from '../../../../libs/actions/Task';
import * as Localize from '../../../../libs/Localize';
import * as TransactionUtils from '../../../../libs/TransactionUtils';
import * as CurrencyUtils from '../../../../libs/CurrencyUtils';

/**
* Gets the HTML version of the message in an action.
Expand Down Expand Up @@ -203,15 +200,8 @@ export default [
const modifyExpenseMessage = ReportUtils.getModifiedExpenseMessage(reportAction);
Clipboard.setString(modifyExpenseMessage);
} else if (ReportActionsUtils.isMoneyRequestAction(reportAction)) {
const originalMessage = _.get(reportAction, 'originalMessage', {});
const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID);
const {amount, currency, comment} = ReportUtils.getTransactionDetails(transaction);
const formattedAmount = CurrencyUtils.convertToDisplayString(amount, currency);
const displaymessage = Localize.translateLocal('iou.requestedAmount', {
formattedAmount,
comment,
});
Clipboard.setString(displaymessage);
const displayMessage = ReportUtils.getIouReportActionDisplayMessage(reportAction);
rayane-djouah marked this conversation as resolved.
Show resolved Hide resolved
Clipboard.setString(displayMessage);
} else if (content) {
const parser = new ExpensiMark();
if (!Clipboard.canSetHtml()) {
Expand Down
Loading