-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
refactored BasePaymentsPage to function based component #22412
Conversation
@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] |
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
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]); |
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 this should be a callback?
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 could keep the function block alone, call it from useEffect for network/ changes and debounced Method
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.
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?
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.
Let it be, fine as it is!
…to 16287_refactor_BasePaymentsPage
Hi, @Santhosh-Sellavel |
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
…to 16287_refactor_BasePaymentsPage
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.
Can you please update useLocalize instead of withLocalizeHoc
also use useWindowDimensions instead of withDimensionHOC
useEffect(() => { | ||
// If the user was previously offline, skip debouncing showing the loader | ||
if (!props.network.isOffline) { | ||
updateShouldShowLoadingSpinner(); |
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 use useOnNetworkReconnect
hook and simplify this further
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.
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.
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.
Let me check this
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.
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.
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, 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.
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 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.
Sorry @multijump I missed submitting this yesterday! |
…to 16287_refactor_BasePaymentsPage
…sions instead of withDimensionHOC
Hi @Santhosh-Sellavel |
Hi, @Santhosh-Sellavel |
Can you please resolve conflicts |
Hi, @MonilBhavsar |
Sorry, could you please describe the test. Sorry, what is hovering off over the button triggering? |
@MonilBhavsar While offline, the payment button should be disabled. |
Actually, the wallet is hidden behind the beta. So they might have missed it. Offline Steps:
Does this look good for you @MonilBhavsar ? |
cc: @multijump Please update the steps thanks! |
Yes, that works for me. Thanks! Can we also please test it |
bump @multijump |
I've already tested this, worked well! |
Sorry for late @Santhosh-Sellavel |
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.
Thank you! 🚀
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
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()} |
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.
@multijump Here is the problem, it should be
onPress={navigateToAddPaypalRoute}
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 create a follow-up PR soon, 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.
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.
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.48-0 🚀
|
// 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)) { |
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.
Permissions.canUsePasswordlessLogins
was removed in #22461
🚀 Deployed to production by https://github.com/puneetlath in version: 1.3.48-5 🚀
|
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 1.3.49-0 🚀
|
🚀 Deployed to production by https://github.com/Beamanator in version: 1.3.49-3 🚀
|
} | ||
|
||
BasePaymentsPage.propTypes = propTypes; | ||
BasePaymentsPage.defaultProps = defaultProps; | ||
BasePaymentsPage.displayName = BasePaymentsPage; |
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.
There was a typo here. It should have been 'BasePaymentsPage'
.
And later it caused this regression.
useEffect(() => { | ||
PaymentMethods.openPaymentsPage(); | ||
}, []); |
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 useEffect
wasn't needed here, since another useEffect
below triggers PaymentMethods.openWalletPage()
It caused #45754
Details
Migrate BasePaymentsPage to function based component
Fixed Issues
$ #16287
PROPOSAL: #16287 (comment)
Tests
Should be enabled Add Payments Method button and showed the added payment methods
Offline tests
QA Steps
Follow the same steps listed in the section above.
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
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)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.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