Skip to content

Commit 81884b8

Browse files
mountinyOSBotify
authored andcommitted
Merge pull request #53230 from Expensify/vit-revert51133
[CP Staging] Revert not showing approve and pay buttons if report has violations (cherry picked from commit fc24d28) (CP triggered by mountiny)
1 parent c5d7658 commit 81884b8

File tree

6 files changed

+12
-44
lines changed

6 files changed

+12
-44
lines changed

src/components/MoneyReportHeader.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
120120
const isPayAtEndExpense = TransactionUtils.isPayAtEndExpense(transaction);
121121
const isArchivedReport = ReportUtils.isArchivedRoomWithID(moneyRequestReport?.reportID);
122122
const [archiveReason] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport?.reportID ?? '-1'}`, {selector: ReportUtils.getArchiveReason});
123-
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS);
124123

125124
const getCanIOUBePaid = useCallback(
126-
(onlyShowPayElsewhere = false) => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined, transactionViolations, onlyShowPayElsewhere),
127-
[moneyRequestReport, chatReport, policy, transaction, transactionViolations],
125+
(onlyShowPayElsewhere = false) => IOU.canIOUBePaid(moneyRequestReport, chatReport, policy, transaction ? [transaction] : undefined, onlyShowPayElsewhere),
126+
[moneyRequestReport, chatReport, policy, transaction],
128127
);
129128
const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]);
130129

@@ -136,10 +135,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
136135

137136
const shouldShowPayButton = canIOUBePaid || onlyShowPayElsewhere;
138137

139-
const shouldShowApproveButton = useMemo(
140-
() => IOU.canApproveIOU(moneyRequestReport, policy, transactionViolations) && !hasOnlyPendingTransactions,
141-
[moneyRequestReport, policy, hasOnlyPendingTransactions, transactionViolations],
142-
);
138+
const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(moneyRequestReport, policy) && !hasOnlyPendingTransactions, [moneyRequestReport, policy, hasOnlyPendingTransactions]);
143139

144140
const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(moneyRequestReport);
145141

src/components/ReportActionItem/ReportPreview.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,14 @@ function ReportPreview({
330330

331331
const bankAccountRoute = ReportUtils.getBankAccountRoute(chatReport);
332332
const getCanIOUBePaid = useCallback(
333-
(onlyShowPayElsewhere = false) => IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions, transactionViolations, onlyShowPayElsewhere),
334-
[iouReport, chatReport, policy, allTransactions, transactionViolations],
333+
(onlyShowPayElsewhere = false) => IOU.canIOUBePaid(iouReport, chatReport, policy, allTransactions, onlyShowPayElsewhere),
334+
[iouReport, chatReport, policy, allTransactions],
335335
);
336336

337337
const canIOUBePaid = useMemo(() => getCanIOUBePaid(), [getCanIOUBePaid]);
338338
const onlyShowPayElsewhere = useMemo(() => !canIOUBePaid && getCanIOUBePaid(true), [canIOUBePaid, getCanIOUBePaid]);
339339
const shouldShowPayButton = isPaidAnimationRunning || canIOUBePaid || onlyShowPayElsewhere;
340-
const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, policy, transactionViolations), [iouReport, policy, transactionViolations]);
340+
const shouldShowApproveButton = useMemo(() => IOU.canApproveIOU(iouReport, policy), [iouReport, policy]);
341341

342342
const shouldDisableApproveButton = shouldShowApproveButton && !ReportUtils.isAllowedToApproveExpenseReport(iouReport);
343343

src/libs/ReportUtils.ts

-9
Original file line numberDiff line numberDiff line change
@@ -6356,14 +6356,6 @@ function hasViolations(reportID: string, transactionViolations: OnyxCollection<T
63566356
return transactions.some((transaction) => TransactionUtils.hasViolation(transaction.transactionID, transactionViolations, shouldShowInReview));
63576357
}
63586358

6359-
/**
6360-
* Checks to see if a report contains non-hold violations
6361-
*/
6362-
function hasNonHoldViolation(reportID: string, transactionViolations: OnyxCollection<TransactionViolation[]>, shouldShowInReview?: boolean): boolean {
6363-
const transactions = reportsTransactions[reportID] ?? [];
6364-
return transactions.some((transaction) => TransactionUtils.hasNonHoldViolation(transaction.transactionID, transactionViolations, shouldShowInReview));
6365-
}
6366-
63676359
/**
63686360
* Checks to see if a report contains a violation of type `warning`
63696361
*/
@@ -8585,7 +8577,6 @@ export {
85858577
hasSmartscanError,
85868578
hasUpdatedTotal,
85878579
hasViolations,
8588-
hasNonHoldViolation,
85898580
hasWarningTypeViolations,
85908581
hasNoticeTypeViolations,
85918582
isActionCreator,

src/libs/SearchUIUtils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ function getAction(data: OnyxTypes.SearchResults['data'], key: string): SearchTr
289289
const chatReportRNVP = data[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.chatReportID}`] ?? undefined;
290290

291291
if (
292-
IOU.canIOUBePaid(report, chatReport, policy, allReportTransactions, undefined, false, chatReportRNVP, invoiceReceiverPolicy) &&
292+
IOU.canIOUBePaid(report, chatReport, policy, allReportTransactions, false, chatReportRNVP, invoiceReceiverPolicy) &&
293293
!ReportUtils.hasOnlyHeldExpenses(report.reportID, allReportTransactions)
294294
) {
295295
return CONST.SEARCH.ACTION_TYPES.PAY;

src/libs/TransactionUtils/index.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import {toLocaleDigit} from '@libs/LocaleDigitUtils';
1515
import * as Localize from '@libs/Localize';
1616
import * as NumberUtils from '@libs/NumberUtils';
1717
import Permissions from '@libs/Permissions';
18-
import * as PolicyUtils from '@libs/PolicyUtils';
1918
import {getCleanedTagName, getDistanceRateCustomUnitRate} from '@libs/PolicyUtils';
19+
import * as PolicyUtils from '@libs/PolicyUtils';
2020
// eslint-disable-next-line import/no-cycle
2121
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
2222
import * as ReportConnection from '@libs/ReportConnection';
2323
import * as ReportUtils from '@libs/ReportUtils';
2424
import type {IOURequestType} from '@userActions/IOU';
25-
import type {IOUType} from '@src/CONST';
2625
import CONST from '@src/CONST';
26+
import type {IOUType} from '@src/CONST';
2727
import ONYXKEYS from '@src/ONYXKEYS';
2828
import type {Beta, OnyxInputOrEntry, Policy, RecentWaypoint, Report, ReviewDuplicates, TaxRate, TaxRates, Transaction, TransactionViolation, TransactionViolations} from '@src/types/onyx';
2929
import type {Attendee} from '@src/types/onyx/IOU';
@@ -872,17 +872,6 @@ function hasViolation(transactionID: string, transactionViolations: OnyxCollecti
872872
);
873873
}
874874

875-
/**
876-
* Checks if any non-hold violations for the provided transaction are of type 'violation'
877-
*/
878-
function hasNonHoldViolation(transactionID: string, transactionViolations: OnyxCollection<TransactionViolations>, showInReview?: boolean): boolean {
879-
return !!transactionViolations?.[ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS + transactionID]?.some(
880-
(violation: TransactionViolation) =>
881-
violation.type === CONST.VIOLATION_TYPES.VIOLATION &&
882-
violation.name !== CONST.VIOLATIONS.HOLD &&
883-
(showInReview === undefined || showInReview === (violation.showInReview ?? false)),
884-
);
885-
}
886875
/**
887876
* Checks if any violations for the provided transaction are of type 'notice'
888877
*/
@@ -1295,7 +1284,6 @@ export {
12951284
getRecentTransactions,
12961285
hasReservationList,
12971286
hasViolation,
1298-
hasNonHoldViolation,
12991287
hasBrokenConnectionViolation,
13001288
shouldShowBrokenConnectionViolation,
13011289
hasNoticeTypeViolation,

src/libs/actions/IOU.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -6812,7 +6812,6 @@ function sendMoneyWithWallet(report: OnyxEntry<OnyxTypes.Report>, amount: number
68126812
function canApproveIOU(
68136813
iouReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report> | SearchReport,
68146814
policy: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Policy> | SearchPolicy,
6815-
violations?: OnyxCollection<OnyxTypes.TransactionViolation[]>,
68166815
chatReportRNVP?: OnyxTypes.ReportNameValuePairs,
68176816
) {
68186817
// Only expense reports can be approved
@@ -6833,8 +6832,6 @@ function canApproveIOU(
68336832
const iouSettled = ReportUtils.isSettled(iouReport?.reportID);
68346833
const reportNameValuePairs = chatReportRNVP ?? ReportUtils.getReportNameValuePairs(iouReport?.reportID);
68356834
const isArchivedReport = ReportUtils.isArchivedRoom(iouReport, reportNameValuePairs);
6836-
const allViolations = violations ?? allTransactionViolations;
6837-
const hasNonHoldViolation = ReportUtils.hasNonHoldViolation(iouReport?.reportID ?? '-1', allViolations);
68386835
let isTransactionBeingScanned = false;
68396836
const reportTransactions = TransactionUtils.getAllReportTransactions(iouReport?.reportID);
68406837
for (const transaction of reportTransactions) {
@@ -6847,15 +6844,14 @@ function canApproveIOU(
68476844
}
68486845
}
68496846

6850-
return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport && !isTransactionBeingScanned && !hasNonHoldViolation;
6847+
return isCurrentUserManager && !isOpenExpenseReport && !isApproved && !iouSettled && !isArchivedReport && !isTransactionBeingScanned;
68516848
}
68526849

68536850
function canIOUBePaid(
68546851
iouReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report> | SearchReport,
68556852
chatReport: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Report> | SearchReport,
68566853
policy: OnyxTypes.OnyxInputOrEntry<OnyxTypes.Policy> | SearchPolicy,
68576854
transactions?: OnyxTypes.Transaction[] | SearchTransaction[],
6858-
violations?: OnyxCollection<OnyxTypes.TransactionViolation[]>,
68596855
onlyShowPayElsewhere = false,
68606856
chatReportRNVP?: OnyxTypes.ReportNameValuePairs,
68616857
invoiceReceiverPolicy?: SearchPolicy,
@@ -6902,9 +6898,7 @@ function canIOUBePaid(
69026898

69036899
const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(iouReport);
69046900
const isAutoReimbursable = policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES ? false : ReportUtils.canBeAutoReimbursed(iouReport, policy);
6905-
const allViolations = violations ?? allTransactionViolations;
6906-
const shouldBeApproved = canApproveIOU(iouReport, policy, allViolations);
6907-
const hasNonHoldViolation = ReportUtils.hasNonHoldViolation(iouReport?.reportID ?? '-1', allViolations);
6901+
const shouldBeApproved = canApproveIOU(iouReport, policy);
69086902

69096903
const isPayAtEndExpenseReport = ReportUtils.isPayAtEndExpenseReport(iouReport?.reportID, transactions);
69106904
return (
@@ -6916,7 +6910,6 @@ function canIOUBePaid(
69166910
!isChatReportArchived &&
69176911
!isAutoReimbursable &&
69186912
!shouldBeApproved &&
6919-
!hasNonHoldViolation &&
69206913
!isPayAtEndExpenseReport
69216914
);
69226915
}
@@ -6927,7 +6920,7 @@ function getIOUReportActionToApproveOrPay(chatReport: OnyxEntry<OnyxTypes.Report
69276920
return Object.values(chatReportActions).find((action) => {
69286921
const iouReport = ReportUtils.getReportOrDraftReport(action.childReportID ?? '-1');
69296922
const policy = PolicyUtils.getPolicy(iouReport?.policyID);
6930-
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy, undefined, allTransactionViolations) || canApproveIOU(iouReport, policy, allTransactionViolations);
6923+
const shouldShowSettlementButton = canIOUBePaid(iouReport, chatReport, policy) || canApproveIOU(iouReport, policy);
69316924
return action.childReportID?.toString() !== excludedIOUReportID && action.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && shouldShowSettlementButton;
69326925
});
69336926
}

0 commit comments

Comments
 (0)