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

Trim the value when going back on connect bank account #28305

Merged
merged 33 commits into from
Oct 13, 2023

Conversation

dukenv0307
Copy link
Contributor

@dukenv0307 dukenv0307 commented Sep 27, 2023

Details

We use state and value prop to override the draft value that is not trimmed on connect bank account

Fixed Issues

$ #25996
PROPOSAL: #25996 (comment)

Tests

  1. Login with any account
  2. Create a workspace
  3. Go to the workspace and connect bank account
  4. Enter the valid routing number, account number and go to the next step
  5. For each field that can enter the value, enter the valid value with some spacing before
  6. Fill in all other fields and click on save button
  7. After going to the next step click on back button in the header
  8. Verify that all text input values is trimmed
  • Verify that no errors appear in the JS console

Offline tests

No offline test step since bank account flow needs to enable the network

QA Steps

  1. Login with any account
  2. Create a workspace
  3. Go to the workspace and connect bank account
  4. Enter the valid routing number, account number and go to the next step
  5. For each field that can enter the value, enter the valid value with some spacing before
  6. Fill in all other fields and click on save button
  7. After going to the next step click on back button in the header
  8. Verify that all text input values is trimmed
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-09-27.at.13.48.56.mov
Mobile Web - Chrome
Record_2023-09-27-13-55-25.mp4
Mobile Web - Safari
Screen.Recording.2023-09-27.at.14.01.06.mov
Desktop
Screen.Recording.2023-09-27.at.14.13.12.mov
iOS
Screen.Recording.2023-09-27.at.14.10.10.mov
Android
Screen.Recording.2023-09-27.at.16.40.03.mov

@melvin-bot
Copy link

melvin-bot bot commented Sep 27, 2023

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@dukenv0307 dukenv0307 marked this pull request as ready for review September 27, 2023 09:50
@dukenv0307 dukenv0307 requested a review from a team as a code owner September 27, 2023 09:50
@melvin-bot melvin-bot bot requested review from Ollyws and removed request for a team September 27, 2023 09:50
@melvin-bot
Copy link

melvin-bot bot commented Sep 27, 2023

@Ollyws Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@@ -54,6 +54,23 @@ const defaultProps = {
};

function CompanyStep({reimbursementAccount, reimbursementAccountDraft, getDefaultStateForField, onBackButtonPress, translate, session, user, policyID}) {
const defaultWebsite = useMemo(() => (lodashGet(user, 'isFromPublicDomain', false) ? 'https://' : `https://www.${Str.extractEmailDomain(session.email, '')}`), [user, session]);
const [companyInfomation, setCompanyInfomation] = useState({
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: should be ...Information

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@Ollyws
Copy link
Contributor

Ollyws commented Sep 27, 2023

@dukenv0307 A problem here is that the values will use getDefaultStateForField whenever the page has been refreshed.
Ideally we want to only use getDefaultStateForField after the Save & Continue button has been pressed, and otherwise continue using the draft.

@dukenv0307
Copy link
Contributor Author

dukenv0307 commented Sep 27, 2023

A problem here is that the values will use getDefaultStateForField whenever the page has been refreshed.
Ideally we want to only use getDefaultStateForField after the Save & Continue button has been pressed, and otherwise continue using the draft.

@Ollyws I found another solution that can this issue and the problem above and updated it in the PR. We will save data that returns from BE to draft value instead of using state to control the value. That also can fix for personal detail step as well.
Please help to review again.

@Ollyws
Copy link
Contributor

Ollyws commented Sep 27, 2023

Thanks for the changes I like the new approach.

getFieldsOfCurrentStep(currentStep) {
switch (currentStep) {
case CONST.BANK_ACCOUNT.STEP.BANK_ACCOUNT:
return ['routingNumber', 'accountNumber', 'bankName', 'plaidAccountID', 'plaidAccessToken', 'isSavings'];
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like we could be repeating ourselves a bit here, as if someone wanted to add/remove a field they would have to update this list too. Is there any way we could reference the fields in one place?

Copy link
Contributor Author

@dukenv0307 dukenv0307 Sep 27, 2023

Choose a reason for hiding this comment

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

@Ollyws Here are the list values of the step and this is only called after api update success. If we want to update the change field to draft we will need to compare draft value and achData, I think it will take the same amount of time when we merge all fields of the step.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dukenv0307 What I mean is, in RequestorStep for example we already have a list of input IDs could we perhaps use this list instead of creating a new list here, and implement something similar for the other steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The list here is the list that I copied in each step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we create a const for the list and re-use this.

Copy link
Contributor Author

@dukenv0307 dukenv0307 Sep 27, 2023

Choose a reason for hiding this comment

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

I just updated it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dukenv0307 Thanks but I was specifically referring to this list of input IDs, which we could then perhaps get the values of using _.values()? Let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ollyws I see that we only use this in the special form like AddressForm, other fields doesn't use this. So I think we don't need to create the list input key like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok well if we're not going to implement that then I don't really see the need for a const, just to be used for the requiredFields. Could you revert those two commits? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@Ollyws
Copy link
Contributor

Ollyws commented Sep 28, 2023

@dukenv0307 Something I've noticed is if you press the back button while the page is still loading the draft values are never updated:

backbutton_example.mp4
VIDEO

@dukenv0307
Copy link
Contributor Author

@Ollyws I updated.

@melvin-bot melvin-bot bot requested a review from flodnv October 3, 2023 17:16
@flodnv
Copy link
Contributor

flodnv commented Oct 4, 2023

Could you please fill in the Offline tests section?

@@ -57,10 +57,10 @@ function clearOnfidoToken() {

/**
* Helper method to build the Onyx data required during setup of a Verified Business Bank Account
*
* @param {String | undefined} currentStep
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the doc to explain why it's valid to pass undefined and what we should expect to happen in this strange case?

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 updated.

@dukenv0307
Copy link
Contributor Author

No offline test step since bank account flow needs to enable the network

@flodnv Added the note in offline tests. The bank account flow need to enable network to submit form.

@@ -57,7 +57,7 @@ function clearOnfidoToken() {

/**
* Helper method to build the Onyx data required during setup of a Verified Business Bank Account
* @param {String | undefined} currentStep
* @param {String | undefined} currentStep The step that we need to update the data from BE to draft value
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param {String | undefined} currentStep The step that we need to update the data from BE to draft value
* @param {String | undefined} currentStep The step that we need to update the data from backend to draft value

Is this what it means? If yes, let's update it to use the full word, I don't find it necessary to save a few characters. And if yes, I honestly don't really understand the sentence, perhaps you can try rephrasing it?

Also, you did not clarify what happens if you pass undefined?

Copy link
Contributor

@Ollyws Ollyws Oct 4, 2023

Choose a reason for hiding this comment

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

I think something like The name of the step for which we will update the draft value when data has been sucessfully submitted to the backend. would be clearer.

Undefined here is just for the default value currentStep = undefined as far as I'm aware, in which case the draft will not be updated as this condition will be undefined.

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 something like The name of the step for which we will update the draft value when data has been sucessfully submitted to the backend. would be clearer.

Agreed, I do understand this better. Also, can we say "API" instead of "backend", since that's what we use everywhere?

@@ -79,6 +79,10 @@ function getVBBADataForOnyx() {
value: {
isLoading: false,
errors: null,
// The value of some fields of the currentStep are changed i.e. being trimmed or phone number is parsed when backend returns the data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flodnv Updated more explanation here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:

// The value of some fields of the currentStep are changed (i.e. trimmed, or phone number is formatted) when the API returns the data.

@@ -79,6 +79,10 @@ function getVBBADataForOnyx() {
value: {
isLoading: false,
errors: null,
// The value of some fields of the currentStep are changed i.e. being trimmed or phone number is parsed when backend returns the data
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion:

// The value of some fields of the currentStep are changed (i.e. trimmed, or phone number is formatted) when the API returns the data.

@@ -79,6 +79,9 @@ function getVBBADataForOnyx(currentStep = undefined) {
value: {
isLoading: false,
errors: null,
// The value of some fields of the currentStep are changed i.e. being trimmed or phone number is parsed when backend returns the data
// So we need to add this field in successData to update the current data from reimbursement account to the draft value of the form
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sorry, I read this 5 times and I don't understand what it's trying to convey, can you perhaps rephrase it in other words, and with more punctuation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@flodnv Is this more clear?

// In bank account flow, we save the form value to the draft in Onyx. 
// When we update the information in a step, the value of some fields that are updated from backend 
// can be different from the value that we stored to the draft in Onyx (i.e. trimmed, or phone number is formatted).
// So we should store the current step which we call the update API to update the data from backend to the draft in Onyx.
// If currentStep is undefined that means this step don't need to update the data to the draft in Onyx

Copy link
Contributor

Choose a reason for hiding this comment

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

Better, maybe this is even better:

// When setting up a bank account, we save the draft form values in Onyx. 
// When we update the information for a step, the value of some fields that are returned from the API 
// can be different from the value that we stored as the draft in Onyx (i.e. the phone number is formatted).
// This is why we store the current step used to call the API in order to update the corresponding draft data in Onyx.
// If currentStep is undefined that means this step don't need to update the data of the draft in Onyx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to move this to the method's doc

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, maybe yes?

@@ -79,6 +79,9 @@ function getVBBADataForOnyx(currentStep = undefined) {
value: {
isLoading: false,
errors: null,
// The value of some fields of the currentStep are changed i.e. being trimmed or phone number is parsed when backend returns the data
// So we need to add this field in successData to update the current data from reimbursement account to the draft value of the form
// if currentStep is undefined that means the step doesn't need update to the draft
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this in the method's doc?

src/libs/actions/BankAccounts.js Outdated Show resolved Hide resolved
// The value of some fields of the currentStep are changed i.e. being trimmed or phone number is parsed when backend returns the data
// So we need to add this field in successData to update the current data from reimbursement account to the draft value of the form
// if currentStep is undefined that means the step doesn't need update to the draft
stepToUpdateToDraft: currentStep,
Copy link
Contributor

Choose a reason for hiding this comment

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

So why is this called stepToUpdateToDraft and not simply currentStep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already have a field named currentStep in achData of reimbursementAccount

Copy link
Contributor

@flodnv flodnv Oct 6, 2023

Choose a reason for hiding this comment

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

Right... maybe draftStep then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

dukenv0307 and others added 2 commits October 6, 2023 20:09
Co-authored-by: Florent De'Neve <florent@expensify.com>
dukenv0307 and others added 2 commits October 9, 2023 16:07
Co-authored-by: Florent De'Neve <florent@expensify.com>
@dukenv0307
Copy link
Contributor Author

@flodnv Any update here.

@flodnv
Copy link
Contributor

flodnv commented Oct 13, 2023

Sorry, in the future please re-request a review, I filter out commit emails because they're so noisy.

@flodnv flodnv merged commit c9ccae3 into Expensify:main Oct 13, 2023
13 checks passed
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/flodnv in version: 1.3.84-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.3.84-10 🚀

platform result
🤖 android 🤖 skipped 🚫
🖥 desktop 🖥 skipped 🚫
🍎 iOS 🍎 skipped 🚫
🕸 web 🕸 skipped 🚫

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.3.84-10 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/flodnv in version: 1.3.85-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/francoisl in version: 1.3.85-4 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 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