diff --git a/src/components/SettlementButton/index.tsx b/src/components/SettlementButton/index.tsx index ab5ae68d523c..56bb9b8d3cf0 100644 --- a/src/components/SettlementButton/index.tsx +++ b/src/components/SettlementButton/index.tsx @@ -22,6 +22,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import {createWorkspace, isCurrencySupportedForDirectReimbursement, isCurrencySupportedForGlobalReimbursement} from '@libs/actions/Policy/Policy'; import {navigateToBankAccountRoute} from '@libs/actions/ReimbursementAccount'; import {getLastPolicyBankAccountID, getLastPolicyPaymentMethod} from '@libs/actions/Search'; +import {isBankAccountPartiallySetup} from '@libs/BankAccountUtils'; import Navigation from '@libs/Navigation/Navigation'; import {formatPaymentMethods, getActivePaymentType} from '@libs/PaymentUtils'; import {getActiveAdminWorkspaces, getPolicyEmployeeAccountIDs, isPaidGroupPolicy, isPolicyAdmin} from '@libs/PolicyUtils'; @@ -214,14 +215,15 @@ function SettlementButton({ return false; }, [policy, isAccountLocked, isUserValidated, chatReportID, reportID, showLockedAccountModal, isDelegateAccessRestricted, showDelegateNoAccessModal]); - const getPaymentSubitems = useCallback( + const getPaymentSubItems = useCallback( (payAsBusiness: boolean) => { const requiredAccountType = payAsBusiness ? CONST.BANK_ACCOUNT.TYPE.BUSINESS : CONST.BANK_ACCOUNT.TYPE.PERSONAL; return formattedPaymentMethods .filter((method) => { const accountData = method?.accountData as AccountData; - return accountData?.type === requiredAccountType; + const isPartiallySetup = isBankAccountPartiallySetup(accountData?.state); + return accountData?.type === requiredAccountType && !isPartiallySetup; }) .map((formattedPaymentMethod) => ({ text: formattedPaymentMethod?.title ?? '', @@ -376,7 +378,7 @@ function SettlementButton({ value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, }; return [ - ...(isCurrencySupported ? getPaymentSubitems(payAsBusiness) : []), + ...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []), ...(isCurrencySupported && isPolicyCurrencySupported ? [addBankAccountItem] : []), { text: translate('iou.payElsewhere', {formattedAmount: ''}), diff --git a/src/hooks/useBulkPayOptions.ts b/src/hooks/useBulkPayOptions.ts index 29b70bea45be..3a342f1982e2 100644 --- a/src/hooks/useBulkPayOptions.ts +++ b/src/hooks/useBulkPayOptions.ts @@ -3,6 +3,7 @@ import type {TupleToUnion} from 'type-fest'; import type {PopoverMenuItem} from '@components/PopoverMenu'; import type {BankAccountMenuItem} from '@components/Search/types'; import {isCurrencySupportedForGlobalReimbursement} from '@libs/actions/Policy/Policy'; +import {isBankAccountPartiallySetup} from '@libs/BankAccountUtils'; import Navigation from '@libs/Navigation/Navigation'; import {formatPaymentMethods} from '@libs/PaymentUtils'; import {hasRequestFromCurrentAccount} from '@libs/ReportActionsUtils'; @@ -98,12 +99,13 @@ function useBulkPayOptions({ }); } - const getPaymentSubitems = (payAsBusiness: boolean) => { + const getPaymentSubItems = (payAsBusiness: boolean) => { const requiredAccountType = payAsBusiness ? CONST.BANK_ACCOUNT.TYPE.BUSINESS : CONST.BANK_ACCOUNT.TYPE.PERSONAL; return formattedPaymentMethods .filter((method) => { const accountData = method?.accountData as AccountData; - return accountData?.type === requiredAccountType; + const isPartiallySetup = isBankAccountPartiallySetup(accountData?.state); + return accountData?.type === requiredAccountType && !isPartiallySetup; }) .map((formattedPaymentMethod) => ({ text: formattedPaymentMethod?.title ?? '', @@ -181,7 +183,7 @@ function useBulkPayOptions({ }, }; return [ - ...(isCurrencySupported ? getPaymentSubitems(payAsBusiness) : []), + ...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []), ...(isCurrencySupported ? [addBankAccountItem] : []), { text: translate('iou.payElsewhere', {formattedAmount: ''}), diff --git a/src/hooks/usePaymentOptions.ts b/src/hooks/usePaymentOptions.ts index a397cf284bcc..0684b2edfc1b 100644 --- a/src/hooks/usePaymentOptions.ts +++ b/src/hooks/usePaymentOptions.ts @@ -2,6 +2,7 @@ import {useCallback, useEffect, useMemo, useRef} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import type {TupleToUnion} from 'type-fest'; import type SettlementButtonProps from '@components/SettlementButton/types'; +import {isBankAccountPartiallySetup} from '@libs/BankAccountUtils'; import type {PaymentOrApproveOption} from '@libs/PaymentUtils'; import {formatPaymentMethods} from '@libs/PaymentUtils'; import {getPolicyEmployeeAccountIDs} from '@libs/PolicyUtils'; @@ -16,7 +17,7 @@ import Navigation from '@navigation/Navigation'; import {isCurrencySupportedForGlobalReimbursement} from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {BankAccountList, FundList, LastPaymentMethod} from '@src/types/onyx'; +import type {AccountData, BankAccountList, FundList, LastPaymentMethod} from '@src/types/onyx'; import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject'; import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails'; @@ -163,16 +164,24 @@ function usePaymentOptions({ if (isInvoiceReport) { const formattedPaymentMethods = formatPaymentMethods(bankAccountList, fundList, styles, translate); const isCurrencySupported = isCurrencySupportedForGlobalReimbursement(currency as CurrencyType); - const getPaymentSubitems = (payAsBusiness: boolean) => - formattedPaymentMethods.map((formattedPaymentMethod) => ({ - text: formattedPaymentMethod?.title ?? '', - description: formattedPaymentMethod?.description ?? '', - icon: formattedPaymentMethod?.icon, - onSelected: () => onPress(CONST.IOU.PAYMENT_TYPE.EXPENSIFY, payAsBusiness, formattedPaymentMethod.methodID, formattedPaymentMethod.accountType), - iconStyles: formattedPaymentMethod?.iconStyles, - iconHeight: formattedPaymentMethod?.iconSize, - iconWidth: formattedPaymentMethod?.iconSize, - })); + const getPaymentSubItems = (payAsBusiness: boolean) => { + const requiredAccountType = payAsBusiness ? CONST.BANK_ACCOUNT.TYPE.BUSINESS : CONST.BANK_ACCOUNT.TYPE.PERSONAL; + return formattedPaymentMethods + .filter((method) => { + const accountData = method?.accountData as AccountData; + const isPartiallySetup = isBankAccountPartiallySetup(accountData?.state); + return accountData?.type === requiredAccountType && !isPartiallySetup; + }) + .map((formattedPaymentMethod) => ({ + text: formattedPaymentMethod?.title ?? '', + description: formattedPaymentMethod?.description ?? '', + icon: formattedPaymentMethod?.icon, + onSelected: () => onPress(CONST.IOU.PAYMENT_TYPE.EXPENSIFY, payAsBusiness, formattedPaymentMethod.methodID, formattedPaymentMethod.accountType), + iconStyles: formattedPaymentMethod?.iconStyles, + iconHeight: formattedPaymentMethod?.iconSize, + iconWidth: formattedPaymentMethod?.iconSize, + })); + }; const addBankAccountItem = { text: translate('bankAccount.addBankAccount'), @@ -190,7 +199,7 @@ function usePaymentOptions({ value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, backButtonText: translate('iou.individual'), subMenuItems: [ - ...(isCurrencySupported ? getPaymentSubitems(false) : []), + ...(isCurrencySupported ? getPaymentSubItems(false) : []), { text: translate('iou.payElsewhere', {formattedAmount: ''}), icon: icons.Cash, @@ -208,7 +217,7 @@ function usePaymentOptions({ value: CONST.IOU.PAYMENT_TYPE.ELSEWHERE, backButtonText: translate('iou.business'), subMenuItems: [ - ...(isCurrencySupported ? getPaymentSubitems(true) : []), + ...(isCurrencySupported ? getPaymentSubItems(true) : []), ...(isCurrencySupported ? [addBankAccountItem] : []), { text: translate('iou.payElsewhere', {formattedAmount: ''}),