Skip to content

Commit

Permalink
Jetpack AI: Improve simple site redirect after upgrade behavior (#35376)
Browse files Browse the repository at this point in the history
* Build calypso URL to redirect user back after upgrade

* Changelog

* Only redirect to post edit view if the site is Simple

* Change the default redirect URL for wpcom sites as the calypso home page
  • Loading branch information
lhkowalski authored Jan 31, 2024
1 parent ca0914c commit 251401f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Jetpack AI: Build a Calypso URL as the redirect destination for Simple sites after upgrade.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ import {
import useAutosaveAndRedirect from '../../../../shared/use-autosave-and-redirect';
import useAiFeature from '../use-ai-feature';

const getWPComRedirectToURL = () => {
const searchParams = new URLSearchParams( window.location.search );
const site = getSiteFragment();

if ( isSimpleSite() && searchParams.has( 'post' ) ) {
// When there is an explicit post, use it as the destination
return `https://wordpress.com/post/${ site }/${ searchParams.get( 'post' ) }`;
}
// When there is no explicit post, or the site is not Simple, use the home page as the destination
return `https://wordpress.com/home/${ site }`;
};

export default function useAICheckout(): {
checkoutUrl: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -18,11 +30,13 @@ export default function useAICheckout(): {
} {
const { nextTier, tierPlansEnabled } = useAiFeature();

const wpcomRedirectToURL = getWPComRedirectToURL();

const wpcomCheckoutUrl = tierPlansEnabled
? getRedirectUrl( 'jetpack-ai-yearly-tier-upgrade-nudge', {
site: getSiteFragment(),
path: `jetpack_ai_yearly:-q-${ nextTier?.limit }`,
query: `redirect_to=${ encodeURIComponent( window.location.href ) }`,
query: `redirect_to=${ encodeURIComponent( wpcomRedirectToURL ) }`,
} )
: getRedirectUrl( 'jetpack-ai-monthly-plan-ai-assistant-block-banner', {
site: getSiteFragment(),
Expand Down

0 comments on commit 251401f

Please sign in to comment.