diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 6e514871632f0..06d679d982078 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -30,6 +30,7 @@ import { isArchivedReportWithID, isInvoiceReport, isReportApproved, + isReportOwner, navigateBackOnDeleteTransaction, reportTransactionsSelector, } from '@libs/ReportUtils'; @@ -53,6 +54,7 @@ import { canSubmitReport, deleteMoneyRequest, deleteTrackExpense, + getNextApproverAccountID, payInvoice, payMoneyRequest, submitReport, @@ -208,10 +210,12 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea const shouldShowStatusBar = hasAllPendingRTERViolations || shouldShowBrokenConnectionViolation || hasOnlyHeldExpenses || hasScanningReceipt || isPayAtEndExpense || hasOnlyPendingTransactions; - // When prevent self-approval is enabled, we need to show the optimistic next step + // When prevent self-approval is enabled & the current user is submitter AND they're submitting to theirself, 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 optimisticNextStep = policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep; + const nextApproverAccountID = getNextApproverAccountID(moneyRequestReport); + const isSubmitterSameAsNextApprover = isReportOwner(moneyRequestReport) && nextApproverAccountID === moneyRequestReport?.ownerAccountID; + const optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep; const shouldShowNextStep = transactions?.length !== 0 && isFromPaidPolicy && !!optimisticNextStep?.message?.length && !shouldShowStatusBar; const shouldShowAnyButton = @@ -344,7 +348,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea (isDuplicate || shouldShowSettlementButton || !!shouldShowExportIntegrationButton || shouldShowSubmitButton || shouldShowMarkAsCashButton) && (!!statusBarProps || shouldShowNextStep); - // The submit button should be success green colour only if the user is submitter and the policy does not have Scheduled Submit turned on + // The submit button should be success green colour only if the user is the submitter and the policy does not have Scheduled Submit turned on const isWaitingForSubmissionFromCurrentUser = useMemo( () => chatReport?.isOwnPolicyExpenseChat && !policy?.harvesting?.enabled, [chatReport?.isOwnPolicyExpenseChat, policy?.harvesting?.enabled], diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index b9f1abf81edc3..1e3073dca7737 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -92,14 +92,14 @@ function buildOptimisticNextStepForPreventSelfApprovalsEnabled() { }, { text: 'yourself', - type: 'strong', + type: 'next-step-email', }, { text: '. Approving your own reports is ', }, { text: 'forbidden', - type: 'strong', + type: 'next-step-email', }, { text: ' by your policy. Please submit this report to someone else or contact your admin to change the person you submit to.',