Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use invoiceTransferBankAccountID to determine default badge for a payment method on Invoices page #54619

Merged
merged 5 commits into from
Jan 16, 2025
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
2 changes: 2 additions & 0 deletions src/libs/API/parameters/AddPersonalBankAccountParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type AddPersonalBankAccountParams = {
bank?: string;
plaidAccountID: string;
plaidAccessToken: string;
policyID?: string;
source?: string;
};

export default AddPersonalBankAccountParams;
16 changes: 14 additions & 2 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ function setPlaidEvent(eventName: string | null) {
/**
* Open the personal bank account setup flow, with an optional exitReportID to redirect to once the flow is finished.
*/
function openPersonalBankAccountSetupView(exitReportID?: string, isUserValidated = true) {
function openPersonalBankAccountSetupView(exitReportID?: string, policyID?: string, source?: string, isUserValidated = true) {
clearPlaid().then(() => {
if (exitReportID) {
Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {exitReportID});
}
if (policyID) {
Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {policyID});
}
if (source) {
Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {source});
}
if (!isUserValidated) {
Navigation.navigate(ROUTES.SETTINGS_WALLET_VERIFY_ACCOUNT.getRoute(Navigation.getActiveRoute(), ROUTES.SETTINGS_ADD_BANK_ACCOUNT));
}
Expand Down Expand Up @@ -196,7 +202,7 @@ function connectBankAccountWithPlaid(bankAccountID: number, selectedPlaidBankAcc
*
* TODO: offline pattern for this command will have to be added later once the pattern B design doc is complete
*/
function addPersonalBankAccount(account: PlaidBankAccount) {
function addPersonalBankAccount(account: PlaidBankAccount, policyID?: string, source?: string) {
const parameters: AddPersonalBankAccountParams = {
addressName: account.addressName ?? '',
routingNumber: account.routingNumber,
Expand All @@ -207,6 +213,12 @@ function addPersonalBankAccount(account: PlaidBankAccount) {
plaidAccountID: account.plaidAccountID,
plaidAccessToken: account.plaidAccessToken,
};
if (policyID) {
parameters.policyID = policyID;
}
if (source) {
parameters.source = source;
}

const onyxData: OnyxData = {
optimisticData: [
Expand Down
7 changes: 5 additions & 2 deletions src/pages/AddPersonalBankAccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import useThemeStyles from '@hooks/useThemeStyles';
import getPlaidOAuthReceivedRedirectURI from '@libs/getPlaidOAuthReceivedRedirectURI';
import Navigation from '@libs/Navigation/Navigation';
import * as BankAccounts from '@userActions/BankAccounts';

Check failure on line 15 in src/pages/AddPersonalBankAccountPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
import * as PaymentMethods from '@userActions/PaymentMethods';

Check failure on line 16 in src/pages/AddPersonalBankAccountPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -46,12 +46,15 @@

const submitBankAccountForm = useCallback(() => {
const bankAccounts = plaidData?.bankAccounts ?? [];
const policyID = personalBankAccount?.policyID;
const source = personalBankAccount?.source;

const selectedPlaidBankAccount = bankAccounts.find((bankAccount) => bankAccount.plaidAccountID === selectedPlaidAccountId);

if (selectedPlaidBankAccount) {
BankAccounts.addPersonalBankAccount(selectedPlaidBankAccount);
BankAccounts.addPersonalBankAccount(selectedPlaidBankAccount, policyID, source);
}
}, [plaidData, selectedPlaidAccountId]);
}, [plaidData, selectedPlaidAccountId, personalBankAccount]);

const exitFlow = useCallback(
(shouldContinue = false) => {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import ControlSelection from '@libs/ControlSelection';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';

Check failure on line 42 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as ErrorUtils from '@libs/ErrorUtils';

Check failure on line 43 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import focusComposerWithDelay from '@libs/focusComposerWithDelay';
import * as LocalePhoneNumber from '@libs/LocalePhoneNumber';

Check failure on line 45 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import Navigation from '@libs/Navigation/Navigation';
import Permissions from '@libs/Permissions';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';

Check failure on line 48 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as PolicyUtils from '@libs/PolicyUtils';

Check failure on line 49 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as ReportActionsUtils from '@libs/ReportActionsUtils';

Check failure on line 50 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as ReportUtils from '@libs/ReportUtils';

Check failure on line 51 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import type {MissingPaymentMethod} from '@libs/ReportUtils';
import SelectionScraper from '@libs/SelectionScraper';
import shouldRenderAddPaymentCard from '@libs/shouldRenderAppPaymentCard';
import {ReactionListContext} from '@pages/home/ReportScreenContext';
import * as BankAccounts from '@userActions/BankAccounts';

Check failure on line 56 in src/pages/home/report/PureReportActionItem.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @userActions are not allowed. Use named imports instead. Example: import { action } from "@userActions/module"
import * as EmojiPickerAction from '@userActions/EmojiPickerAction';
import * as Member from '@userActions/Policy/Member';
import * as Report from '@userActions/Report';
Expand Down Expand Up @@ -733,7 +733,9 @@
success
style={[styles.w100, styles.requestPreviewBox]}
text={translate('bankAccount.addBankAccount')}
onPress={() => BankAccounts.openPersonalBankAccountSetupView(Navigation.getTopmostReportId() ?? linkedReport?.reportID, isUserValidated)}
onPress={() =>
BankAccounts.openPersonalBankAccountSetupView(Navigation.getTopmostReportId() ?? linkedReport?.reportID, undefined, undefined, isUserValidated)
}
pressOnEnter
large
/>
Expand Down
18 changes: 2 additions & 16 deletions src/pages/settings/Wallet/PaymentMethodList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,10 @@ function dismissError(item: PaymentMethodItem) {
}
}

function shouldShowDefaultBadge(filteredPaymentMethods: PaymentMethod[], item: PaymentMethod, walletLinkedAccountID: number, isDefault = false): boolean {
function shouldShowDefaultBadge(filteredPaymentMethods: PaymentMethod[], isDefault = false): boolean {
if (!isDefault) {
return false;
}
// Find all payment methods that are marked as default
const defaultPaymentMethods = filteredPaymentMethods.filter((method: PaymentMethod) => !!method.isDefault);

// If there is more than one payment method, show the default badge only for the most recently added default account.
if (defaultPaymentMethods.length > 1) {
if (item.accountType === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT) {
return item.accountData?.bankAccountID === walletLinkedAccountID;
}
if (item.accountType === CONST.PAYMENT_METHODS.DEBIT_CARD) {
return item.accountData?.fundID === walletLinkedAccountID;
}
}
const defaultablePaymentMethodCount = filteredPaymentMethods.filter(
(method) => method.accountType === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT || method.accountType === CONST.PAYMENT_METHODS.DEBIT_CARD,
).length;
Expand Down Expand Up @@ -409,9 +397,7 @@ function PaymentMethodList({
badgeText={
shouldShowDefaultBadge(
filteredPaymentMethods,
item,
userWallet?.walletLinkedAccountID ?? CONST.DEFAULT_NUMBER_ID,
invoiceTransferBankAccountID ? invoiceTransferBankAccountID === item.methodID : item.isDefault,
invoiceTransferBankAccountID ? invoiceTransferBankAccountID === item.methodID : item.methodID === userWallet?.walletLinkedAccountID,
)
? translate('paymentMethodList.defaultPaymentMethod')
: undefined
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/invoices/WorkspaceInvoiceVBASection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function WorkspaceInvoiceVBASection({policyID}: WorkspaceInvoiceVBASectionProps)
// Determines whether or not the modal popup is mounted from the bottom of the screen instead of the side mount on Web or Desktop screens
const isPopoverBottomMount = anchorPosition.anchorPositionTop === 0 || shouldUseNarrowLayout;
const shouldShowMakeDefaultButton = !paymentMethod.isSelectedPaymentMethodDefault;
const transferBankAccountID = policy?.invoice?.bankAccount?.transferBankAccountID;
const transferBankAccountID = policy?.invoice?.bankAccount?.transferBankAccountID ?? -1;

/**
* Set position of the payment menu
Expand Down Expand Up @@ -166,7 +166,7 @@ function WorkspaceInvoiceVBASection({policyID}: WorkspaceInvoiceVBASectionProps)
const addPaymentMethodTypePressed = (paymentType: string) => {
hideAddPaymentMenu();
if (paymentType === CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT || paymentType === CONST.PAYMENT_METHODS.BUSINESS_BANK_ACCOUNT) {
BankAccounts.openPersonalBankAccountSetupView(undefined, isUserValidated);
BankAccounts.openPersonalBankAccountSetupView(undefined, policyID, 'invoice', isUserValidated);
return;
}

Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/PersonalBankAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type PersonalBankAccount = {
/** Any reportID we should redirect to at the end of the flow */
exitReportID?: string;

/** The policyID of the workspace for which the bank account is being added */
policyID?: string;

/** Where the bank account addition was started, e.g., from the Invoices page or Wallet page */
source?: string;

/** If set, continue with the KYC flow after adding a PBA. This specifies the fallback route to use. */
onSuccessFallbackRoute?: Route;
};
Expand Down
Loading