Skip to content

Commit

Permalink
Merge pull request #29847 from getusha/fix-navigate-to-enable-payment
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam authored Oct 18, 2023
2 parents 1d8b6e3 + 5d73a1f commit 843b955
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
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
*/
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;

0 comments on commit 843b955

Please sign in to comment.