Skip to content

Commit

Permalink
Merge pull request #47094 from bernhardoj/fix/46791-receipt-verified-…
Browse files Browse the repository at this point in the history
…shown-even-when-there-is-issue
  • Loading branch information
cead22 authored Aug 10, 2024
2 parents 6be470f + 30db77c commit e6546d6
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ type MoneyRequestViewPropsWithoutTransaction = MoneyRequestViewOnyxPropsWithoutT

type MoneyRequestViewProps = MoneyRequestViewTransactionOnyxProps & MoneyRequestViewPropsWithoutTransaction;

const receiptImageViolationNames: OnyxTypes.ViolationName[] = [
CONST.VIOLATIONS.RECEIPT_REQUIRED,
CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED,
CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT,
CONST.VIOLATIONS.SMARTSCAN_FAILED,
];

const receiptFieldViolationNames: OnyxTypes.ViolationName[] = [CONST.VIOLATIONS.MODIFIED_AMOUNT, CONST.VIOLATIONS.MODIFIED_DATE];

const deleteTransaction = (parentReport: OnyxEntry<OnyxTypes.Report>, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>) => {
if (!parentReportAction) {
return;
Expand Down Expand Up @@ -374,14 +383,24 @@ function MoneyRequestView({
const isReceiptAllowed = !isPaidReport && !isInvoice;
const shouldShowReceiptEmptyState =
isReceiptAllowed && !hasReceipt && !isApproved && !isSettled && (canEditReceipt || isAdmin || isApprover) && (canEditReceipt || ReportUtils.isPaidGroupPolicy(report));
const receiptViolationNames: OnyxTypes.ViolationName[] = [
CONST.VIOLATIONS.RECEIPT_REQUIRED,
CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED,
CONST.VIOLATIONS.CASH_EXPENSE_WITH_NO_RECEIPT,
CONST.VIOLATIONS.SMARTSCAN_FAILED,
];
const receiptViolations =
transactionViolations?.filter((violation) => receiptViolationNames.includes(violation.name)).map((violation) => ViolationsUtils.getViolationTranslation(violation, translate)) ?? [];

const [receiptImageViolations, receiptViolations] = useMemo(() => {
const imageViolations = [];
const allViolations = [];

for (const violation of transactionViolations ?? []) {
const isReceiptFieldViolation = receiptFieldViolationNames.includes(violation.name);
const isReceiptImageViolation = receiptImageViolationNames.includes(violation.name);
if (isReceiptFieldViolation || isReceiptImageViolation) {
const violationMessage = ViolationsUtils.getViolationTranslation(violation, translate);
allViolations.push(violationMessage);
if (isReceiptImageViolation) {
imageViolations.push(violationMessage);
}
}
}
return [imageViolations, allViolations];
}, [transactionViolations, translate]);

// Whether to show receipt audit result (e.g.`Verified`, `Issue Found`) and messages (e.g. `Receipt not verified. Please confirm accuracy.`)
// `!!(receiptViolations.length || didReceiptScanSucceed)` is for not showing `Verified` when `receiptViolations` is empty and `didReceiptScanSucceed` is false.
Expand Down Expand Up @@ -498,7 +517,7 @@ function MoneyRequestView({
/>
)}
{!shouldShowReceiptEmptyState && !hasReceipt && <View style={{marginVertical: 6}} />}
{shouldShowAuditMessage && <ReceiptAuditMessages notes={receiptViolations} />}
{shouldShowAuditMessage && <ReceiptAuditMessages notes={receiptImageViolations} />}
<OfflineWithFeedback pendingAction={getPendingFieldAction('amount')}>
<MenuItemWithTopDescription
title={amountTitle}
Expand Down

0 comments on commit e6546d6

Please sign in to comment.