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

My Jetpack: Change Jetpack AI product page limit handling #39129

Merged
merged 2 commits into from
Aug 29, 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
Expand Up @@ -68,8 +68,8 @@ export default function () {
} = aiAssistantFeature || {};

const isFree = currentTier?.value === 0;
const hasUnlimited = currentTier?.value === 1 || ( ! tierPlansEnabled && ! isFree );
const hasPaidTier = ! isFree && ! hasUnlimited;
const hasUnlimited = currentTier?.value === 1;
const hasPaidTier = ( ! isFree && ! hasUnlimited ) || ( hasUnlimited && ! tierPlansEnabled );
const shouldContactUs = ! hasUnlimited && hasPaidTier && ! nextTier && currentTier;
const freeRequestsLeft = isFree && 20 - allTimeRequests >= 0 ? 20 - allTimeRequests : 0;
const showCurrentUsage = hasPaidTier && ! isFree && usage;
Expand Down Expand Up @@ -100,26 +100,37 @@ export default function () {
const showRenewalNotice = isOverLimit && hasPaidTier;
const showUpgradeNotice = isOverLimit && isFree;

const currentTierValue = currentTier?.value || 0;
const currentUsage = usage?.[ 'requests-count' ] || 0;
const currentTierLimit = currentTier?.limit || 0;
const currentUsage = usage?.requestsCount || 0;

const tierRequestsLeft =
currentTierValue - currentUsage >= 0 ? currentTierValue - currentUsage : 0;
currentTierLimit - currentUsage >= 0 ? currentTierLimit - currentUsage : 0;
const requestCardNumber = tierPlansEnabled ? tierRequestsLeft : currentUsage;

const currentUsageLabel = __( 'Requests this month', 'jetpack-my-jetpack' );
const currentRemainingLabel = __( 'Requests for this month', 'jetpack-my-jetpack' );

const renewalNoticeTitle = __(
"You've reached your request limit for this month",
'jetpack-my-jetpack'
);
const upgradeNoticeTitle = __( "You've used all your free requests", 'jetpack-my-jetpack' );

const renewalNoticeBody = sprintf(
const renewalNoticeBodyInfo = sprintf(
// translators: %d is the number of days left in the month.
__(
'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'
),
__( 'Wait for %d days to reset your limit', 'jetpack-my-jetpack' ),
Math.floor( ( new Date( usage?.nextStart || null ) - new Date() ) / ( 1000 * 60 * 60 * 24 ) )
);

const renewalNoticeBodyTeaser = __(
', or upgrade now to a higher tier for additional requests and keep your work moving forward.',
'jetpack-my-jetpack'
);

const renewalNoticeBody = ! tierPlansEnabled
? renewalNoticeBodyInfo + '.'
: renewalNoticeBodyInfo + renewalNoticeBodyTeaser;

const upgradeNoticeBody = __(
'Reach for More with Jetpack AI! Upgrade now for additional requests and keep your momentum going.',
'jetpack-my-jetpack'
Expand Down Expand Up @@ -222,10 +233,10 @@ export default function () {
<AiIcon />
<div>
<div className={ styles[ 'product-interstitial__stats-card-text' ] }>
{ __( 'Requests for this month', 'jetpack-my-jetpack' ) }
{ tierPlansEnabled ? currentRemainingLabel : currentUsageLabel }
</div>
<div className={ styles[ 'product-interstitial__stats-card-value' ] }>
{ tierRequestsLeft }
{ requestCardNumber }
</div>
</div>
</Card>
Expand Down Expand Up @@ -264,11 +275,15 @@ export default function () {
{ showNotice && (
<div className={ styles[ 'product-interstitial__ai-notice' ] }>
<Notice
actions={ [
<Button isPrimary onClick={ upgradeClickHandler }>
{ showRenewalNotice ? renewalNoticeCta : upgradeNoticeCta }
</Button>,
] }
actions={
tierPlansEnabled
? [
<Button isPrimary onClick={ upgradeClickHandler }>
{ showRenewalNotice ? renewalNoticeCta : upgradeNoticeCta }
</Button>,
]
: {}
}
onClose={ onNoticeClose }
level={ showRenewalNotice ? 'warning' : 'error' }
title={ showRenewalNotice ? renewalNoticeTitle : upgradeNoticeTitle }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

My Jetpack: show over quota notice and period usage counter for unlimited plans
Loading