Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ViolationMessages from '@components/ViolationMessages';
import {useWideRHPState} from '@components/WideRHPContextProvider';

import useActiveRoute from '@hooks/useActiveRoute';
import useAllTransactionViolations from '@hooks/useAllTransactionViolations';
import useAttendees from '@hooks/useAttendees';
import useCardFeedErrors from '@hooks/useCardFeedErrors';
import useConfirmModal from '@hooks/useConfirmModal';
Expand Down Expand Up @@ -284,6 +285,7 @@ function MoneyRequestView({

const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${getNonEmptyStringOnyxID(linkedTransactionID)}`);
const transactionViolations = useTransactionViolations(transaction?.transactionID, true, distanceOriginalPolicy ?? policy);
const allTransactionViolations = useAllTransactionViolations(transaction?.transactionID);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const delegateAccountID = useDelegateAccountID();
Expand Down Expand Up @@ -736,6 +738,7 @@ function MoneyRequestView({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations: allTransactionViolations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -876,6 +879,7 @@ function MoneyRequestView({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations: allTransactionViolations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -913,6 +917,7 @@ function MoneyRequestView({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations: allTransactionViolations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -953,6 +958,7 @@ function MoneyRequestView({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations: allTransactionViolations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/useAllTransactionViolations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';

import ONYXKEYS from '@src/ONYXKEYS';
import type {TransactionViolations} from '@src/types/onyx';

import type {OnyxEntry} from 'react-native-onyx';

import useOnyx from './useOnyx';

/**
* Returns all violations for the given transaction without any ownership or visibility calculations unlike useTransactionViolations
*/
function useAllTransactionViolations(transactionID: string | undefined): OnyxEntry<TransactionViolations> {
const [allTransactionViolations] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${getNonEmptyStringOnyxID(transactionID)}`);

return allTransactionViolations;
}

export default useAllTransactionViolations;
28 changes: 28 additions & 0 deletions src/libs/TransactionPreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
isOnHold,
isPending,
isScanning,
shouldShowViolation,
} from './TransactionUtils';
import {isInvalidMerchantValue} from './ValidationUtils';
import {filterReceiptViolations, isHardViolationOrRateDateWarning} from './Violations/ViolationsUtils';
Expand Down Expand Up @@ -358,6 +359,27 @@ function getTransactionPreviewTextAndTranslationPaths({
};
}

/**
* The over-auto-approval-limit notice ships without `showInReview`, so the notice-type check that gates the preview RBR
* skips it, even though it is worth an RBR for whoever has to approve the report. `shouldShowViolation` is the single
* rule for who that is, and it is applied here rather than trusting the array because some callers pass raw Onyx
* violations instead of the visible ones.
*/
function hasVisibleOverAutoApprovalLimitViolation(
transaction: OnyxEntry<OnyxTypes.Transaction> | undefined,
violations: OnyxTypes.TransactionViolations,
currentUserEmail: string,
currentUserAccountID: number,
report: OnyxEntry<OnyxTypes.Report>,
policy: OnyxEntry<OnyxTypes.Policy>,
): boolean {
if (!violations?.some((violation) => violation.name === CONST.VIOLATIONS.OVER_AUTO_APPROVAL_LIMIT)) {
return false;
}

return shouldShowViolation(report, policy, CONST.VIOLATIONS.OVER_AUTO_APPROVAL_LIMIT, currentUserEmail, currentUserAccountID, true, transaction);
}

function createTransactionPreviewConditionals({
iouReport,
iouReportOwnerLogin,
Expand Down Expand Up @@ -418,6 +440,7 @@ function createTransactionPreviewConditionals({
!!hasViolationsOfTypeNotice ||
hasWarningTypeViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport ?? undefined, iouReportOwnerLogin, policy) ||
hasViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport ?? undefined, iouReportOwnerLogin, policy, true) ||
hasVisibleOverAutoApprovalLimitViolation(transaction, violations, currentUserEmail ?? '', currentUserAccountID, iouReport ?? undefined, policy) ||
(isDistanceRequest(transaction) &&
violations?.some(
(violation) => violation.name === CONST.VIOLATIONS.MODIFIED_AMOUNT && (violation.type === CONST.VIOLATION_TYPES.VIOLATION || violation.type === CONST.VIOLATION_TYPES.NOTICE),
Expand Down Expand Up @@ -489,6 +512,11 @@ function transactionHasRBR(
return true;
}

// Check for the over-auto-approval-limit notice, which reaches the approver without showInReview
if (hasVisibleOverAutoApprovalLimitViolation(transaction, violations, currentUserEmail, currentUserAccountID, iouReport, policy)) {
return true;
}

// Check for distance-request modified-amount violations (type VIOLATION or NOTICE)
if (
isDistanceRequest(transaction) &&
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/IOU/SplitTransactionUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ function updateSplitTransactions({
isOffline,
delegateAccountID,
isTrackIntentUser,
violations: transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${existingTransactionID}`],
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down
25 changes: 25 additions & 0 deletions src/libs/actions/IOU/UpdateMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ function updateMoneyRequestReimbursable({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: {
Expand All @@ -445,6 +446,7 @@ function updateMoneyRequestReimbursable({
delegateAccountID: number | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
isTrackIntentUser: boolean | undefined;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
}) {
Expand All @@ -470,6 +472,7 @@ function updateMoneyRequestReimbursable({
isOffline,
delegateAccountID,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand All @@ -495,6 +498,7 @@ function updateMoneyRequestMerchant({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: {
Expand All @@ -515,6 +519,7 @@ function updateMoneyRequestMerchant({
delegateAccountID: number | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
isTrackIntentUser: boolean | undefined;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
}) {
Expand Down Expand Up @@ -553,6 +558,7 @@ function updateMoneyRequestMerchant({
hash,
delegateAccountID,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -832,6 +838,7 @@ type UpdateMoneyRequestTagParams = {
delegateAccountID: number | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
isTrackIntentUser: boolean | undefined;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
};
Expand All @@ -856,6 +863,7 @@ function updateMoneyRequestTag({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: UpdateMoneyRequestTagParams) {
Expand All @@ -881,6 +889,7 @@ function updateMoneyRequestTag({
isOffline,
delegateAccountID,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -964,6 +973,7 @@ type UpdateMoneyRequestTaxRateParams = {
delegateAccountID: number | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
isTrackIntentUser: boolean | undefined;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
};
Expand All @@ -986,6 +996,7 @@ function updateMoneyRequestTaxRate({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: UpdateMoneyRequestTaxRateParams) {
Expand All @@ -1009,6 +1020,7 @@ function updateMoneyRequestTaxRate({
isASAPSubmitBetaEnabled,
delegateAccountID,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -1040,6 +1052,7 @@ type UpdateMoneyRequestDistanceParams = {
isTrackIntentUser: boolean | undefined;
personalPolicyOutputCurrency: string | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
};
Expand Down Expand Up @@ -1069,6 +1082,7 @@ function updateMoneyRequestDistance({
isTrackIntentUser,
personalPolicyOutputCurrency,
reportPolicyTags,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: UpdateMoneyRequestDistanceParams) {
Expand Down Expand Up @@ -1115,6 +1129,7 @@ function updateMoneyRequestDistance({
delegateAccountID,
isTrackIntentUser,
personalPolicyOutputCurrency,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -1200,6 +1215,7 @@ function updateMoneyRequestCategory({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: {
Expand All @@ -1220,6 +1236,7 @@ function updateMoneyRequestCategory({
delegateAccountID: number | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
isTrackIntentUser: boolean | undefined;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
}) {
Expand All @@ -1245,6 +1262,7 @@ function updateMoneyRequestCategory({
hash,
delegateAccountID,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand All @@ -1269,6 +1287,7 @@ function updateMoneyRequestDescription({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
}: {
Expand All @@ -1288,6 +1307,7 @@ function updateMoneyRequestDescription({
delegateAccountID: number | undefined;
reportPolicyTags: OnyxEntry<OnyxTypes.PolicyTagLists>;
isTrackIntentUser: boolean | undefined;
violations: OnyxEntry<OnyxTypes.TransactionViolations>;
getCurrencyDecimals: CurrencyListActionsContextType['getCurrencyDecimals'];
getCurrencySymbol: CurrencyListActionsContextType['getCurrencySymbol'];
}) {
Expand Down Expand Up @@ -1326,6 +1346,7 @@ function updateMoneyRequestDescription({
hash,
delegateAccountID,
isTrackIntentUser,
violations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -1570,6 +1591,7 @@ function updateMoneyRequestAmountAndCurrency({
hash,
delegateAccountID,
isTrackIntentUser,
violations: transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`],
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down Expand Up @@ -1625,6 +1647,9 @@ type UpdateMoneyRequestDataKeys =
| typeof ONYXKEYS.COLLECTION.SNAPSHOT
| typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT;

/**
* @param params.violations - pass all violations including those generated on the server. Otherwise, server violations will be lost in the local optimistic calculation.
*/
function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): UpdateMoneyRequestData<UpdateMoneyRequestDataKeys> {
const {
transactionID,
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/TransactionInlineEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function getIouParamsForTransaction({
currentUserAccountID,
currentUserEmail,
}: GetIouParamsInput) {
// transaction is passed in by the caller; only the scoped violations are derived here for the thread-report build.
// transaction is passed in by the caller; only the violations scoped to this transaction are derived here.
const transactionViolationsForTransaction = transactionViolations?.[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`];

// parentReport (already resolved to the self DM for unreported expenses), parentReportAction, and
Expand Down Expand Up @@ -235,6 +235,7 @@ function getIouParamsForTransaction({
getCurrencyDecimals,
getCurrencySymbol,
reportPolicyTags,
violations: transactionViolationsForTransaction,
// Field-specific extras
transaction,
policyTagList: policyTags,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import useAllTransactionViolations from '@hooks/useAllTransactionViolations';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDelegateAccountID from '@hooks/useDelegateAccountID';
Expand All @@ -9,7 +10,6 @@ import usePermissions from '@hooks/usePermissions';
import usePrevious from '@hooks/usePrevious';
import useReportOwnerAsAttendee from '@hooks/useReportOwnerAsAttendee';
import useRestartOnReceiptFailure from '@hooks/useRestartOnReceiptFailure';
import useTransactionViolations from '@hooks/useTransactionViolations';

import {setMoneyRequestAttendees} from '@libs/actions/IOU/MoneyRequest';
import {updateMoneyRequestAttendees} from '@libs/actions/IOU/UpdateMoneyRequest';
Expand Down Expand Up @@ -61,7 +61,7 @@ function DynamicIOURequestStepAttendees({
const previousAttendees = usePrevious(attendees);
const {translate} = useLocalize();
const {getCurrencyDecimals, getCurrencySymbol} = useCurrencyListActions();
const transactionViolations = useTransactionViolations(transactionID);
const allTransactionViolations = useAllTransactionViolations(transactionID);
useRestartOnReceiptFailure(transaction, reportID, iouType, action);
const currentUserAccountIDParam = currentUserPersonalDetails.accountID;
const currentUserEmailParam = currentUserPersonalDetails.login ?? '';
Expand Down Expand Up @@ -92,7 +92,7 @@ function DynamicIOURequestStepAttendees({
policy,
policyTagList: policyTags,
policyCategories,
violations: transactionViolations ?? undefined,
violations: allTransactionViolations,
currentUserAccountIDParam,
currentUserEmailParam,
isASAPSubmitBetaEnabled,
Expand Down Expand Up @@ -120,7 +120,7 @@ function DynamicIOURequestStepAttendees({
policy,
policyTags,
policyCategories,
transactionViolations,
allTransactionViolations,
currentUserAccountIDParam,
currentUserEmailParam,
isASAPSubmitBetaEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {useSearchQueryContext} from '@components/Search/SearchContext';
import type {ListItem} from '@components/SelectionList/types';
import WorkspaceEmptyStateSection from '@components/WorkspaceEmptyStateSection';

import useAllTransactionViolations from '@hooks/useAllTransactionViolations';
import {useCurrencyListActions} from '@hooks/useCurrencyList';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDelegateAccountID from '@hooks/useDelegateAccountID';
Expand Down Expand Up @@ -94,6 +95,7 @@ function DynamicIOURequestStepCategory({
const policyID = policy?.id;

const [splitDraftTransaction] = useOnyx(`${ONYXKEYS.COLLECTION.SPLIT_TRANSACTION_DRAFT}${transactionID}`);
const allTransactionViolations = useAllTransactionViolations(transaction?.transactionID);
const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`);
const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES_DRAFT}${policyIdDraft}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`);
Expand Down Expand Up @@ -202,6 +204,7 @@ function DynamicIOURequestStepCategory({
delegateAccountID,
reportPolicyTags,
isTrackIntentUser,
violations: allTransactionViolations,
getCurrencyDecimals,
getCurrencySymbol,
});
Expand Down
Loading
Loading