From e8a1f9c9cf6e71fbe3389c16e29a4b211eca046e Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 11 Mar 2025 01:27:50 +0200 Subject: [PATCH 1/4] Only show prevent self approval if next approver is submitter who is self --- src/components/MoneyReportHeader.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 6e514871632f0..1366c35ca22e7 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, @@ -211,7 +213,9 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea // When prevent self-approval is enabled, 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], From d1a6ef72e501ca0b38e28f4dc43bee6d085b8b18 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 11 Mar 2025 01:28:53 +0200 Subject: [PATCH 2/4] Add new condition to change --- src/components/MoneyReportHeader.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 1366c35ca22e7..9f730512554de 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -210,7 +210,7 @@ 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 nextApproverAccountID = getNextApproverAccountID(moneyRequestReport); From 27768d1c4537f416b4f8d150dc6cc1ae3d72daa7 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Tue, 11 Mar 2025 01:39:22 +0200 Subject: [PATCH 3/4] prettify --- src/components/MoneyReportHeader.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyReportHeader.tsx b/src/components/MoneyReportHeader.tsx index 9f730512554de..06d679d982078 100644 --- a/src/components/MoneyReportHeader.tsx +++ b/src/components/MoneyReportHeader.tsx @@ -215,7 +215,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea // to avoid any flicker during transitions between online/offline states const nextApproverAccountID = getNextApproverAccountID(moneyRequestReport); const isSubmitterSameAsNextApprover = isReportOwner(moneyRequestReport) && nextApproverAccountID === moneyRequestReport?.ownerAccountID; - const optimisticNextStep = (isSubmitterSameAsNextApprover && policy?.preventSelfApproval) ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep; + const optimisticNextStep = isSubmitterSameAsNextApprover && policy?.preventSelfApproval ? buildOptimisticNextStepForPreventSelfApprovalsEnabled() : nextStep; const shouldShowNextStep = transactions?.length !== 0 && isFromPaidPolicy && !!optimisticNextStep?.message?.length && !shouldShowStatusBar; const shouldShowAnyButton = From 1807c6ff529a5d3da83145eaabb4534f804fa9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucien=20Akchot=C3=A9?= Date: Tue, 11 Mar 2025 09:28:44 +0100 Subject: [PATCH 4/4] fix styling for prevent self approval --- src/libs/NextStepUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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.',