From e4262fb403e9485f2c9eed9541bb07c40c74cc7c Mon Sep 17 00:00:00 2001 From: Christian Gastrell Date: Wed, 22 Nov 2023 15:42:27 -0300 Subject: [PATCH] AI Assistant: tier plans upgrade nudge update (#34254) * add tier plans flag, use new JP redirect for tier plans checkout link * adjust Nudge for tier plans * changelog * use JP redirect for contact href * Simplify ternary condition for tier plans flag Co-authored-by: Douglas Henri * simplify flag assignment here as well --------- Co-authored-by: Douglas Henri --- .../changelog/add-tier-plans-upgrade-nudge | 4 ++ .../components/upgrade-prompt/index.tsx | 60 ++++++++++++++++++- .../hooks/use-ai-checkout/index.ts | 18 +++++- 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-tier-plans-upgrade-nudge diff --git a/projects/plugins/jetpack/changelog/add-tier-plans-upgrade-nudge b/projects/plugins/jetpack/changelog/add-tier-plans-upgrade-nudge new file mode 100644 index 0000000000000..fc005729b3a88 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-tier-plans-upgrade-nudge @@ -0,0 +1,4 @@ +Significance: minor +Type: enhancement + +Adjust UpgradeNudge for tier plans diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/upgrade-prompt/index.tsx b/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/upgrade-prompt/index.tsx index b09baf1f4bc07..dc39cb9abf45b 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/upgrade-prompt/index.tsx +++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/components/upgrade-prompt/index.tsx @@ -1,8 +1,9 @@ /* * External dependencies */ +import { getRedirectUrl } from '@automattic/jetpack-components'; import { createInterpolateElement } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; +import { __, sprintf } from '@wordpress/i18n'; import React from 'react'; /* * Internal dependencies @@ -22,6 +23,11 @@ const DefaultUpgradePrompt = (): React.ReactNode => { const { checkoutUrl, autosaveAndRedirect, isRedirecting } = useAICheckout(); const canUpgrade = canUserPurchasePlan(); + const tierPlansEnabled = + window?.Jetpack_Editor_Initial_State?.available_blocks[ 'ai-enable-tier-plans-ui' ]?.available; + + const { nextTier } = useAiFeature(); + if ( ! canUpgrade ) { return ( { ); } + if ( tierPlansEnabled ) { + if ( ! nextTier ) { + const contactHref = getRedirectUrl( 'jetpack-ai-tiers-more-requests-contact' ); + return ( + + ); + } + return ( + Upgrade now to increase your requests limit to %d.', + 'jetpack' + ), + nextTier.limit + ), + { + br:
, + strong: , + } + ) } + goToCheckoutPage={ autosaveAndRedirect } + isRedirecting={ isRedirecting } + visible={ true } + align={ 'center' } + title={ null } + context={ null } + /> + ); + } + return ( void; isRedirecting: boolean; } { - const wpcomCheckoutUrl = getRedirectUrl( 'jetpack-ai-monthly-plan-ai-assistant-block-banner', { - site: getSiteFragment(), - } ); + const tierPlansEnabled = + window?.Jetpack_Editor_Initial_State?.available_blocks[ 'ai-enable-tier-plans-ui' ]?.available; + + const { nextTier } = useAiFeature(); + + const wpcomCheckoutUrl = tierPlansEnabled + ? getRedirectUrl( 'jetpack-ai-yearly-tier-upgrade-nudge', { + site: getSiteFragment(), + path: `jetpack_ai_yearly:-q-${ nextTier?.limit }`, + query: `redirect_to=${ window.location.href }`, + } ) + : getRedirectUrl( 'jetpack-ai-monthly-plan-ai-assistant-block-banner', { + site: getSiteFragment(), + } ); const checkoutUrl = isAtomicSite() || isSimpleSite()