diff --git a/extensions/blocks/recurring-payments/edit.jsx b/extensions/blocks/recurring-payments/edit.jsx index a9e131e568e0a..bb629869b8c97 100644 --- a/extensions/blocks/recurring-payments/edit.jsx +++ b/extensions/blocks/recurring-payments/edit.jsx @@ -79,6 +79,8 @@ class MembershipsButtonEdit extends Component { this.hasUpgradeNudge = ! recurringPaymentsAvailability.available && recurringPaymentsAvailability.unavailableReason === 'missing_plan'; + + this.isPremiumContentChild = this.props.context.isPremiumContentChild || false; } componentDidMount = () => { @@ -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 = @@ -371,9 +374,118 @@ class MembershipsButtonEdit extends Component { ); - render = () => { + renderDisclaimer = () => { + return ( +
+ + { __( 'Read more about Payments and related fees.', 'jetpack' ) } + +
+ ); + }; + + renderUpgradeNudges = () => { const { notices, postId } = this.props; - const { connected, connectURL, products } = this.state; + const { connected, connectURL } = this.state; + + return ( + <> + { ! this.hasUpgradeNudge && + ! this.state.shouldUpgrade && + connected === API_STATE_NOTCONNECTED && ( + + ) } + { ! this.hasUpgradeNudge && this.state.shouldUpgrade && ( +
+ } + label={ __( 'Payments', 'jetpack' ) } + notices={ notices } + instructions={ __( + "You'll need to upgrade your plan to use the Payments block.", + 'jetpack' + ) } + > + + { this.renderDisclaimer() } + +
+ ) } + + ); + } + + 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 && ( + } notices={ notices }> + + + ) } + { ! this.state.shouldUpgrade && + ! this.props.attributes.planId && + connected === API_STATE_CONNECTED && + products.length === 0 && ( +
+ } + label={ __( 'Payments', 'jetpack' ) } + notices={ notices } + > +
+

+ { __( 'To use this block, first add at least one payment plan.', 'jetpack' ) } +

+ { this.renderAddMembershipAmount( true ) } + { this.renderDisclaimer() } +
+
+
+ ) } + { ! this.state.shouldUpgrade && + ! this.props.attributes.planId && + this.state.addingMembershipAmount !== PRODUCT_FORM_SUBMITTED && + connected === API_STATE_CONNECTED && + products.length > 0 && ( +
+ } + label={ __( 'Payments', 'jetpack' ) } + notices={ notices } + > +
+

+ { __( + 'To use this block, select a previously created payment plan.', + 'jetpack' + ) } +

+ { this.renderMembershipAmounts() } +

{ __( 'Or a new one.', 'jetpack' ) }

+ { this.renderAddMembershipAmount( false ) } + { this.renderDisclaimer() } +
+
+
+ ) } + + ); + }; + + render = () => { + const { products } = this.state; /** * Filters the flag that determines if the Recurring Payments block controls should be shown in the inspector. @@ -412,116 +524,31 @@ class MembershipsButtonEdit extends Component { return ( { this.props.noticeUI } - { ! this.hasUpgradeNudge && - ! this.state.shouldUpgrade && - connected === API_STATE_NOTCONNECTED && ( - - ) } - { ! this.hasUpgradeNudge && this.state.shouldUpgrade && ( -
- } - label={ __( 'Payments', 'jetpack' ) } - notices={ notices } - instructions={ __( - "You'll need to upgrade your plan to use the Payments block.", - 'jetpack' - ) } - > - - -
- ) } - { ( connected === API_STATE_LOADING || - this.state.addingMembershipAmount === PRODUCT_FORM_SUBMITTED ) && - ! this.props.attributes.planId && ( - } notices={ notices }> - - - ) } - { ! this.state.shouldUpgrade && - ! this.props.attributes.planId && - connected === API_STATE_CONNECTED && - products.length === 0 && ( -
- } - label={ __( 'Payments', 'jetpack' ) } - notices={ notices } - > -
-

- { __( 'To use this block, first add at least one payment plan.', 'jetpack' ) } -

- { this.renderAddMembershipAmount( true ) } -
-
-
- ) } - { ! this.state.shouldUpgrade && - ! this.props.attributes.planId && - this.state.addingMembershipAmount !== PRODUCT_FORM_SUBMITTED && - connected === API_STATE_CONNECTED && - products.length > 0 && ( -
- } - label={ __( 'Payments', 'jetpack' ) } - notices={ notices } - > -
-

- { __( - 'To use this block, select a previously created payment plan.', - 'jetpack' - ) } -

- { this.renderMembershipAmounts() } -

{ __( 'Or a new one.', 'jetpack' ) }

- { this.renderAddMembershipAmount( false ) } -
-
-
- ) } - - - - { __( 'Read more about Payments and related fees.', 'jetpack' ) } - - - + { ! this.isPremiumContentChild && this.renderUpgradeNudges() } + { ! this.isPremiumContentChild && this.renderPlanNotices() } + { showControls && inspectorControls } - { ( ( ( this.hasUpgradeNudge || ! this.state.shouldUpgrade ) && - connected !== API_STATE_LOADING ) || - this.props.attributes.planId ) && ( - - ) } + +
); }; } export default compose( [ - withSelect( ( select, { clientId } ) => ( { + withSelect( ( select ) => ( { postId: select( 'core/editor' ).getCurrentPostId(), - innerButtons: select( 'core/editor' ).getBlocksByClientId( clientId ), } ) ), withDispatch( dispatch => { const { updateBlockAttributes } = dispatch( 'core/editor' ); diff --git a/extensions/blocks/recurring-payments/index.js b/extensions/blocks/recurring-payments/index.js index f4a8da3a78553..95c4687ede030 100644 --- a/extensions/blocks/recurring-payments/index.js +++ b/extensions/blocks/recurring-payments/index.js @@ -46,6 +46,7 @@ export const settings = { 'stripe', _x( 'memberships', 'block search term', 'jetpack' ), ], + usesContext: [ 'isPremiumContentChild' ], attributes: { planId: { type: 'integer',