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

Do not always clear Onyx VBA data when accessing workspace sections #5771

Merged
merged 5 commits into from
Oct 13, 2021

Conversation

Gonals
Copy link
Contributor

@Gonals Gonals commented Oct 12, 2021

@MonilBhavsar, @tgolen

I'm not super happy with this solution, so I'm open to suggestions 😬

Fixed Issues

$ #5760

Tests/ QA Steps

  1. On NewDot, Log into an account with no VBA in its free workspace.
  2. Open the workspace and add an OPEN account.
  3. Go to the Workspace->Pay Bills. You should immediately see the option to pay the bills:

Screen Shot 2021-10-12 at 3 25 17 PM

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

@Gonals Gonals requested a review from tgolen October 12, 2021 15:11
@Gonals Gonals self-assigned this Oct 12, 2021
@Gonals Gonals requested a review from a team as a code owner October 12, 2021 15:11
@MelvinBot MelvinBot requested review from MonilBhavsar and removed request for a team October 12, 2021 15:11
// one on the server side, let's make sure we use just the server-side data.
if (hasLocalOpenAccount && lodashGet(achData, 'state', '') !== BankAccount.STATE.OPEN) {
Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, error: ''});
reimbursementAccountInSetup = {};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we do Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: false, error: ''}); on line 348, it happens before reimbursementAccountInSetup is set, so it never gets populated. In this case, we need to clear it manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think my first question is.... why are we using Onyx.set() here and above instead of Onyx.merge()? If there is no reason for it, then I think we should just use merge() in both places and then I don't think you need any of the changes to the signature of fetchFreePlanVerifiedBankAccount()

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just use merge() in both places

Correction: I mean, I think we can just use merge() above, and that's the only change this PR needs to make.

Copy link
Contributor Author

@Gonals Gonals Oct 12, 2021

Choose a reason for hiding this comment

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

If we use merge and the bank account has been deleted on the server side (but still remains in Onyx), it will remain in Oxyx instead of getting cleared out. Handling this situation was the annoying part of the issue 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

How often would we expect that case to actually happen? Is that really a valid flow?

Copy link
Contributor Author

@Gonals Gonals Oct 12, 2021

Choose a reason for hiding this comment

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

I don't expect it to happen often at all. It can easily happen by deleting the bank account from oldDot, though.
Even not counting that flow, though I am not sure about using merge all the time. This function is used in bank account setup and I worry using merge in that flow will cause unwanted behavior (after all, the comments do mention we are using set specifically and consciously.

If we don't worry about the deleted bank account situation, though, we could get rid of this part and just have the set/merge split at the top.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I saw the comment for the original set:

We are using set here since we will rely on data from the server (not local data) to populate the VBA flow

I don't know that this is really the desired behavior. This is making the app the opposite of offline-first. I think we should be fine rendering whatever is in Onyx, and then load new data on top of whatever is already there. Thinking about the setup flow, if the UI was showing what was in Onyx already, then why wouldn't it be OK to keep showing it when you're offline? I would try merge() and just verify it doesn't change anything about the VBA flow.

Regarding the delete account flow, I spoke with you 1:1 to make sure I had the full context around that and I don't think it is a flow we should worry about right now because it's a very edge case. The proper solution for handling the bank account deletion is to implement a pusher event just like we do when a new action is added to a report.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. I have been doing some testing on the VBA flow with merge and I haven't noticed any issues/differences. Let's move ahead with it, then!

tgolen
tgolen previously approved these changes Oct 12, 2021
@tgolen tgolen requested review from marcaaron and removed request for MonilBhavsar October 12, 2021 16:29
@github-actions
Copy link
Contributor

⚠️ ⚠️ Heads up! This pull request has the CP Staging label. ⚠️ ⚠️
Merging it will cause it to be immediately deployed to staging, even if the open StagingDeployCash deploy checklist is locked.

@marcaaron
Copy link
Contributor

I'm trying to think of a way we can do this without altering the logic in a flow that is mostly working OK. This change makes me a little uncomfortable as there may be other places that depend on the "reset" logic.

@marcaaron
Copy link
Contributor

Another way to look at this problem is that we are displaying options while we are still "loading" some information we need to determine which option to show. So, a safer move at this stage of the game might be to hold showing these option until loading is finished.

@Gonals
Copy link
Contributor Author

Gonals commented Oct 12, 2021

Another way to look at this problem is that we are displaying options while we are still "loading" some information we need to determine which option to show. So, a safer move at this stage of the game might be to hold showing these option until loading is finished.

You can take a look at my previous commit. You might like it better :)

@marcaaron
Copy link
Contributor

The solution I had in mind is to only render the children if we have reimbursementAccount.loading == false

{this.props.children(hasVBA, policyID, isUsingECard)}

Otherwise we are passing hasVBA with a value that might not be correct until we are done loading.

@tgolen
Copy link
Contributor

tgolen commented Oct 12, 2021

I think this boils down to:

Can we display something in Onyx that may or may not be stale?

I think that almost everywhere else in the app we have decided that this is OK to do that. We show what's in Onyx, and then we update it silently in the background (think of the network reconnection logic).

So, there isn't anything about this case which makes me think that we should treat it differently, but this is possibly where I am open to reason.

@marcaaron
Copy link
Contributor

I think that almost everywhere else in the app we have decided that this is OK to do that
So, there isn't anything about this case which makes me think that we should treat it differently, but this is possibly where I am open to reason.

Only thing I can add is that this feature was not implemented with that idea in mind and the interactions with local data and API are fairly complex in comparison to other simpler flows in the app. That's not to say we can't change how it works, but I think that's something that should have been established in the design stage.

@marcaaron
Copy link
Contributor

Did a quick test and found a couple of things that aren't working correctly. I'll continue testing and help find other issues if these are not decided to be blockers or we want to find solutions to them.

Issue 1 - Unexpectedly dropped into the company step flow

Repro steps:

  1. Create a new account + workspace
  2. Select Plaid option
  3. Advance to the Company Step
  4. Bail on the flow, refresh the page, and reopen it again

Expected:
User is brought back to the BankAccountStep since a bank account is not officially created until they get past the CompanyStep

Actual:
User lands in the CompanyStep again

Issue 2 - Error messages persist on page refresh

Repro steps:

  1. Create a new account + workspace
  2. Select Plaid option
  3. Advance to the Company Step + submit with no information
  4. Bail on the flow, refresh the page, and reopen it again

Expected:
Next time user lands on this flow error messages are cleared

Actual:
Error messages persist page refresh

Copy link
Contributor

@marcaaron marcaaron left a comment

Choose a reason for hiding this comment

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

Not sure about the first issue found above. Maybe it's not a blocker if everything works OK? I only tested that the behavior changed. But I think the errors should clear if we are visiting a flow again so I would request we come up with a solution to that new problem introduced.

// 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, {loading: true, error: ''});
Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {loading: true, error: ''});
Copy link
Contributor

Choose a reason for hiding this comment

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

Kinda want to propose a less risky change here. Here's how it goes...

Since the /bank-account flow may be expecting multiple fields to be "reset" before we fetch the bank account then we should try to only carry over the state that we need for now.

I think to solve the current issue we could do something like:

const initialData = {loading: true, error: ''};
const state = lodashGet(reimbursementAccountInSetup, 'achData.state');

if (state === BankAccount.STATE.OPEN) {
    initialData.achData = {state: BankAccount.STATE.OPEN};
}

Onyx.set(ONYXKEYS.REIMBURSEMENT_ACCOUNT, initialData);

Copy link
Contributor Author

@Gonals Gonals Oct 13, 2021

Choose a reason for hiding this comment

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

I think this is a pretty good solution, as it shouldn't affect the add bank account flow, which was my main worry with the current one. However, it won't work as-is. At this point, reimbursementAccountInSetup is still empty, so there's no state there.
We can either pass a flag from WorspacePageWithSections, as I was doing before, or do an Onyx.connect. I think the first option might be better, but I can go for either. Any preference @marcaaron?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've pushed changes for solution #1 (with the flag). LMK what you think

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah bummer sounds like a good case for Onyx.isInitialized() if it existed 😄

@marcaaron marcaaron merged commit d61248f into main Oct 13, 2021
@marcaaron marcaaron deleted the alberto-workspaceSections branch October 13, 2021 17:43
github-actions bot pushed a commit that referenced this pull request Oct 13, 2021
Do not always clear Onyx VBA data when accessing workspace sections

(cherry picked from commit d61248f)
@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by @marcaaron in version: 1.1.7-7 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @AndrewGable in version: 1.1.7-24 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.1.7-25 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @roryabraham in version: 1.1.8-9 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants