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

Fix: navigate to enable-payment page after adding Bank account #29847

Merged
merged 4 commits into from
Oct 18, 2023
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
3 changes: 3 additions & 0 deletions src/components/SettlementButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import KYCWall from './KYCWall';
import withNavigation from './withNavigation';
import * as Expensicons from './Icon/Expensicons';
import ButtonWithDropdownMenu from './ButtonWithDropdownMenu';
import * as BankAccounts from '../libs/actions/BankAccounts';
import ROUTES from '../ROUTES';

const propTypes = {
/** Callback to execute when this button is pressed. Receives a single payment type argument. */
Expand Down Expand Up @@ -191,6 +193,7 @@ function SettlementButton({
const selectPaymentType = (event, iouPaymentType, triggerKYCFlow) => {
if (iouPaymentType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY || iouPaymentType === CONST.IOU.PAYMENT_TYPE.VBBA) {
triggerKYCFlow(event, iouPaymentType);
BankAccounts.setPersonalBankAccountContinueKYCOnSuccess(ROUTES.ENABLE_PAYMENTS);
return;
}

Expand Down
8 changes: 8 additions & 0 deletions src/libs/actions/BankAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ function openPersonalBankAccountSetupView(exitReportID: string) {
});
}

/**
* Whether after adding a bank account we should continue with the KYC flow
*/
Comment on lines +58 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Stores a route that is navigated to after successfully adding a bank account

function setPersonalBankAccountContinueKYCOnSuccess(onSuccessFallbackRoute: string) {
Onyx.merge(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {onSuccessFallbackRoute});
}

function clearPersonalBankAccount() {
clearPlaid();
Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {});
Expand Down Expand Up @@ -431,6 +438,7 @@ export {
connectBankAccountWithPlaid,
deletePaymentBankAccount,
handlePlaidError,
setPersonalBankAccountContinueKYCOnSuccess,
openPersonalBankAccountSetupView,
clearReimbursementAccount,
openReimbursementAccountPage,
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/PaymentMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const kycWallRef = createRef<KYCWallRef>();
/**
* When we successfully add a payment method or pass the KYC checks we will continue with our setup action if we have one set.
*/
function continueSetup() {
function continueSetup(fallbackRoute = ROUTES.HOME) {
if (!kycWallRef.current?.continue) {
Navigation.goBack(ROUTES.HOME);
Navigation.goBack(fallbackRoute);
return;
}

// Close the screen (Add Debit Card, Add Bank Account, or Enable Payments) on success and continue with setup
Navigation.goBack(ROUTES.HOME);
Navigation.goBack(fallbackRoute);
kycWallRef.current.continue();
}

Expand Down
9 changes: 7 additions & 2 deletions src/pages/AddPersonalBankAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Form from '../components/Form';
import ROUTES from '../ROUTES';
import * as PlaidDataProps from './ReimbursementAccount/plaidDataPropTypes';
import ConfirmationPage from '../components/ConfirmationPage';
import * as PaymentMethods from '../libs/actions/PaymentMethods';

const propTypes = {
...withLocalizePropTypes,
Expand Down Expand Up @@ -86,10 +87,14 @@ class AddPersonalBankAccountPage extends React.Component {
BankAccounts.addPersonalBankAccount(selectedPlaidBankAccount);
}

exitFlow() {
exitFlow(shouldContinue = false) {
const exitReportID = lodashGet(this.props, 'personalBankAccount.exitReportID');
const onSuccessFallbackRoute = lodashGet(this.props, 'personalBankAccount.onSuccessFallbackRoute', '');

if (exitReportID) {
Navigation.dismissModal(exitReportID);
} else if (shouldContinue && onSuccessFallbackRoute) {
PaymentMethods.continueSetup(onSuccessFallbackRoute);
} else {
Navigation.goBack(ROUTES.SETTINGS_WALLET);
}
Expand All @@ -115,7 +120,7 @@ class AddPersonalBankAccountPage extends React.Component {
description={this.props.translate('addPersonalBankAccountPage.successMessage')}
shouldShowButton
buttonText={this.props.translate('common.continue')}
onButtonPress={this.exitFlow}
onButtonPress={() => this.exitFlow(true)}
/>
) : (
<Form
Expand Down
3 changes: 3 additions & 0 deletions src/types/onyx/PersonalBankAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type PersonalBankAccount = {

/** Any reportID we should redirect to at the end of the flow */
exitReportID?: string;

/** The route to redirect after adding PBA successfully */
onSuccessFallbackRoute?: string;
};

export default PersonalBankAccount;
Loading