diff --git a/src/hooks/useSearchBulkActions.ts b/src/hooks/useSearchBulkActions.ts index 320c3bffe03c..bbc9abee45bd 100644 --- a/src/hooks/useSearchBulkActions.ts +++ b/src/hooks/useSearchBulkActions.ts @@ -326,6 +326,11 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { const totalFormattedAmount = getTotalFormattedAmount(convertToDisplayString, selectedReports, selectedTransactions, selectedBulkCurrency); const onlyShowPayElsewhere = useMemo(() => { + const selectedCurrencies = [...selectedReports.map((report) => report.currency), ...Object.values(selectedTransactions).map((transaction) => transaction.currency)].filter(Boolean); + if (new Set(selectedCurrencies).size > 1) { + return true; + } + const firstPolicyID = selectedPolicyIDs.at(0); const selectedPolicy = firstPolicyID ? currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${firstPolicyID}`] : undefined; return (selectedTransactionReportIDs ?? selectedReportIDs).some((reportID) => { @@ -368,6 +373,8 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { selectedTransactionReportIDs, selectedReportIDs, bankAccountList, + selectedReports, + selectedTransactions, currentUserPersonalDetails?.login, currentUserPersonalDetails.accountID, ]); @@ -1264,13 +1271,12 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) { }, }); } - const {shouldEnableBulkPayOption, isFirstTimePayment} = getPayOption(selectedReports, selectedTransactions, lastPaymentMethods, selectedReportIDs, personalPolicyID); + const {shouldEnableBulkPayOption} = getPayOption(selectedReports, selectedTransactions, lastPaymentMethods, selectedReportIDs, personalPolicyID); - const shouldShowPayOption = !isOffline && !isAnyTransactionOnHold && shouldEnableBulkPayOption; + const shouldShowPayOption = !isOffline && !isAnyTransactionOnHold && shouldEnableBulkPayOption && !!bulkPayButtonOptions?.length; if (shouldShowPayOption) { - const hasMultipleBusinessBankAccounts = (businessBankAccountOptions?.length ?? 0) > 1; - const shouldShowPaySubmenu = isFirstTimePayment || (shouldShowBusinessBankAccountOptions && hasMultipleBusinessBankAccounts); + const shouldShowPaySubmenu = !!bulkPayButtonOptions?.length; const payButtonOption = { icon: expensifyIcons.MoneyBag, diff --git a/src/libs/actions/Search.ts b/src/libs/actions/Search.ts index 20059d76789c..56a98b7b6d56 100644 --- a/src/libs/actions/Search.ts +++ b/src/libs/actions/Search.ts @@ -1330,17 +1330,13 @@ function getPayOption( ? selectedReports.every( (report) => report.allActions.includes(CONST.SEARCH.ACTION_TYPES.PAY) && - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - ((hasLastPaymentMethod && report.policyID) || (getReportType(report.reportID) === getReportType(firstReport?.reportID) && report.policyID === firstReport?.policyID)) && + getReportType(report.reportID) === getReportType(firstReport?.reportID) && shouldShowBulkOptionForRemainingTransactions(selectedTransactions, selectedReportIDs, transactionKeys), ) : transactionKeys.every( (transactionIDKey) => selectedTransactions[transactionIDKey].action === CONST.SEARCH.ACTION_TYPES.PAY && - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - ((hasLastPaymentMethod && selectedTransactions[transactionIDKey].policyID) || - (getReportType(selectedTransactions[transactionIDKey].reportID) === getReportType(firstTransaction?.reportID) && - selectedTransactions[transactionIDKey].policyID === firstTransaction?.policyID)), + getReportType(selectedTransactions[transactionIDKey].reportID) === getReportType(firstTransaction?.reportID), ); return {