-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix: Add payment dynamic #7566
Fix: Add payment dynamic #7566
Conversation
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.
@rushatgabhane @deetergp I've updated, created the base file to make it more DRY. |
src/components/Form.js
Outdated
@@ -122,6 +122,7 @@ class Form extends React.Component { | |||
* @returns {React.Component} | |||
*/ | |||
childrenWrapperWithProps(children) { | |||
// eslint-disable-next-line rulesdir/prefer-underscore-method | |||
return React.Children.map(children, (child) => { |
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 is not related to the issue.
@luacmartins can _.map(children, (child)=>{})
be used here instead?
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.
@rushatgabhane It doesn't pass lint check. I guess it's not a big deal, thus I added it.
Reference: https://reactjs.org/docs/react-api.html#reactchildrenmap
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.
@rushatgabhane great question! React.Children.map
is not equivalent to _.map
, as it's a special method provided to React's children.
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.
Thanks so much!
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.
@phivh Something is off since we added that rule to the linter here - Expensify/eslint-config-expensify#44. Make sure to pull the latest changes on main and run npm install
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.
yeah, it couldn't have been merged to main if it didn't pass the lint 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.
Overall looks good, just requesting some minor changes @phivh
@@ -52,6 +29,9 @@ class KYCWall extends React.Component { | |||
} | |||
|
|||
componentDidMount() { | |||
if (this.props.isResizeListen) { | |||
window.removeEventListener('resize', null); |
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 should be in componentWillUnmount()
/** Where to place the popover */ | ||
popoverPlacement: PropTypes.string, | ||
|
||
/** Is resize event happens on the web/desktop? */ |
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.
Not a blocker: Change the comment to "Listen for window resize event on web and desktop."
popoverPlacement: PropTypes.string, | ||
|
||
/** Is resize event happens on the web/desktop? */ | ||
isResizeListen: 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.
Not a blocker: change the prop name to listenResize
?
* | ||
* @param {Object} position | ||
*/ | ||
|
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.
remove extra new line
formattedSelectedPaymentMethod, | ||
}); | ||
this.setPositionAddPaymentMenu(position); | ||
} else { |
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.
Remove else
and return early in the above if
instead.
/** Are we loading payment methods? */ | ||
isLoadingPaymentMethods: PropTypes.bool, | ||
|
||
/** Is resize event happens on the web/desktop? */ |
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.
Not a blocker: Change the comment to "Listen for window resize event on web and desktop."
isLoadingPaymentMethods: PropTypes.bool, | ||
|
||
/** Is resize event happens on the web/desktop? */ | ||
isResizeListen: 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.
Not a blocker: change the prop name to listenResize?
@@ -178,6 +169,9 @@ class PaymentsPage extends React.Component { | |||
* Hide the add payment modal | |||
*/ | |||
hideAddPaymentMenu() { | |||
if (this.props.isResizeListen) { | |||
window.removeEventListener('resize', null); |
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.
Remove eventListener in hideDefaultDeleteMenu()
too.
KYCWall.propTypes = propTypes; | ||
KYCWall.defaultProps = defaultProps; | ||
KYCWall.displayName = 'KYCWall'; | ||
export default KYCWall; |
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.
New line above export
please
@rushatgabhane 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.
@deetergp LGTM and tests well on all platforms.
import BasePaymentsPage from './BasePaymentsPage'; | ||
|
||
const PaymentsPage = () => ( | ||
<BasePaymentsPage listenResize /> |
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.
Not going to leave a full review here, but please see this draft PR which explains proper usage of boolean props to enable or disable features...
@rushatgabhane please 👀 and thank you 🙇
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.
And applied this would be changed to something like shouldListenForResize
.
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.
Agreed. Let's change it.
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.
Thanks, I agree!
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.
Overall looks good. Just had couple minor changes.
* | ||
* @param {Object} position | ||
*/ | ||
|
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.
Remove line break
import BasePaymentsPage from './BasePaymentsPage'; | ||
|
||
const PaymentsPage = () => ( | ||
<BasePaymentsPage listenResize /> |
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.
Agreed. Let's change it.
@deetergp @rushatgabhane 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 good. Thanks for the changes.
Should we merge it? It might require merging by core team. |
@deetergp feel free to merge this as I don't think neither Marc nor I will leave a full review. |
Thanks, @luacmartins, but I think @rushatgabhane may want to give it another look. If not, I'll merge. |
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.
@deetergp LGTM! 🎉️
No good deed goes unpunished! We've got two approvals, but now we've got a merge conflict. @phivh Once you fix the conflict, I'll re-approve and merge. |
@deetergp I've just updated. Could you please take a look if anything is ok? |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
let clickedElementLocation = getClickedElementLocation(event.nativeEvent); | ||
let position = this.getAnchorPosition(clickedElementLocation); | ||
if (this.props.shouldListenForResize) { | ||
window.addEventListener('resize', () => { |
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, hmm, this is gonna bind a new event listener each time. That can have unintended consequences. The best practice would be to set an event listener once on component init and then clean it up on unmount...
Here's an example of what that looks like using a class component
https://reactjs.org/docs/hooks-effect.html#example-using-classes-1
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.
hmm, we already added a remove listener when the modal close. The scenario is add listener when the modal appears and remove listener when the modal closes.
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.
Please fix this. Here are the instructions...
- add event listeners in
componentDidMount()
- remove event listeners in
componentWillUnmount()
- bind the callbacks they use i.e. don't use an arrow function
Generally speaking even if we are focusing on the web side for consistency we should use the Dimensions
utility. React native web is able to use this.
https://reactnative.dev/docs/0.66/dimensions#addeventlistener
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.
@phivh right now, we're adding a event listener each time the window is resized.
So yeah, let's create a follow-up PR to fix this. 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.
ok, let me take into this one
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.
@marcaaron @deetergp @rushatgabhane created follow-up PR for this one. Please take a look when you guys have a chance.
#7847
Details
Fixed Issues
$ #7385
Tests
QA Steps
Tested On
Screenshots
Web
web.mp4
Mobile Web
NA
Desktop
desktop_app.mp4
iOS
NA
Android
NA