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
7 changes: 7 additions & 0 deletions src/hooks/useBulkPayOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type UseBulkPayOptionProps = {
isCurrencySupportedWallet?: boolean;
currency: string | undefined;
formattedAmount: string;
onlyShowPayElsewhere: boolean;
};

type UseBulkPayOptionReturnType = {
Expand All @@ -54,6 +55,7 @@ function useBulkPayOptions({
isCurrencySupportedWallet,
currency,
formattedAmount,
onlyShowPayElsewhere,
}: UseBulkPayOptionProps): UseBulkPayOptionReturnType {
const icons = useMemoizedLazyExpensifyIcons(['Building', 'User'] as const);
const {translate} = useLocalize();
Expand Down Expand Up @@ -137,6 +139,10 @@ function useBulkPayOptions({
return undefined;
}

if (onlyShowPayElsewhere) {
return [paymentMethods[CONST.IOU.PAYMENT_TYPE.ELSEWHERE]];
}

if (shouldShowBusinessBankAccountOptions) {
buttonOptions.push(paymentMethods[CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT]);
}
Expand Down Expand Up @@ -238,6 +244,7 @@ function useBulkPayOptions({
chatReport,
getPaymentSubitems,
formattedAmount,
onlyShowPayElsewhere,
]);

return {
Expand Down
12 changes: 11 additions & 1 deletion src/pages/Search/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
import {hasTransactionBeenRejected} from '@libs/TransactionUtils';
import type {ReceiptFile} from '@pages/iou/request/step/IOURequestStepScan/types';
import variables from '@styles/variables';
import {dismissRejectUseExplanation, initMoneyRequest, initSplitExpense, setMoneyRequestParticipantsFromReport, setMoneyRequestReceipt} from '@userActions/IOU';
import {canIOUBePaid, dismissRejectUseExplanation, initMoneyRequest, initSplitExpense, setMoneyRequestParticipantsFromReport, setMoneyRequestReceipt} from '@userActions/IOU';
import {openOldDotLink} from '@userActions/Link';
import {buildOptimisticTransactionAndCreateDraft} from '@userActions/TransactionEdit';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -172,13 +172,23 @@ function SearchPage({route}: SearchPageProps) {
const selectedBulkCurrency = selectedReports.at(0)?.currency ?? Object.values(selectedTransactions).at(0)?.currency;
const totalFormattedAmount = getTotalFormattedAmount(selectedReports, selectedTransactions, selectedBulkCurrency);

const onlyShowPayElsewhere = useMemo(() => {
const selectedPolicy = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.POLICY}${selectedPolicyIDs.at(0)}`];
return (selectedTransactionReportIDs ?? selectedReportIDs).some((reportID) => {
const report = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const chatReport = currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.chatReportID}`];
return report && !canIOUBePaid(report, chatReport, selectedPolicy, undefined, false) && canIOUBePaid(report, chatReport, selectedPolicy, undefined, true);
});
}, [currentSearchResults?.data, selectedPolicyIDs, selectedReportIDs, selectedTransactionReportIDs]);

const {bulkPayButtonOptions, latestBankItems} = useBulkPayOptions({
selectedPolicyID: selectedPolicyIDs.at(0),
selectedReportID: selectedTransactionReportIDs.at(0) ?? selectedReportIDs.at(0),
activeAdminPolicies,
isCurrencySupportedWallet: isCurrencySupportedBulkWallet,
currency: selectedBulkCurrency,
formattedAmount: totalFormattedAmount,
onlyShowPayElsewhere,
});

useEffect(() => {
Expand Down
Loading