Skip to content

Commit afa0869

Browse files
committed
cli: Include link to upgrade plan when you hit limit
1 parent 0c34f9b commit afa0869

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

cli/src/components/subscription-limit-banner.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SUBSCRIPTION_TIERS } from '@codebuff/common/constants/subscription-plans'
12
import open from 'open'
23
import React from 'react'
34

@@ -32,6 +33,11 @@ export const SubscriptionLimitBanner = () => {
3233
const remainingBalance = usageData?.remainingBalance ?? 0
3334
const hasAlaCarteCredits = remainingBalance > 0
3435

36+
// Determine if user can upgrade (not on highest tier)
37+
const maxTier = Math.max(...Object.keys(SUBSCRIPTION_TIERS).map(Number))
38+
const currentTier = subscriptionData?.hasSubscription ? subscriptionData.subscription.tier : 0
39+
const canUpgrade = currentTier < maxTier
40+
3541
const [alwaysALaCarte, setAlwaysALaCarteState] = React.useState(
3642
() => getAlwaysUseALaCarte(),
3743
)
@@ -61,6 +67,10 @@ export const SubscriptionLimitBanner = () => {
6167
open(WEBSITE_URL + '/usage')
6268
}
6369

70+
const handleUpgrade = () => {
71+
open(WEBSITE_URL + '/pricing')
72+
}
73+
6474
const handleWait = () => {
6575
setInputMode('default')
6676
}
@@ -146,22 +156,33 @@ export const SubscriptionLimitBanner = () => {
146156
{' '}({remainingBalance.toLocaleString()} credits)
147157
</text>
148158
</Button>
149-
{isWeeklyLimit ? (
150-
<Button onClick={handleBuyCredits}>
151-
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Buy Credits{' '}</text>
159+
{canUpgrade ? (
160+
<Button onClick={handleUpgrade}>
161+
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Upgrade Plan ↗{' '}</text>
152162
</Button>
153163
) : (
164+
<Button onClick={handleBuyCredits}>
165+
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Buy Credits ↗{' '}</text>
166+
</Button>
167+
)}
168+
{!isWeeklyLimit &&
154169
<Button onClick={handleWait}>
155170
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Wait for new block{' '}</text>
156171
</Button>
157-
)}
172+
}
158173
</>
159174
) : (
160175
<>
161176
<text style={{ fg: theme.muted }}>No a-la-carte credits available.</text>
162-
<Button onClick={handleBuyCredits}>
163-
<text style={{ fg: theme.background, bg: theme.foreground }}>{' '}Buy Credits{' '}</text>
164-
</Button>
177+
{canUpgrade ? (
178+
<Button onClick={handleUpgrade}>
179+
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Upgrade Plan ↗{' '}</text>
180+
</Button>
181+
) : (
182+
<Button onClick={handleBuyCredits}>
183+
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Buy Credits ↗{' '}</text>
184+
</Button>
185+
)}
165186
<Button onClick={handleWait}>
166187
<text style={{ fg: theme.background, bg: theme.muted }}>{' '}Wait{' '}</text>
167188
</Button>

0 commit comments

Comments
 (0)