-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Earn: Add a Stripe connect prompt to the Donations block. (#43166)
- Loading branch information
Showing
7 changed files
with
152 additions
and
59 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
apps/full-site-editing/full-site-editing-plugin/donations/donations-tabs.js
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
apps/full-site-editing/full-site-editing-plugin/donations/donations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import StripeNudge from './stripe-nudge'; | ||
|
||
const Donations = ( { stripeConnectUrl } ) => { | ||
const [ activeTab, setActiveTab ] = useState( 'one-time' ); | ||
|
||
const isActive = ( button ) => ( activeTab === button ? 'active' : null ); | ||
|
||
return ( | ||
<div className="donations__container"> | ||
{ stripeConnectUrl && <StripeNudge stripeConnectUrl={ stripeConnectUrl } /> } | ||
<div className="donations__tabs"> | ||
<Button className={ isActive( 'one-time' ) } onClick={ () => setActiveTab( 'one-time' ) }> | ||
{ __( 'One-Time', 'full-site-editing' ) } | ||
</Button> | ||
<Button className={ isActive( 'monthly' ) } onClick={ () => setActiveTab( 'monthly' ) }> | ||
{ __( 'Monthly', 'full-site-editing' ) } | ||
</Button> | ||
<Button className={ isActive( 'annually' ) } onClick={ () => setActiveTab( 'annually' ) }> | ||
{ __( 'Annually', 'full-site-editing' ) } | ||
</Button> | ||
<div | ||
id="donations__tab-one-time" | ||
className={ classNames( 'donations__tab', { active: isActive( 'one-time' ) } ) } | ||
> | ||
{ __( 'One time', 'full-site-editing' ) } | ||
</div> | ||
<div | ||
id="donations__tab-monthly" | ||
className={ classNames( 'donations__tab', { active: isActive( 'monthly' ) } ) } | ||
> | ||
{ __( 'Monthly', 'full-site-editing' ) } | ||
</div> | ||
<div | ||
id="donations__tab-annually" | ||
className={ classNames( 'donations__tab', { active: isActive( 'annually' ) } ) } | ||
> | ||
{ __( 'Annually', 'full-site-editing' ) } | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Donations; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
apps/full-site-editing/full-site-editing-plugin/donations/stripe-nudge.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
// eslint-disable-next-line no-restricted-imports | ||
import { Button, Dashicon } from '@wordpress/components'; | ||
import { Warning } from '@wordpress/block-editor'; | ||
import { compose } from '@wordpress/compose'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { withDispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
const StripeNudge = ( { autosaveAndRedirect, stripeConnectUrl } ) => ( | ||
<Warning | ||
actions={ | ||
// Use href to determine whether or not to display the Upgrade button. | ||
stripeConnectUrl && [ | ||
<Button | ||
key="connect" | ||
href={ stripeConnectUrl } // Only for server-side rendering, since onClick doesn't work there. | ||
onClick={ autosaveAndRedirect } | ||
target="_top" | ||
isDefault | ||
className="premium-content-block-nudge__button stripe-nudge__button" | ||
> | ||
{ __( 'Connect', 'full-site-editing' ) } | ||
</Button>, | ||
] | ||
} | ||
className="donations__nudge premium-content-block-nudge" | ||
> | ||
<span className="donations__nudge-info premium-content-block-nudge__info"> | ||
<Dashicon icon="star-filled" /> | ||
<span className="donations__nudge-text-container premium-content-block-nudge__text-container"> | ||
<span className="donations__nudge-title premium-content-block-nudge__title"> | ||
{ __( 'Connect to Stripe to use this block on your site', 'full-site-editing' ) } | ||
</span> | ||
<span className="donations__nudge-message premium-content-block-nudge__message"> | ||
{ __( | ||
'This block will be hidden from your visitors until you connect to Stripe.', | ||
'full-site-editing' | ||
) } | ||
</span> | ||
</span> | ||
</span> | ||
</Warning> | ||
); | ||
|
||
export default compose( [ | ||
withDispatch( ( dispatch, { stripeConnectUrl } ) => ( { | ||
autosaveAndRedirect: async ( event ) => { | ||
event.preventDefault(); // Don't follow the href before autosaving | ||
await dispatch( 'core/editor' ).savePost(); | ||
// Using window.top to escape from the editor iframe on WordPress.com | ||
window.top.location.href = stripeConnectUrl; | ||
}, | ||
} ) ), | ||
] )( StripeNudge ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-block-donations-stripe-connect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import tracksRecordEvent from './track-record-event'; | ||
|
||
/** | ||
* Return the event definition object to track `wpcom_block_donations_stripe_connect_click `. | ||
* | ||
* @returns {{handler: Function, selector: string, type: string}} event object definition. | ||
*/ | ||
export default () => ( { | ||
selector: '.wp-block[data-type="a8c/donations"] .stripe-nudge__button', | ||
type: 'click', | ||
handler: () => tracksRecordEvent( 'wpcom_block_donations_stripe_connect_click' ), | ||
} ); |