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

Display displayName instead of primaryLogin on the ReportPreview message #20446

Merged
merged 34 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d2c07a2
Display displayName instead of primaryLogin in report preview
hoangzinh Jun 8, 2023
5e1b4c7
Show report preview action in LHN
hoangzinh Jun 8, 2023
4338186
Refactor code using existing util to display money request message
hoangzinh Jun 8, 2023
b58a8f8
Fix linter
hoangzinh Jun 8, 2023
3b8bb48
Fix linter
hoangzinh Jun 8, 2023
3788f8f
Merge branch 'main' into df/19301
hoangzinh Jun 14, 2023
9171962
Add a new utils to get money request message
hoangzinh Jun 14, 2023
0da6a76
remove redundant export
hoangzinh Jun 14, 2023
644d71f
Fix settled message is 0 amount in LHN
hoangzinh Jun 14, 2023
d58e95c
Merge branch 'main' into df/19301
hoangzinh Jun 14, 2023
1e1e34d
Fix amount is 0 after sign in
hoangzinh Jun 14, 2023
e329173
Fix linter
hoangzinh Jun 14, 2023
caa45ea
Fix checking isHavingOustandingIOU
hoangzinh Jun 15, 2023
b57b897
Correct the method name
hoangzinh Jun 15, 2023
9009632
Refactor as feedbacks
hoangzinh Jun 15, 2023
f4e1390
Update variable name
hoangzinh Jun 15, 2023
bad0519
Merge branch 'main' into df/19301
hoangzinh Jun 15, 2023
5bd7268
Correct typo
hoangzinh Jun 16, 2023
0320938
Merge branch 'main' into df/19301
hoangzinh Jun 21, 2023
20b7a1a
Show report review action message in LHN
hoangzinh Jun 21, 2023
e59d39f
Remove map action.message
hoangzinh Jun 21, 2023
d1c6412
Rename method to scope it only for reportAction preview
hoangzinh Jun 21, 2023
117c9f0
Fix eslint
hoangzinh Jun 21, 2023
a5d0633
Fix get payerName
hoangzinh Jun 21, 2023
e018913
Use last visible action instead of last action
hoangzinh Jun 21, 2023
8942536
Remove redundant empty line
hoangzinh Jun 21, 2023
ba57e73
Revert back to lastReportAction because new reportActionView is optim…
hoangzinh Jun 21, 2023
8142f02
If iouReport is not found locally then use BE message other parse BE …
hoangzinh Jun 25, 2023
d1e4aae
Use report action message instead report last message text
hoangzinh Jun 25, 2023
638fe01
Merge branch 'main' into df/19301
hoangzinh Jun 25, 2023
c9a25e5
Fix translate settled message to ES
hoangzinh Jun 26, 2023
0fc3ed0
Merge branch 'main' into df/19301
hoangzinh Jun 26, 2023
331cc43
Rename method to avoid confusing
hoangzinh Jun 26, 2023
0f106df
Merge branch 'main' into df/19301
hoangzinh Jun 28, 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
56 changes: 20 additions & 36 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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 (
<View style={[styles.chatItemMessage]}>
{_.map(props.action.message, (message, index) => (
<PressableWithoutFeedback
key={`ReportPreview-${props.action.reportActionID}-${index}`}
onPress={() => {
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')}
>
<View style={[styles.flexShrink1]}>
{props.iouReport.hasOutstandingIOU ? (
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>
{lodashGet(message, 'html', props.translate('iou.payerOwesAmount', {payer: managerName, amount: reportAmount}))}
</Text>
) : (
<View style={[styles.flexRow]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>
{lodashGet(message, 'html', props.translate('iou.payerSettled', {amount: reportAmount}))}
</Text>
</View>
)}
</View>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
/>
</PressableWithoutFeedback>
))}
<PressableWithoutFeedback
onPress={() => {
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')}
>
<View style={[styles.flexShrink1]}>
<Text style={[styles.chatItemMessage, styles.cursorPointer, styles.colorMuted]}>{displayingMessage}</Text>
</View>
<Icon
src={Expensicons.ArrowRight}
fill={StyleUtils.getIconFillColor(getButtonState(props.isHovered))}
/>
</PressableWithoutFeedback>
{isCurrentUserManager && !ReportUtils.isSettled(props.iouReport.reportID) && (
<SettlementButton
currency={props.iouReport.currency}
Expand Down
3 changes: 2 additions & 1 deletion src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ export default {
amountEach: ({amount}) => `${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}` : ''}`,
Expand Down
3 changes: 2 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}` : ''}`,
Expand Down
5 changes: 5 additions & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '' : '';

Expand Down
20 changes: 20 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @param {Object} reportAction
* @returns {Boolean}
Expand Down Expand Up @@ -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', '');
hoangzinh marked this conversation as resolved.
Show resolved Hide resolved
}

function isCreatedTaskReportAction(reportAction) {
return reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && _.has(reportAction.originalMessage, 'taskReportID');
}
Expand Down Expand Up @@ -461,6 +479,8 @@ export {
isTransactionThread,
getFormattedAmount,
isSentMoneyReportAction,
isReportPreviewAction,
getIOUReportIDFromReportActionPreview,
isMessageDeleted,
isWhisperAction,
};
30 changes: 30 additions & 0 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -2361,5 +2390,6 @@ export {
getMoneyRequestAction,
getBankAccountRoute,
getParentReport,
getReportPreviewMessage,
getOriginalReportID,
};
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function ReportActionItem(props) {
} else if (props.action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORTPREVIEW) {
children = (
<ReportPreview
iouReportID={props.action.originalMessage.linkedReportID}
iouReportID={ReportActionsUtils.getIOUReportIDFromReportActionPreview(props.action)}
chatReportID={props.report.reportID}
action={props.action}
isHovered={hovered}
Expand Down