-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 AddPersonalBankAccount to use Form #11076
Conversation
Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers! |
@@ -163,7 +122,14 @@ class AddPersonalBankAccountPage extends React.Component { | |||
</FixedFooter> | |||
</> | |||
) : ( | |||
<FormScrollView> | |||
<Form | |||
formID={ONYXKEYS.PERSONAL_BANK_ACCOUNT} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this already exists, but I'm hazy on how the form IDs work - would it make more sense to add a new ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT
to separate it out from the key for the value itself?
Otherwise this is looking good when I skimmed; I will look closer and also test tomorrow!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes one of the reasons I didn't wanna move the key under FORMS
is that there are other external PRs ongoing that touch the same keys so we figured out that we'll keep keys as they are now and then once everything is merged we'll move the keys under the FORMS
key. But I'm gonna double check in case this specific key is only used here then I can move it under FORMS
. Good eye!
Hey so I tested this on web and it seems good EXCEPT when I put in an incorrect password, there's no feedback - the button acts as if it's clicked but immediately returns to the same text, no error visible. Putting in the correct password works as expected. Is there any other branch I need to check out locally other than this one (e.g. something in Web-E or otherwise) to make this work? Let me know! |
Oh it looks like I need to refactor |
Updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, and errors work now! Can you add testing steps into the overview (just write out what the video shows)? Then I can fill out that other checklist and get this merged, unless @luacmartins has any further notes.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Couple of minor comments.
*/ | ||
validate() { | ||
validate(values) { | ||
const errors = {}; | ||
if (_.isUndefined(this.state.selectedPlaidBankAccount)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to validate selectedPlaidBankAccount
if it doesn't have an inputID and we hide the submit button if no value is selected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I'll remove it.
const errors = {}; | ||
if (_.isUndefined(this.state.selectedPlaidBankAccount)) { | ||
errors.selectedBank = true; | ||
} | ||
|
||
if (this.props.isPasswordRequired && _.isEmpty(this.state.password)) { | ||
if (this.props.isPasswordRequired && _.isEmpty(values.password)) { | ||
errors.password = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to convert this error to a translated error string instead of bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like isPasswordRequired
is undefined
, so code inside will never run. I think we only wanna show an error if the pasword is empty? Display something like "This field is required"? Or is the backend error enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh if we don't require a password to add a personal bank account, we don't need to validate it in the front-end either. We could just remove this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is required to add a personal bank account. But for some reason we never set isPasswordRequired
to true. Because if you send an empty password the backend sends back an "invalid password" error. I can either remove the check and rely on the backend, or add a check to validate the field is not empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The password field is required, so I think that we can remove mentions to that prop and:
- Add a check for empty password
- Add check for invalid password
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Add check for [invalid password]
I think we're asking the user there to input their existing password? So it should already be valid, unless it's incorrect then the backend will handle that case. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's fine too. I don't have strong feelings about 2. We should still update the validate method to account for an empty password and remove the check for selectedPlaidBankAccount
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youssef-lr any updates regarding my comment above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it, sorry! Was OOO (sick).
Also the PR title and linked issue mention AddPlaidBankAccount, but the refactored page is AddPersonalBankAccount page 😬 |
Yes I realize this 😁 I'm not really sue what to refactor inside of AddPlaidBankAccount, any insights? As for AddPersonalBankAccount, I refactored it because you mentioned it in this comment. Let me know what needs to be done in Should I change this issue title? Or create separate issue for it and link to it here? |
I think just changing the issue title and mentioning that comment in the original post is enough. As for the refactor in AddPlaidBankAccount, that comment points to this part |
Updated and added tests! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onSubmit={this.submit} | ||
validate={this.validate} | ||
style={[styles.mh5, styles.mb5, styles.flex1]} | ||
> | ||
<View style={[styles.mh5, styles.mb5, styles.flex1]}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This View is duplicating the styles applied by Form. I think we should just make it a fragment.
<View style={[styles.mh5, styles.mb5, styles.flex1]}> | |
<> |
autoCompleteType="password" | ||
textContentType="password" | ||
autoCapitalize="none" | ||
autoFocus={canFocusInputOnScreenFocus()} | ||
onChangeText={text => this.setState({password: text})} | ||
errorText={this.getErrorText('password')} | ||
hasError={this.getErrors().password} | ||
/> | ||
</View> | ||
)} | ||
</View> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</View> | |
</> |
@@ -177,30 +140,18 @@ class AddPersonalBankAccountPage extends React.Component { | |||
{!_.isUndefined(this.state.selectedPlaidBankAccount) && ( | |||
<View style={[styles.mb5]}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this view
<View style={[styles.mb5]}> |
autoCompleteType="password" | ||
textContentType="password" | ||
autoCapitalize="none" | ||
autoFocus={canFocusInputOnScreenFocus()} | ||
onChangeText={text => this.setState({password: text})} | ||
errorText={this.getErrorText('password')} | ||
hasError={this.getErrors().password} | ||
/> | ||
</View> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</View> |
submitButtonText={this.props.translate('common.saveAndContinue')} | ||
onSubmit={this.submit} | ||
validate={this.validate} | ||
style={[styles.mh5, styles.mb5, styles.flex1]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the extra bottom margin
style={[styles.mh5, styles.mb5, styles.flex1]} | |
style={[styles.mh5, styles.flex1]} |
Updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
✋ 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 @luacmartins in version: 1.2.13-0 🚀
|
Tested, it works! Checking off ✅ |
🚀 Deployed to production by @yuwenmemon in version: 1.2.13-5 🚀
|
…dplaidaccount_form Refactor AddPersonalBankAccount to use Form
Details
cc @luacmartins
Fixed Issues
$ #9577
Tests and QA
Password is a required field
error is show.Incorrect password
is shown above the submit button.PR Review Checklist
Contributor (PR Author) Checklist
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)PR Reviewer Checklist
The Contributor+ will copy/paste it into a new comment and complete it after the author checklist is completed
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
have been tested & I retested again)/** comment above it */
displayName
propertythis
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)QA Steps
Screenshots
Web
Screen.Recording.2022-09-22.at.22.38.24.mov
Mobile Web
Desktop
iOS
Android