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
1 change: 1 addition & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,7 @@ function MoneyReportHeader({
[CONST.REPORT.SECONDARY_ACTIONS.PAY]: {
text: translate('iou.settlePayment', {formattedAmount: totalAmount}),
icon: expensifyIcons.Cash,
rightIcon: expensifyIcons.ArrowRight,
value: CONST.REPORT.SECONDARY_ACTIONS.PAY,
backButtonText: translate('iou.settlePayment', {formattedAmount: totalAmount}),
sentryLabel: CONST.SENTRY_LABEL.MORE_MENU.PAY,
Expand Down
6 changes: 5 additions & 1 deletion src/libs/ReportPreviewActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ function canPay(report: Report, isReportArchived: boolean, currentUserAccountID:
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(report);
const isReimbursed = isSettled(report);

const isExported = report.isExportedToIntegration ?? false;
const hasExportError = report?.hasExportError ?? false;
const didExportFail = !isExported && hasExportError;

if (isExpense && isReportPayer && isPaymentsEnabled && isReportFinished && reimbursableSpend !== 0) {
return true;
return !didExportFail;
}

if (!isProcessing) {
Expand Down
20 changes: 16 additions & 4 deletions src/libs/ReportPrimaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ function isApproveAction(report: Report, reportTransactions: Transaction[], poli
return isProcessingReportUtils(report);
}

function isPrimaryPayAction(report: Report, policy?: Policy, reportNameValuePairs?: ReportNameValuePairs, isChatReportArchived?: boolean, invoiceReceiverPolicy?: Policy) {
function isPrimaryPayAction(
report: Report,
policy?: Policy,
reportNameValuePairs?: ReportNameValuePairs,
isChatReportArchived?: boolean,
invoiceReceiverPolicy?: Policy,
reportActions?: ReportAction[],
isSecondaryAction?: boolean,
) {
if (isArchivedReport(reportNameValuePairs) || isChatReportArchived) {
return false;
}
Expand All @@ -164,6 +172,9 @@ function isPrimaryPayAction(report: Report, policy?: Policy, reportNameValuePair
const isReportApproved = isReportApprovedUtils({report});
const isReportClosed = isClosedReportUtils(report);
const isProcessingReport = isProcessingReportUtils(report);
const isExported = isExportedUtil(reportActions);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduced #87654. isExportedUtil(reportActions) is called without report, so it falls back to scanning report actions instead of reading report.isExportedToIntegration. After a failed export, the optimistic action persists, making isExported incorrectly return true and showing Pay instead of Export. Fixed in #90154.

const hasExportError = hasExportErrorUtil(reportActions, report);
const didExportFail = !isExported && hasExportError;

const isApprovalEnabled = policy ? policy.approvalMode && policy.approvalMode !== CONST.POLICY.APPROVAL_MODE.OPTIONAL : false;
const isSubmittedWithoutApprovalsEnabled = !isApprovalEnabled && isProcessingReport;
Expand All @@ -172,7 +183,7 @@ function isPrimaryPayAction(report: Report, policy?: Policy, reportNameValuePair
const {reimbursableSpend} = getMoneyRequestSpendBreakdown(report);

if (isReportPayer && isExpenseReport && arePaymentsEnabled && isReportFinished && reimbursableSpend !== 0) {
return true;
return isSecondaryAction ?? !didExportFail;
}

if (!isProcessingReport) {
Expand Down Expand Up @@ -404,7 +415,8 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf<t
return '';
}

const isPayActionWithAllExpensesHeld = isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived) && hasOnlyHeldExpenses(report?.reportID);
const isPayActionWithAllExpensesHeld =
isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy, reportActions) && hasOnlyHeldExpenses(report?.reportID);
const expensesToHold = getAllExpensesToHoldIfApplicable(report, reportActions, reportTransactions, policy);

if (isMarkAsCashAction(currentUserEmail, currentUserAccountID, report, reportTransactions, violations, policy)) {
Expand All @@ -430,7 +442,7 @@ function getReportPrimaryAction(params: GetReportPrimaryActionParams): ValueOf<t
return CONST.REPORT.PRIMARY_ACTIONS.SUBMIT;
}

if (isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy)) {
if (isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived, invoiceReceiverPolicy, reportActions)) {
return CONST.REPORT.PRIMARY_ACTIONS.PAY;
}

Expand Down
7 changes: 6 additions & 1 deletion src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
canRejectReportAction,
doesReportContainRequestsFromMultipleUsers,
getTransactionDetails,
hasExportError as hasExportErrorUtils,
hasOnlyHeldExpenses,
hasOnlyNonReimbursableTransactions,
hasReportBeenReopened as hasReportBeenReopenedUtils,
Expand Down Expand Up @@ -702,7 +703,11 @@
}): Array<ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>> {
const options: Array<ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>> = [];

if (isPrimaryPayAction(report, policy, reportNameValuePairs) && hasOnlyHeldExpenses(report?.reportID)) {
const isExported = isExportedUtils(reportActions);
const hasExportError = hasExportErrorUtils(reportActions, report);
const didExportFail = !isExported && hasExportError;

if (isPrimaryPayAction(report, policy, reportNameValuePairs, isChatReportArchived, undefined, reportActions, true) && (hasOnlyHeldExpenses(report?.reportID) || didExportFail)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.PAY);
}

Expand Down Expand Up @@ -768,7 +773,7 @@
}

// Disabled for now to fix deploy blockers. Will be re-enabled in https://github.com/Expensify/App/pull/77343
if (isDuplicateAction(report, reportTransactions) && false) {

Check warning on line 776 in src/libs/ReportSecondaryActionUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected constant condition
options.push(CONST.REPORT.SECONDARY_ACTIONS.DUPLICATE);
}

Expand Down Expand Up @@ -849,7 +854,7 @@
}

// Disabled for now to fix deploy blockers. Will be re-enabled in https://github.com/Expensify/App/pull/77343
if (isDuplicateAction(parentReport, [reportTransaction]) && false) {

Check warning on line 857 in src/libs/ReportSecondaryActionUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Unexpected constant condition
options.push(CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.DUPLICATE);
}

Expand Down
Loading