Skip to content

Commit

Permalink
Merge pull request #31043 from dukenv0307/fix/29733
Browse files Browse the repository at this point in the history
RBR should appear in LHN on failed split receipt scans
  • Loading branch information
youssef-lr authored Dec 7, 2023
2 parents b7d36c1 + e4e5b8f commit d3ea6ea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/components/ReportActionItem/MoneyRequestPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useThemeStyles from '@styles/useThemeStyles';
import * as PaymentMethods from '@userActions/PaymentMethods';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
import * as Localize from '@src/libs/Localize';
import ONYXKEYS from '@src/ONYXKEYS';
import ReportActionItemImages from './ReportActionItemImages';

Expand Down Expand Up @@ -234,6 +235,10 @@ function MoneyRequestPreview(props) {
return props.translate('iou.receiptScanning');
}

if (TransactionUtils.hasMissingSmartscanFields(props.transaction)) {
return Localize.translateLocal('iou.receiptMissingDetails');
}

return CurrencyUtils.convertToDisplayString(requestAmount, requestCurrency);
};

Expand Down
2 changes: 2 additions & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ function getAllReportErrors(report, reportActions) {
if (ReportUtils.hasMissingSmartscanFields(report.reportID) && !ReportUtils.isSettled(report.reportID)) {
_.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')});
}
} else if (ReportUtils.hasSmartscanError(_.values(reportActions))) {
_.extend(reportActionErrors, {smartscan: ErrorUtils.getMicroSecondOnyxError('report.genericSmartscanFailureMessage')});
}

// All error objects related to the report. Each object in the sources contains error messages keyed by microtime
Expand Down
46 changes: 40 additions & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,19 @@ Onyx.connect({
},
});

let allTransactions: OnyxCollection<Transaction> = {};

Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
return;
}
allTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => transaction));
},
});

function getPolicyTags(policyID: string) {
return allPolicyTags[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
}
Expand Down Expand Up @@ -898,8 +911,8 @@ function hasSingleParticipant(report: OnyxEntry<Report>): boolean {
*
*/
function hasOnlyDistanceRequestTransactions(iouReportID: string | undefined): boolean {
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
return allTransactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction));
const transactions = TransactionUtils.getAllReportTransactions(iouReportID);
return transactions.every((transaction) => TransactionUtils.isDistanceRequest(transaction));
}

/**
Expand Down Expand Up @@ -1588,8 +1601,8 @@ function requiresAttentionFromCurrentUser(option: OnyxEntry<Report> | OptionData
*
*/
function hasNonReimbursableTransactions(iouReportID: string | undefined): boolean {
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
return allTransactions.filter((transaction) => transaction.reimbursable === false).length > 0;
const transactions = TransactionUtils.getAllReportTransactions(iouReportID);
return transactions.filter((transaction) => transaction.reimbursable === false).length > 0;
}

function getMoneyRequestReimbursableTotal(report: OnyxEntry<Report>, allReportsDict: OnyxCollection<Report> = null): number {
Expand Down Expand Up @@ -1841,8 +1854,8 @@ function canEditReportAction(reportAction: OnyxEntry<ReportAction>): boolean {
* Gets all transactions on an IOU report with a receipt
*/
function getTransactionsWithReceipts(iouReportID: string | undefined): Transaction[] {
const allTransactions = TransactionUtils.getAllReportTransactions(iouReportID);
return allTransactions.filter((transaction) => TransactionUtils.hasReceipt(transaction));
const transactions = TransactionUtils.getAllReportTransactions(iouReportID);
return transactions.filter((transaction) => TransactionUtils.hasReceipt(transaction));
}

/**
Expand Down Expand Up @@ -1934,6 +1947,10 @@ function getReportPreviewMessage(
return Localize.translateLocal('iou.receiptScanning');
}

if (TransactionUtils.hasMissingSmartscanFields(linkedTransaction)) {
return Localize.translateLocal('iou.receiptMissingDetails');
}

const transactionDetails = getTransactionDetails(linkedTransaction);
const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency ?? '');
return Localize.translateLocal('iou.didSplitAmount', {formattedAmount, comment: transactionDetails?.comment ?? ''});
Expand Down Expand Up @@ -4251,6 +4268,22 @@ function getRoom(type: ValueOf<typeof CONST.REPORT.CHAT_TYPE>, policyID: string)
function shouldDisableWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy);
}
/**
* Checks if report action has error when smart scanning
*/
function hasSmartscanError(reportActions: ReportAction[]) {
return reportActions.some((action) => {
if (!ReportActionsUtils.isSplitBillAction(action) && !ReportActionsUtils.isReportPreviewAction(action)) {
return false;
}
const isReportPreviewError = ReportActionsUtils.isReportPreviewAction(action) && hasMissingSmartscanFields(ReportActionsUtils.getIOUReportIDFromReportActionPreview(action));
const transactionID = (action.originalMessage as IOUMessage).IOUTransactionID ?? '0';
const transaction = allTransactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? {};
const isSplitBillError = ReportActionsUtils.isSplitBillAction(action) && TransactionUtils.hasMissingSmartscanFields(transaction as Transaction);

return isReportPreviewError || isSplitBillError;
});
}

function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean {
if (event.key.length > 1) {
Expand Down Expand Up @@ -4451,6 +4484,7 @@ export {
shouldDisableWelcomeMessage,
navigateToPrivateNotes,
canEditWriteCapability,
hasSmartscanError,
shouldAutoFocusOnKeyPress,
};

Expand Down

0 comments on commit d3ea6ea

Please sign in to comment.