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

Refactor ReimbursementAccountPage's fetchFreePlanVerifiedBankAccount #11751

Merged
merged 18 commits into from
Nov 10, 2022
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
46 changes: 44 additions & 2 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,47 @@ function validateBankAccount(bankAccountID, validateCode) {
});
}

function openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep) {
const onyxData = {
optimisticData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
errors: null,
isLoading: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

is it this @ctkochan22 ?

Are we stuck in the isLoading state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but upon any sort of completion it should be set to false

},
},
],
successData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
isLoading: false,
},
},
],
failureData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
isLoading: false,
},
},
],
};

const param = {
stepToOpen,
subStep,
localCurrentStep,
};

return API.read('OpenReimbursementAccountPage', param, onyxData);
}

/**
* Updates the bank account in the database with the company step data
*
Expand Down Expand Up @@ -323,12 +364,13 @@ function verifyIdentityForBankAccount(bankAccountID, onfidoData) {

export {
addPersonalBankAccount,
connectBankAccountManually,
clearOnfidoToken,
clearPersonalBankAccount,
clearPlaid,
clearOnfidoToken,
connectBankAccountManually,
connectBankAccountWithPlaid,
deletePaymentBankAccount,
openReimbursementAccountPage,
updateBeneficialOwnersForBankAccount,
updateCompanyInformationForBankAccount,
updatePersonalInformationForBankAccount,
Expand Down
8 changes: 5 additions & 3 deletions src/pages/ReimbursementAccount/ReimbursementAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import getPlaidOAuthReceivedRedirectURI from '../../libs/getPlaidOAuthReceivedRe
import Text from '../../components/Text';
import {withNetwork} from '../../components/OnyxProvider';
import networkPropTypes from '../../components/networkPropTypes';
import * as store from '../../libs/actions/ReimbursementAccount/store';

// Steps
import BankAccountStep from './BankAccountStep';
Expand Down Expand Up @@ -150,9 +151,10 @@ class ReimbursementAccountPage extends React.Component {
// We can specify a step to navigate to by using route params when the component mounts.
// We want to use the same stepToOpen variable when the network state changes because we can be redirected to a different step when the account refreshes.
const stepToOpen = this.getStepToOpenFromRouteParams();

// If we are trying to navigate to `/bank-account/new` and we already have a bank account then don't allow returning to `/new`
BankAccounts.fetchFreePlanVerifiedBankAccount(stepToOpen !== CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT ? stepToOpen : '');
const reimbursementAccount = store.getReimbursementAccountInSetup();
const subStep = reimbursementAccount.subStep || '';
const localCurrentStep = reimbursementAccount.currentStep || '';
BankAccounts.openReimbursementAccountPage(stepToOpen, subStep, localCurrentStep);
}

render() {
Expand Down