-
Notifications
You must be signed in to change notification settings - Fork 3k
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: Expense details - Violation is not displayed on description field when opening IOU details. #56405
base: main
Are you sure you want to change the base?
fix: Expense details - Violation is not displayed on description field when opening IOU details. #56405
Changes from all commits
1e084f2
fafe6d4
3c2ab26
1143243
fc381b2
acb2a64
6913635
083bf1e
17fcb63
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; | |
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useTransactionViolations from '@hooks/useTransactionViolations'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import ControlSelection from '@libs/ControlSelection'; | ||
import {convertToDisplayString} from '@libs/CurrencyUtils'; | ||
|
@@ -48,7 +49,6 @@ import type {TransactionDetails} from '@libs/ReportUtils'; | |
import StringUtils from '@libs/StringUtils'; | ||
import { | ||
compareDuplicateTransactionFields, | ||
getTransactionViolations, | ||
hasMissingSmartscanFields, | ||
hasNoticeTypeViolation as hasNoticeTypeViolationTransactionUtils, | ||
hasPendingUI, | ||
|
@@ -112,8 +112,11 @@ function MoneyRequestPreviewContent({ | |
const transactionID = isMoneyRequestAction ? getOriginalMessage(action)?.IOUTransactionID : undefined; | ||
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); | ||
const [walletTerms] = useOnyx(ONYXKEYS.WALLET_TERMS); | ||
const [allViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS); | ||
const transactionViolations = getTransactionViolations(transaction?.transactionID); | ||
const [violations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, { | ||
selector: (allTransactions) => | ||
Object.fromEntries(Object.entries(allTransactions ?? {}).filter(([key]) => transaction?.transactionID === key.replace(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, ''))), | ||
}); | ||
const transactionViolations = useTransactionViolations(transaction?.transactionID); | ||
|
||
const sessionAccountID = session?.accountID; | ||
const managerID = iouReport?.managerID ?? CONST.DEFAULT_NUMBER_ID; | ||
|
@@ -146,9 +149,9 @@ function MoneyRequestPreviewContent({ | |
const isOnHold = isOnHoldTransactionUtils(transaction); | ||
const isSettlementOrApprovalPartial = !!iouReport?.pendingFields?.partial; | ||
const isPartialHold = isSettlementOrApprovalPartial && isOnHold; | ||
const hasViolations = hasViolationTransactionUtils(transaction?.transactionID, allViolations, true); | ||
const hasNoticeTypeViolations = hasNoticeTypeViolationTransactionUtils(transaction?.transactionID, allViolations, true) && isPaidGroupPolicy(iouReport); | ||
const hasWarningTypeViolations = hasWarningTypeViolationTransactionUtils(transaction?.transactionID, allViolations, true); | ||
const hasViolations = hasViolationTransactionUtils(transaction, violations, true); | ||
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. Why didn't we pass transaction?.transactionID? |
||
const hasNoticeTypeViolations = hasNoticeTypeViolationTransactionUtils(transaction?.transactionID, violations, true) && isPaidGroupPolicy(iouReport); | ||
const hasWarningTypeViolations = hasWarningTypeViolationTransactionUtils(transaction?.transactionID, violations, true); | ||
const hasFieldErrors = hasMissingSmartscanFields(transaction); | ||
const isDistanceRequest = isDistanceRequestTransactionUtils(transaction); | ||
const isPerDiemRequest = isPerDiemRequestTransactionUtils(transaction); | ||
|
@@ -281,7 +284,7 @@ function MoneyRequestPreviewContent({ | |
if (isPending(transaction)) { | ||
return {shouldShow: true, messageIcon: Expensicons.CreditCardHourglass, messageDescription: translate('iou.transactionPending')}; | ||
} | ||
if (shouldShowBrokenConnectionViolation(transaction ? [transaction.transactionID] : [], iouReport, policy)) { | ||
if (shouldShowBrokenConnectionViolation(transaction ? [transaction.transactionID] : [], iouReport, policy, violations)) { | ||
return {shouldShow: true, messageIcon: Expensicons.Hourglass, messageDescription: translate('violations.brokenConnection530Error')}; | ||
} | ||
if (hasPendingUI(transaction, transactionViolations)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {useMemo} from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import {isViolationDismissed} from '@libs/TransactionUtils'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {TransactionViolations} from '@src/types/onyx'; | ||
|
||
function useTransactionViolations(transactionID?: string): TransactionViolations { | ||
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`); | ||
const [transactionViolations = []] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`); | ||
return useMemo(() => transactionViolations.filter((violation) => !isViolationDismissed(transaction, violation)), [transaction, transactionViolations]); | ||
} | ||
|
||
roryabraham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export default useTransactionViolations; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6920,7 +6920,7 @@ function hasViolations( | |
reportTransactions?: SearchTransaction[], | ||
): boolean { | ||
const transactions = reportTransactions ?? getReportTransactions(reportID); | ||
return transactions.some((transaction) => hasViolation(transaction.transactionID, transactionViolations, shouldShowInReview)); | ||
return transactions.some((transaction) => hasViolation(transaction, transactionViolations, shouldShowInReview)); | ||
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. Same question. Why not transaction.transactionID? 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. @rojiphil, the util function |
||
} | ||
|
||
/** | ||
|
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.
Can we not use
transactionViolations
instead?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.
You mean the naming?
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.
No. I meant reuse
const transactionViolations = useTransactionViolations(transaction?.transactionID);
instead ofviolations
.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.
@rojiphil, we need
OnyxCollection
forhasViolationTransactionUtils
,hasNoticeTypeViolationTransactionUtils
&hasWarningTypeViolationTransactionUtils
.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.
Got it. Thanks.