-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Create a FormAlertWrapper that handles more complex components #9665
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
Conversation
Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers! |
/** Is the button in a loading state */ | ||
isLoading: PropTypes.bool, | ||
/** Submit function */ | ||
onSubmit: PropTypes.func.isRequired, | ||
|
||
...withLocalizePropTypes, |
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 just re-arranged them alphabetically. And removed network
src/components/FormAlertWrapper.js
Outdated
{props.isAlertVisible && ( | ||
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mb3]}> | ||
<Icon src={Expensicons.Exclamation} fill={colors.red} /> | ||
{getAlertPrompt()} |
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 this is an anti-pattern. Anytime you feel the need to do this you should instead:
- Move the rendering to this place
- Create a separate component
Having another method that returns stuff to render is only complicating the render process.
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.
Agree
isAlertVisible: PropTypes.bool.isRequired, | ||
|
||
/** Whether message is in html format */ | ||
isMessageHtml: PropTypes.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.
When would there be a message in HTML?
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.
It looks like it's only used in one spot this.props.reimbursementAccount.errorModalMessage
and I really don't like it. I can live with it, but I don't like it. I don't like that there is a component with a prop that is only used for a single use case. For me, that means we should have a separate component like <FormHTMLAlertWrapper>
.
I would also be extatic if we could make a backend change so that there is no HTML message coming from the server at all. I don't think the server should be responding with HTML.
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'm pretty determined to remove this, but it may take some changes in Secure first. Lets address this after this PR
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.
OK, awesome. Thanks!
src/components/FormAlertWrapper.js
Outdated
|
||
return ( | ||
<View style={[styles.flexRow, styles.ml2, styles.flexWrap, styles.flex1]}> | ||
{error} |
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.
Move all the rendering down here to be in one block. It's really difficult to look at this component and reason about the order things are rendered in.
src/components/FormAlertWrapper.js
Outdated
|
||
return ( | ||
<View style={[styles.mh5, styles.mb5, styles.flex1, styles.justifyContentEnd, ...props.containerStyles]}> | ||
{props.isAlertVisible && ( |
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.
Why is isAlertVisible
here instead of doing an early return at the top of render()
and returning null
? If the alert isn't supposed to be visible, why render the container with nothing in it?
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.
Looks great! Thanks for those changes.
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
@ctkochan22 Does this need to be a PROD PR? |
Was this error not appearing before? @mvtglobally |
@ctkochan22 We were not explicitly testing negative scenarios, so I am not sure if this was appearing before or not. There was a PR in OldDot for this error, i can't find it, but i think @Justicea83 was working on it (if I remember right) |
I'll test it again. But the error looks good and is what the error should look like |
Just tested. The error is working as expected. the Button is a bit off style wise, which is not a blocker and will be addressed in a follow up PR |
🚀 Deployed to production by @roryabraham in version: 1.1.82-5 🚀
|
@Expensify/pullerbear
@tgolen @marcaaron @roryabraham
Create
FormAlertWrapper
component, which allows you to wrap other components. We extract the offline/error-handling functionality fromFormAlertWithSubmitButton
and place it inFormAlertWrapper
.For situations that requires more complex buttons, we can use
FormAlertWrapper
by passing the components in as child props. For more basic buttons, we can still useFormAlertWithSubmitButton
.Example: Button with Icons

This will allow us to work with buttons with icons.
Online
Offline

Example: ButtonWithDropdown

This will also work with
ButtonWithMenu
like in SettlementButton.jsOnline:
Offline:

Fixed Issues
$ #9681
Tests
Uses of
FormAlertWithSubmitButton
AddDebitCardPage
4000000000009995
4000056655665556
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
### Fixed Issues
section aboveTests
sectionQA steps
sectiontoggleReport
and notonIconClick
).src/languages/*
filesSTYLE.md
) were followed/** 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
Follow test steps. The test account number should throw out an error. Verify that it does. For the success case, please add one of your own debit cards.
Screenshots