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

Show IOU preview for send money flow #18981

Merged
merged 14 commits into from
May 17, 2023
Merged
2 changes: 1 addition & 1 deletion src/components/ReportActionItem/IOUPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const IOUPreview = (props) => {
const moneyRequestAction = ReportUtils.getMoneyRequestAction(props.action);

// If props.action is undefined then we are displaying within IOUDetailsModal and should use the full report amount
const requestAmount = props.isIOUAction ? moneyRequestAction.total : ReportUtils.getMoneyRequestTotal(props.iouReport);
const requestAmount = props.isIOUAction ? moneyRequestAction.amount : ReportUtils.getMoneyRequestTotal(props.iouReport);
const requestCurrency = props.isIOUAction ? moneyRequestAction.currency : props.iouReport.currency;
const requestComment = Str.htmlDecode(moneyRequestAction.comment).trim();
mountiny marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
13 changes: 9 additions & 4 deletions src/components/ReportActionItem/MoneyRequestAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as OptionsListUtils from '../../libs/OptionsListUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import * as Report from '../../libs/actions/Report';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import * as CurrencyUtils from '../../libs/CurrencyUtils';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';

const propTypes = {
/** All the data of the action */
Expand Down Expand Up @@ -100,8 +100,8 @@ const MoneyRequestAction = (props) => {
const formattedUserLogins = _.map(participants, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase());
const thread = ReportUtils.buildOptimisticChatReport(
formattedUserLogins,
props.translate('iou.threadReportName', {
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(props.action, 'originalMessage.amount', 0), lodashGet(props.action, 'originalMessage.currency', '')),
props.translate(ReportActionsUtils.isSentMoneyReportAction(props.action) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', {
formattedAmount: ReportActionsUtils.getFormattedAmount(props.action),
comment: props.action.originalMessage.comment,
}),
'',
Expand All @@ -123,6 +123,11 @@ const MoneyRequestAction = (props) => {
}
};

const onReportPreviewPressed = () => {
Report.openReport(props.requestReportID);
Navigation.navigate(ROUTES.getReportRoute(props.requestReportID));
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The report preview components is not fully used but I think it should have its own callback to make to separate the concerns


let shouldShowPendingConversionMessage = false;
if (
!_.isEmpty(props.iouReport) &&
Expand Down Expand Up @@ -155,7 +160,7 @@ const MoneyRequestAction = (props) => {
chatReportID={props.chatReportID}
iouReportID={props.requestReportID}
contextMenuAnchor={props.contextMenuAnchor}
onViewDetailsPressed={onIOUPreviewPressed}
onViewDetailsPressed={onReportPreviewPressed}
checkIfContextMenuActive={props.checkIfContextMenuActive}
isHovered={props.isHovered}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ export default {
payerSettled: ({amount}) => `settled up ${amount}`,
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
threadReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
threadRequestReportName: ({formattedAmount, comment}) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} sent${comment ? ` for ${comment}` : ''}`,
error: {
invalidSplit: 'Split amounts do not equal total amount',
other: 'Unexpected error, please try again later',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ export default {
payerSettled: ({amount}) => `pagado ${amount}`,
noReimbursableExpenses: 'El monto de este informe es inválido',
pendingConversionMessage: 'El total se actualizará cuando estés online',
threadReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
threadRequestReportName: ({formattedAmount, comment}) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
threadSentMoneyReportName: ({formattedAmount, comment}) => `${formattedAmount} enviado${comment ? ` para ${comment}` : ''}`,
error: {
invalidSplit: 'La suma de las partes no equivale al monto total',
other: 'Error inesperado, por favor inténtalo más tarde',
Expand Down
38 changes: 36 additions & 2 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as CollectionUtils from './CollectionUtils';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';
import Log from './Log';
import * as CurrencyUtils from './CurrencyUtils';
import isReportMessageAttachment from './isReportMessageAttachment';

const allReportActions = {};
Expand Down Expand Up @@ -61,16 +62,47 @@ function getParentReportAction(report) {
return lodashGet(allReportActions, [report.parentReportID, report.parentReportActionID], {});
}

/**
* Determines if the given report action is sent money report action by checking for 'pay' type and presence of IOUDetails object.
*
* @param {Object} reportAction
* @returns {Boolean}
*/
function isSentMoneyReportAction(reportAction) {
return (
reportAction &&
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
lodashGet(reportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.PAY &&
_.has(reportAction.originalMessage, 'IOUDetails')
);
}

/**
* Returns the formatted amount of a money request. The request and money sent (from send money flow) have
* currency and amount in IOUDetails object.
*
* @param {Object} reportAction
* @returns {Number}
*/
function getFormattedAmount(reportAction) {
return lodashGet(reportAction, 'originalMessage.type', '') === CONST.IOU.REPORT_ACTION_TYPE.PAY && lodashGet(reportAction, 'originalMessage.IOUDetails', false)
? CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.IOUDetails.amount', 0), lodashGet(reportAction, 'originalMessage.IOUDetails.currency', ''))
: CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.amount', 0), lodashGet(reportAction, 'originalMessage.currency', ''));
}

/**
* Returns whether the thread is a transaction thread, which is any thread with IOU parent
* report action of type create.
* report action from requesting money (type - create) or from sending money (type - pay with IOUDetails field)
*
* @param {Object} parentReportAction
* @returns {Boolean}
*/
function isTransactionThread(parentReportAction) {
const originalMessage = lodashGet(parentReportAction, 'originalMessage', {});
return (
parentReportAction && parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && lodashGet(parentReportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.CREATE
parentReportAction &&
parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE || (originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage.IOUDetails))
);
}

Expand Down Expand Up @@ -354,4 +386,6 @@ export {
isCreatedTaskReportAction,
getParentReportAction,
isTransactionThread,
getFormattedAmount,
isSentMoneyReportAction,
};
10 changes: 5 additions & 5 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,17 +971,17 @@ function getDisplayNamesWithTooltips(participants, isMultipleParticipantReport)
*/
function getMoneyRequestAction(reportAction = {}) {
const originalMessage = lodashGet(reportAction, 'originalMessage', {});
let total = originalMessage.amount || 0;
let amount = originalMessage.amount || 0;
let currency = originalMessage.currency || CONST.CURRENCY.USD;
let comment = originalMessage.comment || '';

if (_.has(originalMessage, 'IOUDetails')) {
total = lodashGet(originalMessage, 'IOUDetails.amount', 0);
amount = lodashGet(originalMessage, 'IOUDetails.amount', 0);
currency = lodashGet(originalMessage, 'IOUDetails.currency', CONST.CURRENCY.USD);
comment = lodashGet(originalMessage, 'IOUDetails.comment', '');
}

return {total, currency, comment};
return {amount, currency, comment};
}

/**
Expand Down Expand Up @@ -1055,8 +1055,8 @@ function getMoneyRequestReportName(report) {
* @returns {String}
*/
function getTransactionReportName(reportAction) {
return Localize.translateLocal('iou.threadReportName', {
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(reportAction, 'originalMessage.amount', 0), lodashGet(reportAction, 'originalMessage.currency', '')),
return Localize.translateLocal(ReportActionsUtils.isSentMoneyReportAction(reportAction) ? 'iou.threadSentMoneyReportName' : 'iou.threadRequestReportName', {
formattedAmount: ReportActionsUtils.getFormattedAmount(reportAction),
comment: lodashGet(reportAction, 'originalMessage.comment'),
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,17 @@ class ReportActionItem extends Component {
*/
renderItemContent(hovered = false) {
let children;
const originalMessage = lodashGet(this.props.action, 'originalMessage', {});
// Show the IOUPreview for when request was created, bill was split or money was sent
if (
this.props.action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU &&
this.props.action.originalMessage.type !== CONST.IOU.REPORT_ACTION_TYPE.DELETE &&
this.props.action.originalMessage.type !== CONST.IOU.REPORT_ACTION_TYPE.PAY
originalMessage &&
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.CREATE ||
originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT ||
(originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY && originalMessage.IOUDetails))
Comment on lines +194 to +196
Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to suggest array.includes(originalMessage.type), but it seems a bit complex due to the iOUDetails condition, and needing to ensure type isn't null

) {
// There is no single iouReport for bill splits, so only 1:1 requests require an iouReportID
const iouReportID = this.props.action.originalMessage.IOUReportID ? this.props.action.originalMessage.IOUReportID.toString() : '0';
const iouReportID = originalMessage.IOUReportID ? originalMessage.IOUReportID.toString() : '0';

children = (
<MoneyRequestAction
Expand Down