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

refactored BasePaymentsPage to function based component #22412

Merged
merged 30 commits into from
Jul 28, 2023

Conversation

multijump
Copy link
Contributor

@multijump multijump commented Jul 7, 2023

Details

Migrate BasePaymentsPage to function based component

Fixed Issues

$ #16287
PROPOSAL: #16287 (comment)

Tests

  1. Click the Settings
  2. Click the Payments
    Should be enabled Add Payments Method button and showed the added payment methods
  • Verify that no errors appear in the JS console

Offline tests

  1. Open Setting Page
  2. Go Offline
  3. Verify wallet balance & Add Payment button is disabled
  4. Go Online
  5. Verify Loading is shown for wallet balance and right balance is updated
  6. Verify Add Payment button is enabled

QA Steps

Follow the same steps listed in the section above.

  • 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 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
Chrome.mov
Mobile Web - Chrome
Android-chrome.mov
Mobile Web - Safari
iOS-safari.mov
Desktop
Desktop.mov
iOS
iOS.mov
Android
Android.mov

@multijump multijump requested a review from a team as a code owner July 7, 2023 13:25
@melvin-bot melvin-bot bot requested review from Santhosh-Sellavel and removed request for a team July 7, 2023 13:25
@melvin-bot
Copy link

melvin-bot bot commented Jul 7, 2023

@Santhosh-Sellavel 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]

Comment on lines +63 to +69
const updateShouldShowLoadingSpinner = useCallback(() => {
// In order to prevent a loop, only update state of the spinner if there is a change
const showLoadingSpinner = props.isLoadingPaymentMethods || false;
if (showLoadingSpinner !== shouldShowLoadingSpinner) {
setShouldShowLoadingSpinner(props.isLoadingPaymentMethods && !props.network.isOffline);
}
}, [props.isLoadingPaymentMethods, props.network.isOffline, shouldShowLoadingSpinner]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this should be a callback?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could keep the function block alone, call it from useEffect for network/ changes and debounced Method

Copy link
Contributor Author

@multijump multijump Jul 11, 2023

Choose a reason for hiding this comment

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

Hi, @Santhosh-Sellavel
updateShouldShowLoadingSpinner and debounceSetShouldShowLoadingSpinner is called by here useEffect.

    useEffect(() => {
        // If the user was previously offline, skip debouncing showing the loader
        if (!props.network.isOffline) {
            updateShouldShowLoadingSpinner();
        } else {
            debounceSetShouldShowLoadingSpinner();
        }
    }, [props.network.isOffline, debounceSetShouldShowLoadingSpinner, updateShouldShowLoadingSpinner]);

As you can see, whenever isOffline was changed, useEffect calls different function.
And updateShouldShowLoadingSpinner has props variables like isLoadingPaymentMethods and isOffline and these variables takes part to set state in component.
So I thought it will be good to wrap in useCallback because updateShouldShowLoadingSpinner can be stacked/called to the memory multiple times whenever change isLoadingPaymentMethods and isOffline in props.

If you want to move updateShouldShowLoadingSpinner's body to move to useEffect directly, I will update it.
What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let it be, fine as it is!

@multijump
Copy link
Contributor Author

Hi, @Santhosh-Sellavel
Can you please check my comment?

Copy link
Collaborator

@Santhosh-Sellavel Santhosh-Sellavel left a comment

Choose a reason for hiding this comment

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

Can you please update useLocalize instead of withLocalizeHoc also use useWindowDimensions instead of withDimensionHOC

Comment on lines +341 to +344
useEffect(() => {
// If the user was previously offline, skip debouncing showing the loader
if (!props.network.isOffline) {
updateShouldShowLoadingSpinner();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use useOnNetworkReconnect hook and simplify this further

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @Santhosh-Sellavel
But we need to run a little different function per isOffline.

    useEffect(() => {
        // If the user was previously offline, skip debouncing showing the loader
        if (!props.network.isOffline) {
            updateShouldShowLoadingSpinner();
        } else {
            debounceSetShouldShowLoadingSpinner();
        }
    }, [props.network.isOffline, debounceSetShouldShowLoadingSpinner, updateShouldShowLoadingSpinner]);

As you can see, even though debounceSetShouldShowLoadingSpinner is the debounced function of updateShouldShowLoadingSpinner, they are different functions.
We need to run these different functions per network condition.
So it is some difficult to use useOnNetworkReconnect instead above useEffect.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let me check this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Alright, when do you think debounceSetShouldShowLoadingSpinner method will be called?

How do you confirm whether the user was offline or not by using the current prop?

As this effect can be triggered by changing anyone of the setLoading callbacks too right? The other callbacks does not depends upon props.network alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, debounceSetShouldShowLoadingSpinner will be called when network is offline.
any other callbacks doesn't depends on props.network.
And this effect can be triggered by only network change.

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 we should add offline test for this.
Theoretically, It should work, but looks like we haven't tested it, or we do't have offline test step for this case.

@Santhosh-Sellavel
Copy link
Collaborator

Sorry @multijump I missed submitting this yesterday!

@multijump
Copy link
Contributor Author

Hi @Santhosh-Sellavel
I just updated the useLocalize instead of withLocalizeHoc also use useWindowDimensions instead of withDimensionHOC.
Please check.

@multijump
Copy link
Contributor Author

Sorry @multijump I missed submitting this yesterday!

Hi, @Santhosh-Sellavel
Can you please consider my explains again?

@Santhosh-Sellavel
Copy link
Collaborator

Can you please resolve conflicts

@multijump
Copy link
Contributor Author

@MonilBhavsar
Copy link
Contributor

Sorry, could you please describe the test. Sorry, what is hovering off over the button triggering?

@Santhosh-Sellavel
Copy link
Collaborator

@MonilBhavsar While offline, the payment button should be disabled.

@Santhosh-Sellavel
Copy link
Collaborator

Actually, the wallet is hidden behind the beta. So they might have missed it.

Offline Steps:

  1. Open Setting Page
  2. Go Offline
  3. Verify wallet balance & Add Payment button is disabled
  4. Go Online
  5. Verify Loading is shown for wallet balance and right balance is updated
  6. Verify Add Payment button is enabled

Does this look good for you @MonilBhavsar ?

@Santhosh-Sellavel
Copy link
Collaborator

cc: @multijump Please update the steps thanks!

@MonilBhavsar
Copy link
Contributor

Yes, that works for me. Thanks! Can we also please test it

@Santhosh-Sellavel
Copy link
Collaborator

cc: @multijump Please update the steps thanks!

bump @multijump

@Santhosh-Sellavel
Copy link
Collaborator

Yes, that works for me. Thanks! Can we also please test it

I've already tested this, worked well!

@multijump
Copy link
Contributor Author

cc: @multijump Please update the steps thanks!

Sorry for late @Santhosh-Sellavel
I updated the offline test steps.
And I can test only payment button disabled.
attached screen record for it.
Thanks.
https://github.com/Expensify/App/assets/35476479/8675d30e-60ba-4fe1-89fb-53790517ca5a

Copy link
Contributor

@MonilBhavsar MonilBhavsar left a comment

Choose a reason for hiding this comment

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

Thank you! 🚀

@MonilBhavsar MonilBhavsar merged commit b2381f6 into Expensify:main Jul 28, 2023
@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.

@MonilBhavsar
Copy link
Contributor

Looks like we have a regression. @multijump could you please comment in this slack thread https://expensify.slack.com/archives/C049HHMV9SM/p1690547253119529?thread_ts=1690546771.892759&cid=C049HHMV9SM

)}
{isPayPalMeSelected && (
<Button
onPress={navigateToAddPaypalRoute()}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@multijump Here is the problem, it should be

onPress={navigateToAddPaypalRoute}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please create a follow-up PR soon, 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.

Hi, @Santhosh-Sellavel
Sorry for issue.
I just created followup PR
#23816
But I couldn't record screen because paypal button didn't appear in my dev env.
Can you please let me know how can I add paypal button?
I will test and record screen.
Thanks.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.48-0 🚀

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

// InteractionManager fires after the currently running animation is completed.
// https://github.com/Expensify/App/issues/7768#issuecomment-1044879541
InteractionManager.runAfterInteractions(() => {
if (Permissions.canUsePasswordlessLogins(props.betas)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Permissions.canUsePasswordlessLogins was removed in #22461

@OSBotify
Copy link
Contributor

OSBotify commented Aug 2, 2023

🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.48-5 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Aug 2, 2023

🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.49-0 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Aug 3, 2023

🚀 Deployed to production by https://github.com/Beamanator in version: 1.3.49-3 🚀

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

}

BasePaymentsPage.propTypes = propTypes;
BasePaymentsPage.defaultProps = defaultProps;
BasePaymentsPage.displayName = BasePaymentsPage;
Copy link
Contributor

Choose a reason for hiding this comment

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

There was a typo here. It should have been 'BasePaymentsPage'.
And later it caused this regression.

Comment on lines +323 to +325
useEffect(() => {
PaymentMethods.openPaymentsPage();
}, []);
Copy link
Member

@thesahindia thesahindia Aug 2, 2024

Choose a reason for hiding this comment

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

This useEffect wasn't needed here, since another useEffect below triggers PaymentMethods.openWalletPage()
It caused #45754

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.

7 participants