Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI Logo Generator: fix upgrade links #38598

Merged
merged 7 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

AI Logo Generator: fix upgrade URLs so they work on any site type.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EVENT_MODAL_CLOSE,
EVENT_GENERATE,
} from '../constants.js';
import { useCheckout } from '../hooks/use-checkout.js';
import useLogoGenerator from '../hooks/use-logo-generator.js';
import useRequestErrors from '../hooks/use-request-errors.js';
import { isLogoHistoryEmpty, clearDeletedMedia } from '../lib/logo-storage.js';
Expand Down Expand Up @@ -58,12 +59,12 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
const requestedFeatureData = useRef< boolean >( false );
const [ needsFeature, setNeedsFeature ] = useState( false );
const [ needsMoreRequests, setNeedsMoreRequests ] = useState( false );
const [ upgradeURL, setUpgradeURL ] = useState( '' );
const { selectedLogo, getAiAssistantFeature, generateFirstPrompt, generateLogo, setContext } =
useLogoGenerator();
const { featureFetchError, firstLogoPromptFetchError, clearErrors } = useRequestErrors();
const siteId = siteDetails?.ID;
const [ logoAccepted, setLogoAccepted ] = useState( false );
const { nextTierCheckoutURL: upgradeURL } = useCheckout();

// First fetch the feature data so we have the most up-to-date info from the backend.
const feature = getAiAssistantFeature();
Expand Down Expand Up @@ -107,16 +108,10 @@ export const GeneratorModal: React.FC< GeneratorModalProps > = ( {
! hasHistory &&
currentLimit - currentUsage < logoCost + promptCreationCost;

// If the site requires an upgrade, set the upgrade URL and show the upgrade screen immediately.
// If the site requires an upgrade, show the upgrade screen immediately.
setNeedsFeature( ! feature?.hasFeature ?? true );
setNeedsMoreRequests( siteNeedsMoreRequests );

if ( ! feature?.hasFeature || siteNeedsMoreRequests ) {
const siteUpgradeURL = new URL(
`${ location.origin }/checkout/${ siteDetails?.domain }/${ feature?.nextTier?.slug }`
);
siteUpgradeURL.searchParams.set( 'redirect_to', location.href );
setUpgradeURL( siteUpgradeURL.toString() );
setLoadingState( null );
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const UpgradeScreen: React.FC< {
</span>
&nbsp;
<Button variant="link" href="https://jetpack.com/ai/" target="_blank">
{ __( 'Learn more', 'jetpack-ai-client' ) }
{ __( 'Learn more about Jetpack AI.', 'jetpack-ai-client' ) }
</Button>
</div>
<div className="jetpack-ai-logo-generator-modal__notice-actions">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/**
* External dependencies
*/
import {
isAtomicSite,
isSimpleSite,
getSiteFragment,
} from '@automattic/jetpack-shared-extension-utils';
import { useSelect } from '@wordpress/data';
import debugFactory from 'debug';
/**
Expand All @@ -15,23 +20,33 @@ import type { Selectors } from '../store/types.js';
const debug = debugFactory( 'ai-client:logo-generator:use-checkout' );

export const useCheckout = () => {
const { nextTier, siteDetails } = useSelect( select => {
const { nextTier } = useSelect( select => {
const selectors: Selectors = select( STORE_NAME );
return {
nextTier: selectors.getAiAssistantFeature().nextTier,
siteDetails: selectors.getSiteDetails(),
};
}, [] );

const upgradeURL = new URL(
`${ location.origin }/checkout/${ siteDetails?.domain }/${ nextTier?.slug }`
);
upgradeURL.searchParams.set( 'redirect_to', location.href );
/**
* Use the Jetpack redirect URL to open the checkout page
*/
const wpcomCheckoutUrl = new URL( `https://jetpack.com/redirect/` );
wpcomCheckoutUrl.searchParams.set( 'source', 'jetpack-ai-yearly-tier-upgrade-nudge' );
wpcomCheckoutUrl.searchParams.set( 'site', getSiteFragment() as string );
wpcomCheckoutUrl.searchParams.set( 'path', `jetpack_ai_yearly:-q-${ nextTier?.limit }` );

debug( 'Next tier checkout URL: ', upgradeURL.toString() );
/**
* Open the product interstitial page
*/
const jetpackCheckoutUrl = `${ window?.Jetpack_Editor_Initial_State?.adminUrl }admin.php?redirect_to_referrer=1&page=my-jetpack#/add-jetpack-ai`;

const nextTierCheckoutURL =
isAtomicSite() || isSimpleSite() ? wpcomCheckoutUrl.toString() : jetpackCheckoutUrl;

debug( 'Next tier checkout URL: ', nextTierCheckoutURL );

return {
nextTierCheckoutURL: upgradeURL.toString(),
nextTierCheckoutURL,
hasNextTier: !! nextTier,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Just bumping versions to comply with changelogger checks.


2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"composer/installers": true,
"roots/wordpress-core-installer": true
},
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_1"
"autoloader-suffix": "26841ac2064774301cbe06d174833bfc_wpcomshⓥ5_1_2_alpha"
},
"extra": {
"mirror-repo": "Automattic/wpcom-site-helper",
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/wpcomsh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "@automattic/jetpack-wpcomsh",
"description": "A helper for connecting WordPress.com sites to external host infrastructure.",
"homepage": "https://jetpack.com",
"version": "5.1.1",
"version": "5.1.2-alpha",
"bugs": {
"url": "https://github.com/Automattic/jetpack/labels/[Plugin] Wpcomsh"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/wpcomsh.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
/**
* Plugin Name: WordPress.com Site Helper
* Description: A helper for connecting WordPress.com sites to external host infrastructure.
* Version: 5.1.1
* Version: 5.1.2-alpha
* Author: Automattic
* Author URI: http://automattic.com/
*
* @package wpcomsh
*/

define( 'WPCOMSH_VERSION', '5.1.1' );
define( 'WPCOMSH_VERSION', '5.1.2-alpha' );

// If true, Typekit fonts will be available in addition to Google fonts
add_filter( 'jetpack_fonts_enable_typekit', '__return_true' );
Expand Down
Loading