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: 7 additions & 11 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,9 @@ function MoneyReportHeader({
return Object.values(reportTransactions);
}, [reportTransactions]);

// 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(() => {
const shouldBlockSubmit = 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 @@ -464,9 +456,14 @@ 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 (isBlockSubmitDueToStrictPolicyRules && isReportOwner(moneyRequestReport) && isOpenExpenseReport(moneyRequestReport)) {
if (shouldBlockSubmit && isReportOwner(moneyRequestReport) && isOpenExpenseReport(moneyRequestReport)) {
optimisticNextStep = buildOptimisticNextStepForStrictPolicyRuleViolations();
}

Expand Down Expand Up @@ -869,7 +866,6 @@ function MoneyReportHeader({
success
onPress={confirmApproval}
text={translate('iou.approve')}
isDisabled={isBlockSubmitDueToPreventSelfApproval}
/>
),
[CONST.REPORT.PRIMARY_ACTIONS.PAY]: (
Expand Down
9 changes: 8 additions & 1 deletion 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 && !isReportSubmitter) {
if (submitToAccountID === report.ownerAccountID && policy?.preventSelfApproval) {
return false;
}

Expand Down Expand Up @@ -129,6 +129,13 @@ 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
4 changes: 1 addition & 3 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import {
canSendInvoice,
getGroupPaidPoliciesWithExpenseChatEnabled,
getPolicy,
getSubmitToAccountID,
isPaidGroupPolicy,
isPolicyAdmin,
isPolicyPayer,
Expand Down Expand Up @@ -1299,8 +1298,7 @@ function getActions(

const hasOnlyPendingCardOrScanningTransactions = allReportTransactions.length > 0 && allReportTransactions.every((t) => isScanning(t) || isPending(t));

const submitToAccountID = getSubmitToAccountID(policy, report);
const isAllowedToApproveExpenseReport = isAllowedToApproveExpenseReportUtils(report, submitToAccountID, policy);
const isAllowedToApproveExpenseReport = isAllowedToApproveExpenseReportUtils(report, undefined, policy);

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