From e4f298d7257096b2ad7300297e66eb0962e39a30 Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Thu, 11 Dec 2025 10:58:33 -0800 Subject: [PATCH] Revert "Merge pull request #76887 from nkdengineer/fix/75159" This reverts commit b864dca0c79b18dc3738b1c0496660296875d680, reversing changes made to b13a18b303e16163eeb7ab53a3fb30618f110320. --- src/components/MoneyReportHeader.tsx | 18 +++++++----------- src/libs/ReportPrimaryActionUtils.ts | 9 ++++++++- src/libs/SearchUIUtils.ts | 4 +--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 95bb6245f1e71..746988baf08a5 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -265,17 +265,9 @@ function MoneyReportHeader({ return Object.values(reportTransactions); }, [reportTransactions]); - // When prevent self-approval is enabled & the current user is submitter AND they're submitting to themselves, we need to show the optimistic next step - // We should always show this optimistic message for policies with preventSelfApproval - // to avoid any flicker during transitions between online/offline states - const nextApproverAccountID = getNextApproverAccountID(moneyRequestReport); - const isSubmitterSameAsNextApprover = isReportOwner(moneyRequestReport) && nextApproverAccountID === moneyRequestReport?.ownerAccountID; - const isBlockSubmitDueToStrictPolicyRules = useMemo(() => { + const shouldBlockSubmit = useMemo(() => { return shouldBlockSubmitDueToStrictPolicyRules(moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, accountID, email ?? '', transactions); }, [moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, accountID, email, transactions]); - const isBlockSubmitDueToPreventSelfApproval = isSubmitterSameAsNextApprover && policy?.preventSelfApproval; - - const shouldBlockSubmit = isBlockSubmitDueToStrictPolicyRules || isBlockSubmitDueToPreventSelfApproval; const iouTransactionID = isMoneyRequestAction(requestParentReportAction) ? getOriginalMessage(requestParentReportAction)?.IOUTransactionID : undefined; const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(iouTransactionID)}`, { @@ -464,9 +456,14 @@ function MoneyReportHeader({ hasDuplicates || shouldShowMarkAsResolved; + // When prevent self-approval is enabled & the current user is submitter AND they're submitting to themselves, we need to show the optimistic next step + // We should always show this optimistic message for policies with preventSelfApproval + // to avoid any flicker during transitions between online/offline states + const nextApproverAccountID = getNextApproverAccountID(moneyRequestReport); + const isSubmitterSameAsNextApprover = isReportOwner(moneyRequestReport) && nextApproverAccountID === moneyRequestReport?.ownerAccountID; let optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep; - if (isBlockSubmitDueToStrictPolicyRules && isReportOwner(moneyRequestReport) && isOpenExpenseReport(moneyRequestReport)) { + if (shouldBlockSubmit && isReportOwner(moneyRequestReport) && isOpenExpenseReport(moneyRequestReport)) { optimisticNextStep = buildOptimisticNextStepForStrictPolicyRuleViolations(); } @@ -869,7 +866,6 @@ function MoneyReportHeader({ success onPress={confirmApproval} text={translate('iou.approve')} - isDisabled={isBlockSubmitDueToPreventSelfApproval} /> ), [CONST.REPORT.PRIMARY_ACTIONS.PAY]: ( diff --git a/src/libs/ReportPrimaryActionUtils.ts b/src/libs/ReportPrimaryActionUtils.ts index 965c075a6d33a..7b17022bb3471 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -98,7 +98,7 @@ function isSubmitAction(report: Report, reportTransactions: Transaction[], polic const submitToAccountID = getSubmitToAccountID(policy, report); - if (submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval && !isReportSubmitter) { + if (submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval) { return false; } @@ -129,6 +129,13 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], poli return false; } + const isPreventSelfApprovalEnabled = policy?.preventSelfApproval; + const isReportSubmitter = isCurrentUserSubmitter(report); + + if (isPreventSelfApprovalEnabled && isReportSubmitter) { + return false; + } + return isProcessingReportUtils(report); } diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index 06278f12c7247..ee50849198574 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -80,7 +80,6 @@ import { canSendInvoice, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, - getSubmitToAccountID, isPaidGroupPolicy, isPolicyAdmin, isPolicyPayer, @@ -1299,8 +1298,7 @@ function getActions( const hasOnlyPendingCardOrScanningTransactions = allReportTransactions.length > 0 && allReportTransactions.every((t) => isScanning(t) || isPending(t)); - const submitToAccountID = getSubmitToAccountID(policy, report); - const isAllowedToApproveExpenseReport = isAllowedToApproveExpenseReportUtils(report, submitToAccountID, policy); + const isAllowedToApproveExpenseReport = isAllowedToApproveExpenseReportUtils(report, undefined, policy); // We're not supporting approve partial amount on search page now if (