Skip to content

Commit

Permalink
Merge pull request #30232 from Tony-MK/fix/issue-29899
Browse files Browse the repository at this point in the history
Fix/issue 29899
  • Loading branch information
arosiclair authored Nov 7, 2023
2 parents ea55e63 + 62fc922 commit cbfd424
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,8 @@ const CONST = {

SPECIAL_CHAR: /[,/?"{}[\]()&^%;`$=#<>!*]/g,

FIRST_SPACE: /.+?(?=\s)/,

get SPECIAL_CHAR_OR_EMOJI() {
return new RegExp(`[~\\n\\s]|(_\\b(?!$))|${this.SPECIAL_CHAR.source}|${this.EMOJI.source}`, 'gu');
},
Expand Down
8 changes: 6 additions & 2 deletions src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ function MoneyRequestPreview(props) {

const receiptImages = hasReceipt ? [ReceiptUtils.getThumbnailAndImageURIs(props.transaction)] : [];

const hasPendingWaypoints = lodashGet(props.transaction, 'pendingFields.waypoints', null);

const getSettledMessage = () => {
if (isExpensifyCardTransaction) {
return props.translate('common.done');
Expand Down Expand Up @@ -223,7 +225,7 @@ function MoneyRequestPreview(props) {

const getDisplayAmountText = () => {
if (isDistanceRequest) {
return requestAmount ? CurrencyUtils.convertToDisplayString(requestAmount, props.transaction.currency) : props.translate('common.tbd');
return requestAmount && !hasPendingWaypoints ? CurrencyUtils.convertToDisplayString(requestAmount, props.transaction.currency) : props.translate('common.tbd');
}

if (isScanning) {
Expand Down Expand Up @@ -319,7 +321,9 @@ function MoneyRequestPreview(props) {
</View>
{shouldShowMerchant && (
<View style={[styles.flexRow]}>
<Text style={[styles.textLabelSupporting, styles.mb1, styles.lh20, styles.breakWord]}>{requestMerchant}</Text>
<Text style={[styles.textLabelSupporting, styles.mb1, styles.lh20, styles.breakWord]}>
{hasPendingWaypoints ? requestMerchant.replace(CONST.REGEX.FIRST_SPACE, props.translate('common.tbd')) : requestMerchant}
</Text>
</View>
)}
<View style={[styles.flexRow, styles.mt1]}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/MoneyRequestView.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should
transactionMerchant === '' || transactionMerchant === CONST.TRANSACTION.UNKNOWN_MERCHANT || transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
const isDistanceRequest = TransactionUtils.isDistanceRequest(transaction);
let formattedTransactionAmount = transactionAmount ? CurrencyUtils.convertToDisplayString(transactionAmount, transactionCurrency) : '';
if (isDistanceRequest && !formattedTransactionAmount) {
const hasPendingWaypoints = lodashGet(transaction, 'pendingFields.waypoints', null);
if (isDistanceRequest && (!formattedTransactionAmount || hasPendingWaypoints)) {
formattedTransactionAmount = translate('common.tbd');
}
const formattedOriginalAmount = transactionOriginalAmount && transactionOriginalCurrency && CurrencyUtils.convertToDisplayString(transactionOriginalAmount, transactionOriginalCurrency);
Expand Down Expand Up @@ -206,7 +207,7 @@ function MoneyRequestView({report, betas, parentReport, policyCategories, should
<OfflineWithFeedback pendingAction={lodashGet(transaction, 'pendingFields.waypoints') || lodashGet(transaction, 'pendingAction')}>
<MenuItemWithTopDescription
description={translate('common.distance')}
title={transactionMerchant}
title={hasPendingWaypoints ? transactionMerchant.replace(CONST.REGEX.FIRST_SPACE, translate('common.tbd')) : transactionMerchant}
interactive={canEdit && !isSettled}
shouldShowRightIcon={canEdit && !isSettled}
titleStyle={styles.flex1}
Expand Down
21 changes: 14 additions & 7 deletions src/components/ReportActionItem/ReportPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,24 @@ function ReportPreview(props) {
const lastThreeTransactionsWithReceipts = transactionsWithReceipts.slice(-3);
const lastThreeReceipts = _.map(lastThreeTransactionsWithReceipts, (transaction) => ReceiptUtils.getThumbnailAndImageURIs(transaction));
const hasNonReimbursableTransactions = ReportUtils.hasNonReimbursableTransactions(props.iouReportID);
const hasOnlyOneReceiptRequest = numberOfRequests === 1 && hasReceipts;
const previewSubtitle = hasOnlyOneReceiptRequest
? TransactionUtils.getMerchant(transactionsWithReceipts[0])
: props.translate('iou.requestCount', {
count: numberOfRequests,
scanningReceipts: numberOfScanningReceipts,
});
let formattedMerchant = numberOfRequests === 1 && hasReceipts ? TransactionUtils.getMerchant(transactionsWithReceipts[0]) : null;
const hasPendingWaypoints = formattedMerchant && hasOnlyDistanceRequests && _.every(transactionsWithReceipts, (transaction) => lodashGet(transaction, 'pendingFields.waypoints', null));
if (hasPendingWaypoints) {
formattedMerchant = formattedMerchant.replace(CONST.REGEX.FIRST_SPACE, props.translate('common.tbd'));
}
const previewSubtitle =
formattedMerchant ||
props.translate('iou.requestCount', {
count: numberOfRequests,
scanningReceipts: numberOfScanningReceipts,
});

const shouldShowSubmitButton = isReportDraft && reimbursableSpend !== 0;

const getDisplayAmount = () => {
if (hasPendingWaypoints) {
return props.translate('common.tbd');
}
if (totalDisplaySpend) {
return CurrencyUtils.convertToDisplayString(totalDisplaySpend, props.iouReport.currency);
}
Expand Down
20 changes: 11 additions & 9 deletions src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string

const hasEReceipt = transaction?.hasEReceipt;

if (hasEReceipt) {
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction};
}
if (!Object.hasOwn(transaction?.pendingFields ?? {}, 'waypoints')) {
if (hasEReceipt) {
return {thumbnail: null, image: ROUTES.ERECEIPT.getRoute(transaction.transactionID), transaction};
}

// For local files, we won't have a thumbnail yet
if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) {
return {thumbnail: null, image: path};
}
// For local files, we won't have a thumbnail yet
if (isReceiptImage && (path.startsWith('blob:') || path.startsWith('file:'))) {
return {thumbnail: null, image: path};
}

if (isReceiptImage) {
return {thumbnail: `${path}.1024.jpg`, image: path};
if (isReceiptImage) {
return {thumbnail: `${path}.1024.jpg`, image: path};
}
}

const {fileExtension} = FileUtils.splitExtensionFromFileName(filename) as FileNameAndExtension;
Expand Down

0 comments on commit cbfd424

Please sign in to comment.