From 1f6106351dd853125a87e0d85037011c859c68dc Mon Sep 17 00:00:00 2001 From: Sergey Mitroshin Date: Tue, 30 Jan 2024 09:33:49 -0500 Subject: [PATCH] Boost: Use Blog ID in links to WPCOM instead of site slug (#35002) Adjust checkout links in Boost plugin to use blog ID instead of slug for multi-URL support. --- .../assets/src/js/lib/stores/connection.ts | 19 +++++++++++++------ .../pages/getting-started/getting-started.tsx | 9 +++++++-- .../assets/src/js/pages/upgrade/upgrade.tsx | 6 +++++- .../update-boost-wpcom-links-blog-id | 4 ++++ 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 projects/plugins/boost/changelog/update-boost-wpcom-links-blog-id diff --git a/projects/plugins/boost/app/assets/src/js/lib/stores/connection.ts b/projects/plugins/boost/app/assets/src/js/lib/stores/connection.ts index 2a032e5cef767..ccab4b86573a4 100644 --- a/projects/plugins/boost/app/assets/src/js/lib/stores/connection.ts +++ b/projects/plugins/boost/app/assets/src/js/lib/stores/connection.ts @@ -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 ); diff --git a/projects/plugins/boost/app/assets/src/js/pages/getting-started/getting-started.tsx b/projects/plugins/boost/app/assets/src/js/pages/getting-started/getting-started.tsx index ff1819a5593d9..345b87ab9b56a 100644 --- a/projects/plugins/boost/app/assets/src/js/pages/getting-started/getting-started.tsx +++ b/projects/plugins/boost/app/assets/src/js/pages/getting-started/getting-started.tsx @@ -31,7 +31,7 @@ const GettingStarted: React.FC = () => { const [ , setCriticalCssState ] = useSingleModuleState( 'critical_css' ); const { - connection: { userConnected }, + connection: { userConnected, wpcomBlogId }, initializeConnection, } = useConnection(); @@ -39,7 +39,11 @@ const GettingStarted: React.FC = () => { 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 } ); @@ -53,6 +57,7 @@ const GettingStarted: React.FC = () => { setCriticalCssState, shouldGetStarted, userConnected, + wpcomBlogId, ] ); async function initialize( plan: 'free' | 'premium' ) { diff --git a/projects/plugins/boost/app/assets/src/js/pages/upgrade/upgrade.tsx b/projects/plugins/boost/app/assets/src/js/pages/upgrade/upgrade.tsx index 5d98c12690f41..4d1379290f7f2 100644 --- a/projects/plugins/boost/app/assets/src/js/pages/upgrade/upgrade.tsx +++ b/projects/plugins/boost/app/assets/src/js/pages/upgrade/upgrade.tsx @@ -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' ); }; diff --git a/projects/plugins/boost/changelog/update-boost-wpcom-links-blog-id b/projects/plugins/boost/changelog/update-boost-wpcom-links-blog-id new file mode 100644 index 0000000000000..c27ddd9c50f74 --- /dev/null +++ b/projects/plugins/boost/changelog/update-boost-wpcom-links-blog-id @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Use Blog ID in links to WPCOM instead of site slug.