Skip to content

Commit

Permalink
Fix upgrade button link
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jul 4, 2019
1 parent 4d6617b commit e7fdbb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
4 changes: 1 addition & 3 deletions extensions/shared/register-jetpack-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export default function registerJetpackBlock( name, settings, childBlocks = [] )
const result = registerBlockType( `jetpack/${ name }`, {
...settings,
title: betaExtensions.includes( name ) ? `${ settings.title } (beta)` : settings.title,
edit: requiredPlan
? wrapPaidBlock( { feature: details.required_feature, requiredPlan } )( settings.edit )
: settings.edit,
edit: requiredPlan ? wrapPaidBlock( { requiredPlan } )( settings.edit ) : settings.edit,
} );

// Register child blocks. Using `registerBlockType()` directly avoids availability checks -- if
Expand Down
28 changes: 21 additions & 7 deletions extensions/shared/upgrade-nudge/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get } from 'lodash';
import { get, startsWith } from 'lodash';
import { __, sprintf } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { Button } from '@wordpress/components';
Expand All @@ -16,7 +16,7 @@ import './store';

import './style.scss';

const UpgradeNudge = ( { feature, plan, planName } ) => (
const UpgradeNudge = ( { planName, planPathSlug, postId, postType } ) => (
<div className="jetpack-upgrade-nudge">
<Gridicon className="jetpack-upgrade-nudge__icon" icon="star" size={ 18 } />
<div className="jetpack-upgrade-nudge__info">
Expand All @@ -31,10 +31,12 @@ const UpgradeNudge = ( { feature, plan, planName } ) => (
</div>
<Button
className="jetpack-upgrade-nudge__button"
href={ addQueryArgs( `https://wordpress.com/plans/${ getSiteFragment() }`, {
feature,
plan,
} ) }
href={ addQueryArgs(
`https://wordpress.com/checkout/${ getSiteFragment() }/${ planPathSlug }`,
{
redirect_to: `/${ postType }/${ getSiteFragment() }/${ postId }`,
}
) }
isDefault
>
{ __( 'Upgrade', 'jetpack' ) }
Expand All @@ -43,5 +45,17 @@ const UpgradeNudge = ( { feature, plan, planName } ) => (
);
export default withSelect( ( select, { plan: planSlug } ) => {
const plan = select( 'wordpress-com/plans' ).getPlan( planSlug );
return { planName: get( plan, [ 'product_name_short' ] ) };

// WP.com plan objects have a dedicated `path_slug` field, Jetpack plan objects don't
// For Jetpack, we thus use the plan slug with the 'jetpack_' prefix removed.
const planPathSlug = startsWith( planSlug, 'jetpack_' )
? planSlug.substr( 'jetpack_'.length )
: get( plan, [ 'path_slug' ] );

return {
planName: get( plan, [ 'product_name_short' ] ),
planPathSlug,
postId: select( 'core/editor' ).getCurrentPostId(),
postType: select( 'core/editor' ).getCurrentPostType(),
};
} )( UpgradeNudge );
4 changes: 2 additions & 2 deletions extensions/shared/wrap-paid-block/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import UpgradeNudge from '../upgrade-nudge';

import './style.scss';

export default ( { feature, requiredPlan } ) =>
export default ( { requiredPlan } ) =>
createHigherOrderComponent(
WrappedComponent => props => (
// Wraps the input component in a container, without mutating it. Good!
<div className="jetpack-paid-block__wrapper">
<UpgradeNudge feature={ feature } plan={ requiredPlan } />
<UpgradeNudge plan={ requiredPlan } />
<div className="jetpack-paid-block__disabled">
<WrappedComponent { ...props } />
</div>
Expand Down

0 comments on commit e7fdbb2

Please sign in to comment.