diff --git a/src/components/ReportActionItem/ReportPreview.js b/src/components/ReportActionItem/ReportPreview.js index 1b913baa25e8..8321fcde825a 100644 --- a/src/components/ReportActionItem/ReportPreview.js +++ b/src/components/ReportActionItem/ReportPreview.js @@ -3,7 +3,6 @@ import {View} from 'react-native'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import lodashGet from 'lodash/get'; -import _ from 'underscore'; import Text from '../Text'; import Icon from '../Icon'; import * as Expensicons from '../Icon/Expensicons'; @@ -16,7 +15,6 @@ import ControlSelection from '../../libs/ControlSelection'; import * as DeviceCapabilities from '../../libs/DeviceCapabilities'; import {showContextMenuForReport} from '../ShowContextMenuContext'; import * as StyleUtils from '../../styles/StyleUtils'; -import * as CurrencyUtils from '../../libs/CurrencyUtils'; import * as ReportUtils from '../../libs/ReportUtils'; import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; @@ -95,45 +93,31 @@ const defaultProps = { }; function ReportPreview(props) { - const reportAmount = CurrencyUtils.convertToDisplayString(ReportUtils.getMoneyRequestTotal(props.iouReport), props.iouReport.currency); const managerEmail = props.iouReport.managerEmail || ''; - const managerName = ReportUtils.isPolicyExpenseChat(props.chatReport) ? ReportUtils.getPolicyName(props.chatReport) : ReportUtils.getDisplayNameForParticipant(managerEmail, true); const isCurrentUserManager = managerEmail === lodashGet(props.session, 'email', null); const bankAccountRoute = ReportUtils.getBankAccountRoute(props.chatReport); + const displayingMessage = ReportUtils.getReportPreviewMessage(props.iouReport, props.action); return ( - {_.map(props.action.message, (message, index) => ( - { - Navigation.navigate(ROUTES.getReportRoute(props.iouReportID)); - }} - onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} - onPressOut={() => ControlSelection.unblock()} - onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)} - style={[styles.flexRow, styles.justifyContentBetween]} - accessibilityRole="button" - accessibilityLabel={props.translate('iou.viewDetails')} - > - - {props.iouReport.hasOutstandingIOU ? ( - - {lodashGet(message, 'html', props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount}))} - - ) : ( - - - {lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))} - - - )} - - - - ))} + { + Navigation.navigate(ROUTES.getReportRoute(props.iouReportID)); + }} + onPressIn={() => DeviceCapabilities.canUseTouchScreen() && ControlSelection.block()} + onPressOut={() => ControlSelection.unblock()} + onLongPress={(event) => showContextMenuForReport(event, props.contextMenuAnchor, props.chatReportID, props.action, props.checkIfContextMenuActive)} + style={[styles.flexRow, styles.justifyContentBetween]} + accessibilityRole="button" + accessibilityLabel={props.translate('iou.viewDetails')} + > + + {displayingMessage} + + + {isCurrentUserManager && !ReportUtils.isSettled(props.iouReport.reportID) && ( `${amount} each`, payerOwesAmount: ({payer, amount}) => `${payer} owes ${amount}`, payerPaidAmount: ({payer, amount}) => `${payer} paid ${amount}`, - payerSettled: ({amount}) => `paid ${amount}`, + settledElsewhereWithAmount: ({amount}) => `paid ${amount} elsewhere`, + settledPaypalMeWithAmount: ({amount}) => `paid ${amount} using Paypal.me`, noReimbursableExpenses: 'This report has an invalid amount', pendingConversionMessage: "Total will update when you're back online", threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`, diff --git a/src/languages/es.js b/src/languages/es.js index 2a8af5628045..1267a59b7043 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -358,7 +358,8 @@ export default { amountEach: ({amount}) => `${amount} cada uno`, payerOwesAmount: ({payer, amount}) => `${payer} debe ${amount}`, payerPaidAmount: ({payer, amount}) => `${payer} pagó ${amount}`, - payerSettled: ({amount}) => `pagó ${amount}`, + settledElsewhereWithAmount: ({amount}) => `pagó ${amount} de otra forma`, + settledPaypalMeWithAmount: ({amount}) => `pagó ${amount} con PayPal.me`, noReimbursableExpenses: 'El monto de este informe es inválido', pendingConversionMessage: 'El total se actualizará cuando estés online', threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`, diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f4f48654e3b7..d33a379a1b94 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -377,9 +377,14 @@ function getAllReportErrors(report, reportActions) { * @returns {String} */ function getLastMessageTextForReport(report) { + const lastReportAction = lastReportActions[report.reportID]; let lastMessageTextFromReport = ''; + if (ReportUtils.isReportMessageAttachment({text: report.lastMessageText, html: report.lastMessageHtml})) { lastMessageTextFromReport = `[${Localize.translateLocal('common.attachment')}]`; + } else if (ReportActionUtils.isReportPreviewAction(lastReportAction)) { + const iouReport = ReportUtils.getReport(ReportActionUtils.getIOUReportIDFromReportActionPreview(lastReportAction)); + lastMessageTextFromReport = ReportUtils.getReportPreviewMessage(iouReport, lastReportAction); } else { lastMessageTextFromReport = report ? report.lastMessageText || '' : ''; diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index 5c9b62ca47d9..dc8ad305fee0 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -56,6 +56,14 @@ function isMoneyRequestAction(reportAction) { return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.IOU; } +/** + * @param {Object} reportAction + * @returns {Boolean} + */ +function isReportPreviewAction(reportAction) { + return lodashGet(reportAction, 'actionName', '') === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW; +} + /** * @param {Object} reportAction * @returns {Boolean} @@ -421,6 +429,16 @@ function getReportPreviewAction(chatReportID, iouReportID) { ); } +/** + * Get the iouReportID for a given report action. + * + * @param {Object} reportAction + * @returns {String} + */ +function getIOUReportIDFromReportActionPreview(reportAction) { + return lodashGet(reportAction, 'originalMessage.linkedReportID', ''); +} + function isCreatedTaskReportAction(reportAction) { return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID'); } @@ -461,6 +479,8 @@ export { isTransactionThread, getFormattedAmount, isSentMoneyReportAction, + isReportPreviewAction, + getIOUReportIDFromReportActionPreview, isMessageDeleted, isWhisperAction, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 3a03903b0cf8..e768c42a5eb7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -987,6 +987,35 @@ function getTransactionReportName(reportAction) { }); } +/** + * Get money request message for an IOU report + * + * @param {Object} report + * @param {Object} reportAction + * @returns {String} + */ +function getReportPreviewMessage(report, reportAction) { + const reportActionMessage = lodashGet(reportAction, 'message[0].html', ''); + + if (_.isEmpty(report) || !report.reportID) { + // The iouReport is not found locally after SignIn because the OpenApp API won't return iouReports if they're settled + // As a temporary solution until we know how to solve this the best, we just use the message that returned from BE + return reportActionMessage; + } + + const totalAmount = getMoneyRequestTotal(report); + const payerName = isExpenseReport(report) ? getPolicyName(report) : getDisplayNameForParticipant(report.managerID, true); + const formattedAmount = CurrencyUtils.convertToDisplayString(totalAmount, report.currency); + + if (isSettled(report.reportID)) { + // A settled message is in the format of either "paid $1.00 elsewhere" or "paid $1.00 using Paypal.me" + const isSettledPaypalMe = Boolean(reportActionMessage.match(/ Paypal.me$/)); + const translatePhraseKey = isSettledPaypalMe ? 'iou.settledPaypalMeWithAmount' : 'iou.settledElsewhereWithAmount'; + return Localize.translateLocal(translatePhraseKey, {amount: formattedAmount}); + } + return Localize.translateLocal('iou.payerOwesAmount', {payer: payerName, amount: formattedAmount}); +} + /** * Get the title for a report. * @@ -2371,6 +2400,7 @@ export { getMoneyRequestAction, getBankAccountRoute, getParentReport, + getReportPreviewMessage, shouldHideComposer, getOriginalReportID, }; diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 24be64dc6468..dbe48eb532dd 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -248,7 +248,7 @@ function ReportActionItem(props) { } else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) { children = (