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

Payments Block: Remove upgrade nudges when used in Premium Content block #17702

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 132 additions & 105 deletions extensions/blocks/recurring-payments/edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class MembershipsButtonEdit extends Component {
this.hasUpgradeNudge =
! recurringPaymentsAvailability.available &&
recurringPaymentsAvailability.unavailableReason === 'missing_plan';

this.isPremiumContentChild = this.props.context.isPremiumContentChild || false;
}

componentDidMount = () => {
Expand Down Expand Up @@ -343,7 +345,8 @@ class MembershipsButtonEdit extends Component {
const defaultTextForCurrentPlan = currentPlanId
? this.getFormattedPriceByProductId( currentPlanId ) + __( ' Contribution', 'jetpack' )
: undefined;
if ( innerButtons.length ) {

if ( innerButtons && innerButtons.length ) {
innerButtons[ 0 ].innerBlocks.forEach( block => {
const currentText = block.attributes.text;
const text =
Expand Down Expand Up @@ -371,9 +374,118 @@ class MembershipsButtonEdit extends Component {
</div>
);

render = () => {
renderDisclaimer = () => {
return (
<div className="membership-button__disclaimer">
<ExternalLink href="https://wordpress.com/support/wordpress-editor/blocks/payments/#related-fees">
{ __( 'Read more about Payments and related fees.', 'jetpack' ) }
</ExternalLink>
</div>
);
};

renderUpgradeNudges = () => {
apeatling marked this conversation as resolved.
Show resolved Hide resolved
const { notices, postId } = this.props;
const { connected, connectURL, products } = this.state;
const { connected, connectURL } = this.state;

return (
<>
apeatling marked this conversation as resolved.
Show resolved Hide resolved
{ ! this.hasUpgradeNudge &&
! this.state.shouldUpgrade &&
connected === API_STATE_NOTCONNECTED && (
<StripeNudge
blockName="recurring-payments"
postId={ postId }
stripeConnectUrl={ connectURL }
/>
) }
{ ! this.hasUpgradeNudge && this.state.shouldUpgrade && (
<div className="wp-block-jetpack-recurring-payments">
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Payments', 'jetpack' ) }
notices={ notices }
instructions={ __(
"You'll need to upgrade your plan to use the Payments block.",
'jetpack'
) }
>
<Button isSecondary isLarge href={ this.state.upgradeURL } target="_blank">
{ __( 'Upgrade your plan', 'jetpack' ) }
</Button>
{ this.renderDisclaimer() }
</Placeholder>
</div>
) }
</>
);
}

renderPlanNotices = () => {
const { notices } = this.props;
const { connected, products } = this.state;

return (
<>
{ ( connected === API_STATE_LOADING ||
this.state.addingMembershipAmount === PRODUCT_FORM_SUBMITTED ) &&
! this.props.attributes.planId && (
<Placeholder icon={ <BlockIcon icon={ icon } /> } notices={ notices }>
<Spinner />
</Placeholder>
) }
{ ! this.state.shouldUpgrade &&
! this.props.attributes.planId &&
connected === API_STATE_CONNECTED &&
products.length === 0 && (
<div className="wp-block-jetpack-recurring-payments">
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Payments', 'jetpack' ) }
notices={ notices }
>
<div className="components-placeholder__instructions">
<p>
{ __( 'To use this block, first add at least one payment plan.', 'jetpack' ) }
</p>
{ this.renderAddMembershipAmount( true ) }
{ this.renderDisclaimer() }
</div>
</Placeholder>
</div>
) }
{ ! this.state.shouldUpgrade &&
! this.props.attributes.planId &&
this.state.addingMembershipAmount !== PRODUCT_FORM_SUBMITTED &&
connected === API_STATE_CONNECTED &&
products.length > 0 && (
<div className="wp-block-jetpack-recurring-payments">
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Payments', 'jetpack' ) }
notices={ notices }
>
<div className="components-placeholder__instructions">
<p>
{ __(
'To use this block, select a previously created payment plan.',
'jetpack'
) }
</p>
{ this.renderMembershipAmounts() }
<p>{ __( 'Or a new one.', 'jetpack' ) }</p>
{ this.renderAddMembershipAmount( false ) }
{ this.renderDisclaimer() }
</div>
</Placeholder>
</div>
) }
</>
);
};

render = () => {
const { products } = this.state;

/**
* Filters the flag that determines if the Recurring Payments block controls should be shown in the inspector.
Expand Down Expand Up @@ -412,116 +524,31 @@ class MembershipsButtonEdit extends Component {
return (
<Fragment>
{ this.props.noticeUI }
{ ! this.hasUpgradeNudge &&
! this.state.shouldUpgrade &&
connected === API_STATE_NOTCONNECTED && (
<StripeNudge
blockName="recurring-payments"
postId={ postId }
stripeConnectUrl={ connectURL }
/>
) }
{ ! this.hasUpgradeNudge && this.state.shouldUpgrade && (
<div className="wp-block-jetpack-recurring-payments">
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Payments', 'jetpack' ) }
notices={ notices }
instructions={ __(
"You'll need to upgrade your plan to use the Payments block.",
'jetpack'
) }
>
<Button isSecondary isLarge href={ this.state.upgradeURL } target="_blank">
{ __( 'Upgrade your plan', 'jetpack' ) }
</Button>
</Placeholder>
</div>
) }
{ ( connected === API_STATE_LOADING ||
this.state.addingMembershipAmount === PRODUCT_FORM_SUBMITTED ) &&
! this.props.attributes.planId && (
<Placeholder icon={ <BlockIcon icon={ icon } /> } notices={ notices }>
<Spinner />
</Placeholder>
) }
{ ! this.state.shouldUpgrade &&
! this.props.attributes.planId &&
connected === API_STATE_CONNECTED &&
products.length === 0 && (
<div className="wp-block-jetpack-recurring-payments">
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Payments', 'jetpack' ) }
notices={ notices }
>
<div className="components-placeholder__instructions">
<p>
{ __( 'To use this block, first add at least one payment plan.', 'jetpack' ) }
</p>
{ this.renderAddMembershipAmount( true ) }
</div>
</Placeholder>
</div>
) }
{ ! this.state.shouldUpgrade &&
! this.props.attributes.planId &&
this.state.addingMembershipAmount !== PRODUCT_FORM_SUBMITTED &&
connected === API_STATE_CONNECTED &&
products.length > 0 && (
<div className="wp-block-jetpack-recurring-payments">
<Placeholder
icon={ <BlockIcon icon={ icon } /> }
label={ __( 'Payments', 'jetpack' ) }
notices={ notices }
>
<div className="components-placeholder__instructions">
<p>
{ __(
'To use this block, select a previously created payment plan.',
'jetpack'
) }
</p>
{ this.renderMembershipAmounts() }
<p>{ __( 'Or a new one.', 'jetpack' ) }</p>
{ this.renderAddMembershipAmount( false ) }
</div>
</Placeholder>
</div>
) }
<InspectorControls>
<PanelBody title={ __( 'Payments & Fees', 'jetpack' ) }>
<ExternalLink href="https://wordpress.com/support/wordpress-editor/blocks/payments/#related-fees">
{ __( 'Read more about Payments and related fees.', 'jetpack' ) }
</ExternalLink>
</PanelBody>
</InspectorControls>
{ ! this.isPremiumContentChild && this.renderUpgradeNudges() }
{ ! this.isPremiumContentChild && this.renderPlanNotices() }

{ showControls && inspectorControls }
{ ( ( ( this.hasUpgradeNudge || ! this.state.shouldUpgrade ) &&
connected !== API_STATE_LOADING ) ||
this.props.attributes.planId ) && (
<InnerBlocks
template={ [
[
'jetpack/button',
{
element: 'a',
uniqueId: 'recurring-payments-id',
},
],
] }
templateLock="all"
/>
) }

<InnerBlocks
apeatling marked this conversation as resolved.
Show resolved Hide resolved
template={ [
[
'jetpack/button',
{
element: 'a',
uniqueId: 'recurring-payments-id',
},
],
] }
templateLock="all"
/>
</Fragment>
);
};
}

export default compose( [
withSelect( ( select, { clientId } ) => ( {
withSelect( ( select ) => ( {
postId: select( 'core/editor' ).getCurrentPostId(),
innerButtons: select( 'core/editor' ).getBlocksByClientId( clientId ),
apeatling marked this conversation as resolved.
Show resolved Hide resolved
} ) ),
withDispatch( dispatch => {
const { updateBlockAttributes } = dispatch( 'core/editor' );
Expand Down
1 change: 1 addition & 0 deletions extensions/blocks/recurring-payments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const settings = {
'stripe',
_x( 'memberships', 'block search term', 'jetpack' ),
],
usesContext: [ 'isPremiumContentChild' ],
attributes: {
planId: {
type: 'integer',
Expand Down