Skip to content

Commit

Permalink
Keep state in onyx
Browse files Browse the repository at this point in the history
  • Loading branch information
Gonals committed Oct 13, 2021
1 parent 48345e7 commit fee575e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/libs/actions/BankAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,19 @@ function fetchUserWallet() {
* Fetch the bank account currently being set up by the user for the free plan if it exists.
*
* @param {String} [stepToOpen]
* @param {Boolean} [hasLocalOpenVBA]
*/
function fetchFreePlanVerifiedBankAccount(stepToOpen) {
function fetchFreePlanVerifiedBankAccount(stepToOpen, hasLocalOpenVBA = false) {
// Remember which account BankAccountStep subStep the user had before so we can set it later
const subStep = lodashGet(reimbursementAccountInSetup, 'subStep', '');
const initialData = {loading: true, error: ''};
if (hasLocalOpenVBA) {
initialData.achData = {state: BankAccount.STATE.OPEN};
}

Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: true, error: ''});
// We are using set here since we will rely on data from the server (not local data) to populate the VBA flow
// and determine which step to navigate to.
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, initialData);
let bankAccountID;

API.Get({
Expand Down
4 changes: 3 additions & 1 deletion src/pages/workspace/WorkspacePageWithSections.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const defaultProps = {

class WorkspacePageWithSections extends React.Component {
componentDidMount() {
fetchFreePlanVerifiedBankAccount();
const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', '');
const hasVBA = achState === BankAccount.STATE.OPEN;
fetchFreePlanVerifiedBankAccount('', hasVBA);
}

render() {
Expand Down

0 comments on commit fee575e

Please sign in to comment.