Skip to content

Commit

Permalink
My Jetpack: handle AI is_upgradable (#39074)
Browse files Browse the repository at this point in the history
* copy edits

* compute is_upgradable properly based on current tier and if tier plans are disabled

* fix glitch when trying to calculate remaining days

* fix interstitial parameters and cta label

* revert description until we figure out a good one, if needed

* fix versions
  • Loading branch information
CGastrell authored Aug 26, 2024
1 parent 82ceac0 commit c2b8665
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import debugFactory from 'debug';
import { useCallback } from 'react';
/**
Expand Down Expand Up @@ -41,13 +42,14 @@ export default function JetpackAiInterstitial() {
return (
<ProductInterstitial
slug="jetpack-ai"
installsPlugin={ true }
installsPlugin={ true } // this here just to trigger the ctaCallback
imageContainerClassName={ styles.aiImageContainer }
hideTOS={ true }
directCheckout={ false }
ctaCallback={ ctaClickHandler }
ctaButtonLabel={ __( 'Upgrade', 'jetpack-my-jetpack' ) }
>
<img src={ jetpackAiImage } alt="Search" />
<img src={ jetpackAiImage } alt="Jetpack AI" />
</ProductInterstitial>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ export default function () {
nextTier,
usagePeriod: usage,
isOverLimit,
tierPlansEnabled,
} = aiAssistantFeature || {};

const hasUnlimited = currentTier?.value === 1;
const isFree = currentTier?.value === 0;
const hasUnlimited = currentTier?.value === 1 || ( ! tierPlansEnabled && ! isFree );
const hasPaidTier = ! isFree && ! hasUnlimited;
const shouldContactUs = ! hasUnlimited && hasPaidTier && ! nextTier && currentTier;
const freeRequestsLeft = isFree && 20 - allTimeRequests >= 0 ? 20 - allTimeRequests : 0;
Expand Down Expand Up @@ -116,8 +117,9 @@ export default function () {
'Wait for %d days to reset your limit, or upgrade now to a higher tier for additional requests and keep your work moving forward.',
'jetpack-my-jetpack'
),
Math.floor( ( new Date( usage?.[ 'next-start' ] ) - new Date() ) / ( 1000 * 60 * 60 * 24 ) )
Math.floor( ( new Date( usage?.nextStart || null ) - new Date() ) / ( 1000 * 60 * 60 * 24 ) )
);

const upgradeNoticeBody = __(
'Reach for More with Jetpack AI! Upgrade now for additional requests and keep your momentum going.',
'jetpack-my-jetpack'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

My Jetpack: reflect tier filters properly on product class and UI. Fix little nuances with date constructor
2 changes: 1 addition & 1 deletion projects/packages/my-jetpack/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-my-jetpack",
"version": "4.33.0",
"version": "4.33.1-alpha",
"description": "WP Admin page with information and configuration shared among all Jetpack stand-alone plugins",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/my-jetpack/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/my-jetpack/src/class-initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Initializer {
*
* @var string
*/
const PACKAGE_VERSION = '4.33.0';
const PACKAGE_VERSION = '4.33.1-alpha';

/**
* HTML container ID for the IDC screen on My Jetpack page.
Expand Down
21 changes: 14 additions & 7 deletions projects/packages/my-jetpack/src/products/class-jetpack-ai.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,12 @@ public static function get_features_by_usage_tier( $tier ) {
}

$features = array(
__( 'Artificial intelligence chatbot', 'jetpack-my-jetpack' ),
__( 'Generate text, tables, lists, and forms', 'jetpack-my-jetpack' ),
__( 'Refine the tone and content to your liking', 'jetpack-my-jetpack' ),
__( 'Get feedback about your post', 'jetpack-my-jetpack' ),
__( 'Seamless WordPress editor integration', 'jetpack-my-jetpack' ),
__( 'Easily refine content to your liking', 'jetpack-my-jetpack' ),
__( 'Make your content easier to read', 'jetpack-my-jetpack' ),
__( 'Generate images with one-click', 'jetpack-my-jetpack' ),
__( 'Optimize your titles for better performance', 'jetpack-my-jetpack' ),
__( 'Priority support', 'jetpack-my-jetpack' ),
);

$tiered_features = array(
Expand Down Expand Up @@ -468,9 +469,15 @@ public static function has_paid_plan_for_product() {
* @return boolean
*/
public static function is_upgradable() {
$has_ai_feature = static::does_site_have_feature( 'ai-assistant' );
$current_tier = self::get_current_usage_tier();
$next_tier = self::get_next_usage_tier();
$has_ai_feature = static::does_site_have_feature( 'ai-assistant' );
$tier_plans_enabled = self::are_tier_plans_enabled();
$current_tier = self::get_current_usage_tier();

if ( $has_ai_feature && ! $tier_plans_enabled && $current_tier >= 1 ) {
return false;
}

$next_tier = self::get_next_usage_tier();

// The check below is debatable, not having the feature should not flag as not upgradable.
// If user is free (tier = 0), not unlimited (tier = 1) and has a next tier, then it's upgradable.
Expand Down

0 comments on commit c2b8665

Please sign in to comment.