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
8 changes: 5 additions & 3 deletions src/components/SettlementButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ?? '',
Expand Down Expand Up @@ -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: ''}),
Expand Down
8 changes: 5 additions & 3 deletions src/hooks/useBulkPayOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ?? '',
Expand Down Expand Up @@ -181,7 +183,7 @@ function useBulkPayOptions({
},
};
return [
...(isCurrencySupported ? getPaymentSubitems(payAsBusiness) : []),
...(isCurrencySupported ? getPaymentSubItems(payAsBusiness) : []),
...(isCurrencySupported ? [addBankAccountItem] : []),
{
text: translate('iou.payElsewhere', {formattedAmount: ''}),
Expand Down
35 changes: 22 additions & 13 deletions src/hooks/usePaymentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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'),
Expand All @@ -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,
Expand All @@ -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: ''}),
Expand Down
Loading