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

Fix: Add payment dynamic #7566

Merged
merged 6 commits into from
Feb 11, 2022
Merged

Conversation

phivh
Copy link
Contributor

@phivh phivh commented Feb 4, 2022

Details

  • The menu add payment method doesn't align when resizing the screen width. Thus, added one window listener that observed resize event and re-set position of the menu.

Fixed Issues

$ #7385

Tests

  • Tested by access to the payment page from the setting page.

QA Steps

  • Login on web / desktop app
  • Select profile > payments
  • Select add payment method
  • Change screen width
  • Verify

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

web.mp4

Mobile Web

NA

Desktop

desktop_app.mp4

iOS

NA

Android

NA

@phivh phivh requested a review from a team as a code owner February 4, 2022 16:04
@MelvinBot MelvinBot requested review from deetergp and rushatgabhane and removed request for a team February 4, 2022 16:04
Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

@phivh Yo, let's make this code more DRY.
Only one function is different between index.js and index.native.js file.

You can refer TextInput on how you could achieve this.

@phivh
Copy link
Contributor Author

phivh commented Feb 6, 2022

@rushatgabhane @deetergp I've updated, created the base file to make it more DRY.

@@ -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) => {
Copy link
Member

@rushatgabhane rushatgabhane Feb 6, 2022

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?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks so much!

Copy link
Contributor

@luacmartins luacmartins Feb 7, 2022

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

Copy link
Member

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

Copy link
Member

@rushatgabhane rushatgabhane left a 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);
Copy link
Member

@rushatgabhane rushatgabhane Feb 7, 2022

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? */
Copy link
Member

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,
Copy link
Member

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
*/

Copy link
Member

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 {
Copy link
Member

@rushatgabhane rushatgabhane Feb 7, 2022

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? */
Copy link
Member

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,
Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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

@phivh phivh requested a review from rushatgabhane February 7, 2022 17:02
@phivh
Copy link
Contributor Author

phivh commented Feb 7, 2022

@rushatgabhane updated!

rushatgabhane
rushatgabhane previously approved these changes Feb 7, 2022
Copy link
Member

@rushatgabhane rushatgabhane left a 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 />
Copy link
Contributor

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

#7611

@rushatgabhane please 👀 and thank you 🙇

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, I agree!

Copy link
Contributor

@deetergp deetergp left a 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
*/

Copy link
Contributor

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 />
Copy link
Contributor

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.

@phivh
Copy link
Contributor Author

phivh commented Feb 8, 2022

@deetergp @rushatgabhane updated!

Copy link
Contributor

@deetergp deetergp left a 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.

@phivh
Copy link
Contributor Author

phivh commented Feb 9, 2022

Looks good. Thanks for the changes.

Should we merge it? It might require merging by core team.

@luacmartins
Copy link
Contributor

@deetergp feel free to merge this as I don't think neither Marc nor I will leave a full review.

@deetergp
Copy link
Contributor

deetergp commented Feb 9, 2022

Thanks, @luacmartins, but I think @rushatgabhane may want to give it another look. If not, I'll merge.

Copy link
Member

@rushatgabhane rushatgabhane left a comment

Choose a reason for hiding this comment

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

@deetergp LGTM! 🎉️

@deetergp
Copy link
Contributor

deetergp commented Feb 9, 2022

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.

@phivh
Copy link
Contributor Author

phivh commented Feb 10, 2022

@deetergp I've just updated. Could you please take a look if anything is ok?

@deetergp deetergp merged commit 1898d81 into Expensify:main Feb 11, 2022
@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 @deetergp in version: 1.1.39-0 🚀

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

let clickedElementLocation = getClickedElementLocation(event.nativeEvent);
let position = this.getAnchorPosition(clickedElementLocation);
if (this.props.shouldListenForResize) {
window.addEventListener('resize', () => {
Copy link
Contributor

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

cc @rushatgabhane @deetergp

Copy link
Contributor Author

@phivh phivh Feb 16, 2022

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.

Copy link
Contributor

@marcaaron marcaaron Feb 16, 2022

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

  1. add event listeners in componentDidMount()
  2. remove event listeners in componentWillUnmount()
  3. 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

Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by @timszot in version: 1.1.39-3 🚀

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

6 participants