Save VBA flow information as users type
If you havenβt already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Click on
Get startedin/workspace/<policyID>/cardin New Expensify. - Input information into the fields.
- Close the right pane without clicking on
Save & Continue - Click on
Get startedagain and verify that the information is lost.
More context in this thread and this issue
Expected Result:
A user should see the entered information when reopening the right pane.
Actual Result:
Users loose the information entered.
Workaround:
Retype everything!
Platform:
Where is this issue occurring?
- Web
- iOS
- Android
- Desktop App
- Mobile Web
Version Number: Logs: https://stackoverflow.com/c/expensify/questions/4856 Notes/Photos/Videos: Any additional supporting documentation Expensify/Expensify Issue URL:
@luacmartins Would you mind summarizing the approach here before we start? I'm curious about what the plan will be.
I was thinking of a similar approach we use for the draft comments. On a high level:
- Create a new Onyx key
draftReimbursementAccountwhere we will store all the draft data. - Create a
updateDraftReimbursementAccountfunction that will:- Take a key-value pair as argument, e.g.
updateDraftReimbursementAccount({routingNumber: '1234'}) - Merge that key and value to the
draftReimbursementAccountOnyx key
- Take a key-value pair as argument, e.g.
- Update the
onChangeTexthandlers of each input to also call a debounced version ofupdateDraftReimbursementAccount - Update the state in each step to take in the value stored in the new Onyx key as default, for example in
BankAccountStep.js, update the state:- From
routingNumber: props.achData.routingNumber || '', - To
routingNumber: props.achData.routingNumber || props.draftReimbursementAccount.routingNumber || '',
- From
- We could also delete the related key-value pairs from the Onyx key once the user clicks
Save & Continue
What are your thoughts?
So draftReimbursementAccount is going to collect all the data for the form fields as we enter it and we will just populate the state for each step when there is no achData values.
I think it works. My only concern would be it feels like we are starting to have a lot of state to manage since we'll have:
- draft state (used to populate the component and save changes)
- server state in the
achData(also used to populate the component) - component level state (to track local changes and submit new values)
Is there a reason why we should we decide to use the achData value first and only use the draft value if we don't have achData?
Future us convo: Feels like something we might want to incorporate on a per "form" basis for a more refined form component in the future so that the "draft" feature is opt-in instead of having to be set up. But not sure if that's an optimization we need to worry about now.
Hmmm... That's a good question. The reason that I can think of is if a user has data in the server, but for some reason wipes draftReimbursementAccount (e.g. logs out, resets browser data, etc) we wouldn't display accurate data.
I agree with your concern here and I'm also open to brainstorming other ideas.
As you mentioned, having a form component that keeps track of draft data, as well as input errors would be a great optimization in the future.
The reason that I can think of is if a user has data in the server, but for some reason wipes draftReimbursementAccount (e.g. logs out, resets browser data, etc) we wouldn't display accurate data.
I think you're saying that if a user:
- has begun the flow and gone far enough to save some
achData - then accidentally clears their local storage or signs out
- we would end up with inaccurate data if we prioritized using the draft values over the
achDatavalues
But I think in that case we'd still default to using the achData values since the draft values are empty?
Thinking more on this though... it does seem possible that a user might do something like:
- continue setting up an account that has
achDataset - the user decides to overwrite values with new ones instead
- they then stop in the middle of the flow without saving any of that data to the server
If they restart the flow which values should they expect to see?
But I think in that case we'd still default to using the achData values since the draft values are empty?
Ah I see what you mean. So, we would do something like this?
routingNumber: props.draftReimbursementAccount.routingNumber || props.achData.routingNumber || ''
In that case, what I said before wouldn't be a problem.
If they restart the flow which values should they expect to see?
That's a really good point! We could argue either way. If the user intentionally stops the flow, they would expect to see achData. However, we could also argue that "stop in the middle of the flow" is similar to accidentally closing the right pane and, in that case, if they see achData they would have lost their edits, which is what we are trying to fix here.
@kevinksullivan for additional input in this scenario.
Yeah I think I mostly agree that the user would expect to see whatever they were editing before they got interrupted and not just whatever we managed to save in the server so in that case we'd do:
- try to use the draft first if it exists
- then use the values in
achDataif we have those
π
But one caveat here is that once we've saved that data to the server... it doesn't feel like we'd need the "draft" anymore. Is there some point where we should ever clear those out?
Awesome! I'm on board with always showing the latest draft.
But one caveat here is that once we've saved that data to the server... it doesn't feel like we'd need the "draft" anymore. Is there some point where we should ever clear those out?
I think that would be step 5 from my original approach. We would clear those key/value pairs throughout the flow and finally delete the key when completing the last step.
- We could also delete the related key-value pairs from the Onyx key once the user clicks Save & Continue
:hand: This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.
π Deployed to staging by @marcaaron in version: 1.0.96-1 π
| platform | result |
|---|---|
| π€ android π€ | success β |
| π₯ desktop π₯ | success β |
| π iOS π | success β |
| πΈ web πΈ | success β |
π Deployed to production by @francoisl in version: 1.0.97-0 π
| platform | result |
|---|---|
| π€ android π€ | success β |
| π₯ desktop π₯ | success β |
| π iOS π | success β |
| πΈ web πΈ | success β |
Issue deployed to prod 7 days ago. Closing.