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
18 changes: 11 additions & 7 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,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, 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)}`, {
Expand Down Expand Up @@ -444,14 +452,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();
}

Expand Down Expand Up @@ -824,6 +827,7 @@ function MoneyReportHeader({
success
onPress={confirmApproval}
text={translate('iou.approve')}
isDisabled={isBlockSubmitDueToPreventSelfApproval}
/>
),
[CONST.REPORT.PRIMARY_ACTIONS.PAY]: (
Expand Down
9 changes: 1 addition & 8 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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;
}

Expand Down Expand Up @@ -129,13 +129,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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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 {
getIOUActionForReportID,
getOriginalMessage,
Expand Down Expand Up @@ -1287,7 +1287,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);

// We're not supporting approve partial amount on search page now
if (
Expand Down
Loading