-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix: [Violations] Distance - Incorrect error message when distance amount is changed to smaller amount. #41649
Changes from 38 commits
2f4d561
bac54f1
d399453
c7ec1df
34d5e2e
0549056
ef8e655
f039038
be4f9be
c9fd9aa
b801997
4240c2f
1043d16
3c71e67
12f0433
407e552
7611122
4ebb250
03a9345
d693489
245d667
efd639c
4e8f365
9e452c4
49954fb
d671670
e2851c4
7ae2d6b
e5420c1
7c38e5c
1595f33
2589ba6
6e63f57
9fec7f9
4fe1913
68ebaa7
2a76377
c5d5a3c
995eaed
e3b692e
0a92c99
1c4d2a1
7cdc36c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import MenuItem from '@components/MenuItem'; | |
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; | ||
import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
import {useSession} from '@components/OnyxProvider'; | ||
import {ReceiptAuditHeader, ReceiptAuditMessages} from '@components/ReceiptAudit'; | ||
import ReceiptAudit, {ReceiptAuditMessages} from '@components/ReceiptAudit'; | ||
import ReceiptEmptyState from '@components/ReceiptEmptyState'; | ||
import Switch from '@components/Switch'; | ||
import Text from '@components/Text'; | ||
|
@@ -189,7 +189,7 @@ function MoneyRequestView({ | |
const tripID = ReportUtils.getTripIDFromTransactionParentReport(parentReport); | ||
const shouldShowViewTripDetails = TransactionUtils.hasReservationList(transaction) && !!tripID; | ||
|
||
const {getViolationsForField} = useViolations(transactionViolations ?? []); | ||
const {getViolationsForField} = useViolations(transactionViolations ?? [], !isReceiptBeingScanned || !ReportUtils.isPaidGroupPolicy(report)); | ||
const hasViolations = useCallback( | ||
(field: ViolationField, data?: OnyxTypes.TransactionViolation['data'], policyHasDependentTags = false, tagValue?: string): boolean => | ||
!!canUseViolations && getViolationsForField(field, data, policyHasDependentTags, tagValue).length > 0, | ||
|
@@ -340,14 +340,13 @@ function MoneyRequestView({ | |
const receiptViolationNames: OnyxTypes.ViolationName[] = [ | ||
CONST.VIOLATIONS.RECEIPT_REQUIRED, | ||
CONST.VIOLATIONS.RECEIPT_NOT_SMART_SCANNED, | ||
CONST.VIOLATIONS.MODIFIED_DATE, | ||
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 shouldShowNotesViolations = !isReceiptBeingScanned && canUseViolations && ReportUtils.isPaidGroupPolicy(report); | ||
const shouldShowReceiptHeader = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); | ||
const shouldShowAuditMessage = !isReceiptBeingScanned && !!canUseViolations && ReportUtils.isPaidGroupPolicy(report); | ||
const shouldShowReceiptAudit = isReceiptAllowed && (shouldShowReceiptEmptyState || hasReceipt); | ||
|
||
const errors = { | ||
...(transaction?.errorFields?.route ?? transaction?.errors), | ||
|
@@ -389,10 +388,11 @@ function MoneyRequestView({ | |
<View style={styles.pRelative}> | ||
{shouldShowAnimatedBackground && <AnimatedEmptyStateBackground />} | ||
<> | ||
{shouldShowReceiptHeader && ( | ||
<ReceiptAuditHeader | ||
{shouldShowReceiptAudit && ( | ||
<ReceiptAudit | ||
notes={receiptViolations} | ||
shouldShowAuditMessage={!!(shouldShowNotesViolations && didRceiptScanSucceed)} | ||
shouldShowAuditSuccess={shouldShowAuditMessage && didRceiptScanSucceed} | ||
shouldShowAuditFailure={shouldShowAuditMessage && hasReceipt} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been looking at this for a minute, and it's not obvious to me why we now need shouldShowAuditSuccess and shouldShowAuditFailure, instead of using notes.length to determine what to show. What cases would we miss if we went back to relying only on notes.length? If you can update the docs for these params to make it clear, please do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously we were relying only on notes.length but if I recall correctly there were cases where success/failure text was shown before the receipt is scanned and even if there were no receipt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you confirm, and if you do, add a manual tests that would reproduce the issue, and confirm your change solves it. If you can't confirm, let's revert to what we had previously There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cead22, pls check the 2nd issue here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Krishna2323 sorry if this is obvious, but can you explain why we can't use a single prop? Both success and failure need to be shown only if there's a receipt, and the issue you linked shows an error when there's no receipt. What am I missing? Can you share test steps to reproduce the issue when we use only 1 prop, that doesn't happen with this solution? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, this is bit confusing. Above condition won't work correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cead22, I think we need We can remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love it, sorry for the late reply There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Krishna2323 will you be able to update this today and get the PR ready for review? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cead22, on it, will be ready in few minutes. |
||
/> | ||
)} | ||
{(hasReceipt || errors) && ( | ||
|
@@ -448,7 +448,7 @@ function MoneyRequestView({ | |
/> | ||
)} | ||
{!shouldShowReceiptEmptyState && !hasReceipt && <View style={{marginVertical: 6}} />} | ||
{shouldShowNotesViolations && <ReceiptAuditMessages notes={receiptViolations} />} | ||
{shouldShowAuditMessage && <ReceiptAuditMessages notes={receiptViolations} />} | ||
<OfflineWithFeedback pendingAction={getPendingFieldAction('amount')}> | ||
<MenuItemWithTopDescription | ||
title={amountTitle} | ||
|
@@ -555,7 +555,6 @@ function MoneyRequestView({ | |
/> | ||
</OfflineWithFeedback> | ||
)} | ||
|
||
{shouldShowTax && ( | ||
<OfflineWithFeedback pendingAction={getPendingFieldAction('taxAmount')}> | ||
<MenuItemWithTopDescription | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ import type { | |
ViolationsInvoiceMarkupParams, | ||
ViolationsMaxAgeParams, | ||
ViolationsMissingTagParams, | ||
ViolationsModifiedAmountParams, | ||
ViolationsOverCategoryLimitParams, | ||
ViolationsOverLimitParams, | ||
ViolationsPerDayLimitParams, | ||
|
@@ -3633,7 +3634,19 @@ export default { | |
missingCategory: 'Missing category', | ||
missingComment: 'Description required for selected category', | ||
missingTag: ({tagName}: ViolationsMissingTagParams) => `Missing ${tagName ?? 'tag'}`, | ||
modifiedAmount: 'Amount greater than scanned receipt', | ||
modifiedAmount: ({type, displayPercentVariance}: ViolationsModifiedAmountParams): string => { | ||
switch (type) { | ||
case 'distance': | ||
return 'Amount differs from calculated distance'; | ||
case 'card': | ||
return 'Amount greater than card transaction'; | ||
default: | ||
if (displayPercentVariance) { | ||
return `Amount ${displayPercentVariance}% greater than scanned receipt`; | ||
} | ||
return 'Amount greater than scanned receipt'; | ||
} | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated 👀 |
||
modifiedDate: 'Date differs from scanned receipt', | ||
nonExpensiworksExpense: 'Non-Expensiworks expense', | ||
overAutoApprovalLimit: ({formattedLimit}: ViolationsOverLimitParams) => `Expense exceeds auto approval limit of ${formattedLimit}`, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sobitneupane @cead22, I mistakenly added
modified amount
violation here while resolving conflict, thats why the violation was shown under receipt. I have removed that and alsoCONST.VIOLATIONS.MODIFIED_DATE
because I believe the date violation should also be shown under date field.