Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isArchivedReportWithID,
isInvoiceReport,
isReportApproved,
isReportOwner,
navigateBackOnDeleteTransaction,
reportTransactionsSelector,
} from '@libs/ReportUtils';
Expand All @@ -53,6 +54,7 @@ import {
canSubmitReport,
deleteMoneyRequest,
deleteTrackExpense,
getNextApproverAccountID,
payInvoice,
payMoneyRequest,
submitReport,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down