From d96d654aa7d4c04e396a4d13a91b7381b60a62fc Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Mon, 24 Nov 2025 23:55:06 +0700 Subject: [PATCH] disable primary action button --- src/components/MoneyReportHeader.tsx | 18 +++++++++++------- src/libs/ReportPrimaryActionUtils.ts | 9 +-------- src/libs/SearchUIUtils.ts | 5 +++-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 4428440ecdac..c4c6f4a29372 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -253,9 +253,17 @@ function MoneyReportHeader({ return Object.values(reportTransactions); }, [reportTransactions]); - const shouldBlockSubmit = useMemo(() => { + // 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(() => { return shouldBlockSubmitDueToStrictPolicyRules(moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, transactions); }, [moneyRequestReport?.reportID, violations, areStrictPolicyRulesEnabled, 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)}`, { @@ -428,14 +436,9 @@ 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 (shouldBlockSubmit && isReportOwner(moneyRequestReport) && isOpenExpenseReport(moneyRequestReport)) { + if (isBlockSubmitDueToStrictPolicyRules && isReportOwner(moneyRequestReport) && isOpenExpenseReport(moneyRequestReport)) { optimisticNextStep = buildOptimisticNextStepForStrictPolicyRuleViolations(); } @@ -801,6 +804,7 @@ 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 a1414b8f1de0..e2f4ae4dd963 100644 --- a/src/libs/ReportPrimaryActionUtils.ts +++ b/src/libs/ReportPrimaryActionUtils.ts @@ -97,7 +97,7 @@ function isSubmitAction(report: Report, reportTransactions: Transaction[], polic const submitToAccountID = getSubmitToAccountID(policy, report); - if (submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval) { + if (submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval && !isReportSubmitter) { return false; } @@ -128,13 +128,6 @@ 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 116bbe4b449a..58e99345a786 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -74,7 +74,7 @@ import {translateLocal} from './Localize'; import Navigation from './Navigation/Navigation'; import Parser from './Parser'; import {getDisplayNameOrDefault} from './PersonalDetailsUtils'; -import {arePaymentsEnabled, canSendInvoice, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils'; +import {arePaymentsEnabled, canSendInvoice, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, getSubmitToAccountID, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils'; import { getOriginalMessage, isCreatedAction, @@ -1316,7 +1316,8 @@ function getActions( const hasOnlyPendingCardOrScanningTransactions = allReportTransactions.length > 0 && allReportTransactions.every((t) => isScanning(t) || isPending(t)); - const isAllowedToApproveExpenseReport = isAllowedToApproveExpenseReportUtils(report, undefined, policy); + const submitToAccountID = getSubmitToAccountID(policy, report); + const isAllowedToApproveExpenseReport = isAllowedToApproveExpenseReportUtils(report, submitToAccountID, policy); if ( canApproveIOU(report, policy, allReportTransactions) && isAllowedToApproveExpenseReport &&