Skip to content

Commit

Permalink
Add loader indication for Stripe notifications banner component (#10398)
Browse files Browse the repository at this point in the history
Co-authored-by: oaratovskyi <[email protected]>
  • Loading branch information
oaratovskyi and oaratovskyi authored Feb 19, 2025
1 parent b1c8328 commit 3eca1b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions changelog/add-10390-stripe-notifications-component-loader
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: add

Add loader indication for Stripe notifications banner component
23 changes: 20 additions & 3 deletions client/overview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
ConnectNotificationBanner,
} from '@stripe/react-connect-js';
import { recordEvent } from 'wcpay/tracks';
import StripeSpinner from 'wcpay/components/stripe-spinner';

const OverviewPageError = () => {
const queryParams = getQuery();
Expand Down Expand Up @@ -94,6 +95,9 @@ const OverviewPage = () => {
setLoadErrorMessage: setStripeNotificationsBannerErrorMessage,
appearance,
} );
const [ stripeComponentLoading, setStripeComponentLoading ] = useState(
true
);

const isTestModeOnboarding = wcpaySettings.testModeOnboarding;
const { isLoading: settingsIsLoading } = useSettings();
Expand Down Expand Up @@ -191,6 +195,7 @@ const OverviewPage = () => {
if ( stripeNotificationsBannerErrorMessage ) {
setShowUpdateDetailsTask( true );
setShowGetVerifyBankAccountTask( true );
setStripeComponentLoading( false );
}
}, [ stripeNotificationsBannerErrorMessage ] );

Expand Down Expand Up @@ -220,6 +225,9 @@ const OverviewPage = () => {
total_count: response.total,
} );
}
// If the component inits successfully, this function is always called.
// It's safe to set the loading false here rather than onLoaderStart, because it happens too early and the UX is not smooth.
setStripeComponentLoading( false );
};

return (
Expand Down Expand Up @@ -270,6 +278,14 @@ const OverviewPage = () => {
<ErrorBoundary>
<Welcome />

{ stripeComponentLoading &&
accountStatus.status !== 'complete' && (
<Card>
<div className="stripe-notifications-banner-loader">
<StripeSpinner />
</div>
</Card>
) }
{ stripeConnectInstance && (
<div
className="stripe-notifications-banner-wrapper"
Expand All @@ -284,12 +300,13 @@ const OverviewPage = () => {
connectInstance={ stripeConnectInstance }
>
<ConnectNotificationBanner
onLoadError={ ( loadError ) =>
onLoadError={ ( loadError ) => {
setStripeNotificationsBannerErrorMessage(
loadError.error.message ||
'Unknown error'
)
}
);
setStripeComponentLoading( false );
} }
collectionOptions={ {
fields: 'eventually_due',
futureRequirements: 'omit',
Expand Down
8 changes: 8 additions & 0 deletions client/overview/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
margin-right: -1px;
}

.stripe-notifications-banner-loader {
width: min( 680px, 90vw ); /* Keeps it 680px max but adapts */
height: 160px;
display: flex;
justify-content: center;
align-items: center;
}

.wcpay-setup-real-payments {
&__body {
display: grid;
Expand Down

0 comments on commit 3eca1b3

Please sign in to comment.