|
| 1 | +import { SUBSCRIPTION_TIERS } from '@codebuff/common/constants/subscription-plans' |
1 | 2 | import open from 'open' |
2 | 3 | import React from 'react' |
3 | 4 |
|
@@ -32,6 +33,11 @@ export const SubscriptionLimitBanner = () => { |
32 | 33 | const remainingBalance = usageData?.remainingBalance ?? 0 |
33 | 34 | const hasAlaCarteCredits = remainingBalance > 0 |
34 | 35 |
|
| 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 | + |
35 | 41 | const [alwaysALaCarte, setAlwaysALaCarteState] = React.useState( |
36 | 42 | () => getAlwaysUseALaCarte(), |
37 | 43 | ) |
@@ -61,6 +67,10 @@ export const SubscriptionLimitBanner = () => { |
61 | 67 | open(WEBSITE_URL + '/usage') |
62 | 68 | } |
63 | 69 |
|
| 70 | + const handleUpgrade = () => { |
| 71 | + open(WEBSITE_URL + '/pricing') |
| 72 | + } |
| 73 | + |
64 | 74 | const handleWait = () => { |
65 | 75 | setInputMode('default') |
66 | 76 | } |
@@ -146,22 +156,33 @@ export const SubscriptionLimitBanner = () => { |
146 | 156 | {' '}({remainingBalance.toLocaleString()} credits) |
147 | 157 | </text> |
148 | 158 | </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> |
152 | 162 | </Button> |
153 | 163 | ) : ( |
| 164 | + <Button onClick={handleBuyCredits}> |
| 165 | + <text style={{ fg: theme.background, bg: theme.muted }}>{' '}Buy Credits ↗{' '}</text> |
| 166 | + </Button> |
| 167 | + )} |
| 168 | + {!isWeeklyLimit && |
154 | 169 | <Button onClick={handleWait}> |
155 | 170 | <text style={{ fg: theme.background, bg: theme.muted }}>{' '}Wait for new block{' '}</text> |
156 | 171 | </Button> |
157 | | - )} |
| 172 | + } |
158 | 173 | </> |
159 | 174 | ) : ( |
160 | 175 | <> |
161 | 176 | <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 | + )} |
165 | 186 | <Button onClick={handleWait}> |
166 | 187 | <text style={{ fg: theme.background, bg: theme.muted }}>{' '}Wait{' '}</text> |
167 | 188 | </Button> |
|
0 commit comments