Skip to content

Commit

Permalink
Donations Form block: show Stripe notice when not connected (#36841)
Browse files Browse the repository at this point in the history
* Donations blocks: show Stripe nudge when not connected

* changelog

* Show loading spinner or nudge, not both

* Use connectUrl

* Whoops.

* Show Stripe nudge whenever disconnected
  • Loading branch information
mpkelly authored Apr 11, 2024
1 parent b9a8b71 commit 855697d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Dontains Form block: show Stripe nudge if not connected.
14 changes: 13 additions & 1 deletion projects/plugins/jetpack/extensions/blocks/donations/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Spinner } from '@automattic/jetpack-components';
import { useDispatch, useSelect } from '@wordpress/data';
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { StripeNudge } from '../../shared/components/stripe-nudge';
import { SUPPORTED_CURRENCIES } from '../../shared/currencies';
import getConnectUrl from '../../shared/get-connect-url';
import { store as membershipProductsStore } from '../../store/membership-products';
import { STORE_NAME as MEMBERSHIPS_PRODUCTS_STORE } from '../../store/membership-products/constants';
import fetchDefaultProducts from './fetch-default-products';
import fetchStatus from './fetch-status';
Expand All @@ -20,6 +22,11 @@ const Edit = props => {
const { lockPostSaving, unlockPostSaving } = useDispatch( 'core/editor' );
const post = useSelect( select => select( 'core/editor' ).getCurrentPost(), [] );

const stripeConnectUrl = useSelect(
select => select( membershipProductsStore ).getConnectUrl(),
''
);

const { setConnectUrl, setConnectedAccountDefaultCurrency } = useDispatch(
MEMBERSHIPS_PRODUCTS_STORE
);
Expand Down Expand Up @@ -125,9 +132,14 @@ const Edit = props => {
return <LoadingError className={ className } error={ loadingError } />;
}

if ( stripeConnectUrl ) {
// Need to connect Stripe first
return <StripeNudge blockName="donations" />;
}

if ( ! currency ) {
// Memberships settings are still loading
return <Spinner />;
return <Spinner color="black" />;
}

return <Tabs { ...props } products={ products } />;
Expand Down
2 changes: 0 additions & 2 deletions projects/plugins/jetpack/extensions/blocks/donations/tabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback, useEffect, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import classNames from 'classnames';
import { StripeNudge } from '../../shared/components/stripe-nudge';
import Controls from './controls';
import Tab from './tab';

Expand Down Expand Up @@ -54,7 +53,6 @@ const Tabs = props => {

return (
<div className={ className }>
<StripeNudge blockName="donations" />
<div className="donations__container">
{ Object.keys( tabs ).length > 1 && (
<div className="donations__nav">
Expand Down

0 comments on commit 855697d

Please sign in to comment.