Skip to content
Merged
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
16 changes: 9 additions & 7 deletions src/libs/ReportSecondaryActionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
hasIntegrationAutoSync,
isPrefferedExporter,
} from './PolicyUtils';
import {getIOUActionForReportID, isPayAction} from './ReportActionsUtils';
import {getIOUActionForReportID, getOneTransactionThreadReportID, isPayAction} from './ReportActionsUtils';
import {
canAddTransaction,
isArchivedReport,
Expand Down Expand Up @@ -274,11 +274,12 @@ function isMarkAsExportedAction(report: Report, policy?: Policy): boolean {
return (isAdmin && syncEnabled) || (isExporter && !syncEnabled);
}

function isHoldAction(report: Report, reportTransactions: Transaction[]): boolean {
function isHoldAction(report: Report, reportTransactions: Transaction[], reportActions?: ReportAction[]): boolean {
const transactionThreadReportID = getOneTransactionThreadReportID(report.reportID, reportActions);
const isOneExpenseReport = reportTransactions.length === 1;
const transaction = reportTransactions.at(0);

if (!isOneExpenseReport || !transaction) {
if ((!!reportActions && !transactionThreadReportID) || !isOneExpenseReport || !transaction) {
return false;
}

Expand Down Expand Up @@ -319,14 +320,15 @@ function isChangeWorkspaceAction(report: Report, policy?: Policy): boolean {
return policies.filter((newPolicy) => isWorkspaceEligibleForReportChange(newPolicy, report, session, policy)).length > 0;
}

function isDeleteAction(report: Report, reportTransactions: Transaction[]): boolean {
function isDeleteAction(report: Report, reportTransactions: Transaction[], reportActions?: ReportAction[]): boolean {
const transactionThreadReportID = getOneTransactionThreadReportID(report.reportID, reportActions ?? []);
const isExpenseReport = isExpenseReportUtils(report);
const isIOUReport = isIOUReportUtils(report);

// This should be removed when is merged https://github.com/Expensify/App/pull/58020
const isSingleTransaction = reportTransactions.length === 1;

if ((!isExpenseReport && !isIOUReport) || !isSingleTransaction) {
if ((!isExpenseReport && !isIOUReport) || !isSingleTransaction || (!!reportActions && !transactionThreadReportID)) {
return false;
}

Expand Down Expand Up @@ -409,7 +411,7 @@ function getSecondaryReportActions(
options.push(CONST.REPORT.SECONDARY_ACTIONS.REOPEN);
}

if (isHoldAction(report, reportTransactions)) {
if (isHoldAction(report, reportTransactions, reportActions)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.HOLD);
}

Expand All @@ -421,7 +423,7 @@ function getSecondaryReportActions(

options.push(CONST.REPORT.SECONDARY_ACTIONS.VIEW_DETAILS);

if (isDeleteAction(report, reportTransactions)) {
if (isDeleteAction(report, reportTransactions, reportActions)) {
options.push(CONST.REPORT.SECONDARY_ACTIONS.DELETE);
}

Expand Down