Skip to content

Commit

Permalink
Boost: Use Blog ID in links to WPCOM instead of site slug (#35002)
Browse files Browse the repository at this point in the history
Adjust checkout links in Boost plugin to use blog ID instead of slug for multi-URL support.
  • Loading branch information
sergeymitr committed Jan 30, 2024
1 parent 8bbce7e commit 1f61063
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
19 changes: 13 additions & 6 deletions projects/plugins/boost/app/assets/src/js/lib/stores/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ import { z } from 'zod';
*
* @param domain
* @param isUserConnected
* @param blogID
*/
export function getUpgradeURL( domain: string, isUserConnected = false ) {
export function getUpgradeURL(
domain: string,
isUserConnected = false,
blogID: string | null = null
) {
const product = 'jetpack_boost_yearly';

const redirectUrl = new URL( window.location.href );
redirectUrl.hash = '#/purchase-successful';

const checkoutProductUrl = new URL( `https://wordpress.com/checkout/${ domain }/${ product }` );
const checkoutProductUrl = new URL(
`https://wordpress.com/checkout/${ blogID ?? domain }/${ product }`
);

// Add redirect_to parameter
checkoutProductUrl.searchParams.set( 'redirect_to', redirectUrl.toString() );
checkoutProductUrl.searchParams.set(
'redirect_to',
'admin.php?page=jetpack-boost#/purchase-successful'
);

// Add site to query string.
checkoutProductUrl.searchParams.set( 'site', domain );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ const GettingStarted: React.FC = () => {
const [ , setCriticalCssState ] = useSingleModuleState( 'critical_css' );

const {
connection: { userConnected },
connection: { userConnected, wpcomBlogId },
initializeConnection,
} = useConnection();

useEffect( () => {
if ( ! shouldGetStarted && selectedPlan ) {
// Go to the purchase flow if the user doesn't have a premium plan.
if ( ! isPremium && selectedPlan === 'premium' ) {
window.location.href = getUpgradeURL( domain, userConnected );
window.location.href = getUpgradeURL(
domain,
userConnected,
wpcomBlogId ? wpcomBlogId.toString() : null
);
} else {
setCriticalCssState( true );
navigate( '/', { replace: true } );
Expand All @@ -53,6 +57,7 @@ const GettingStarted: React.FC = () => {
setCriticalCssState,
shouldGetStarted,
userConnected,
wpcomBlogId,
] );

async function initialize( plan: 'free' | 'premium' ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ const Upgrade: React.FC = () => {

const goToCheckout = () => {
recordBoostEventAndRedirect(
getUpgradeURL( siteDomain, connection.userConnected ),
getUpgradeURL(
siteDomain,
connection.userConnected,
connection?.wpcomBlogId ? connection?.wpcomBlogId.toString() : null
),
'checkout_from_pricing_page_in_plugin'
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Use Blog ID in links to WPCOM instead of site slug.

0 comments on commit 1f61063

Please sign in to comment.