11import { isClaudeOAuthValid } from '@codebuff/sdk'
22import { TextAttributes } from '@opentui/core'
33import open from 'open'
4- import React , { useEffect , useMemo , useState } from 'react'
4+ import React , { useEffect , useMemo } from 'react'
55
66import { BottomBanner } from './bottom-banner'
77import { Button } from './button'
@@ -10,9 +10,9 @@ import { getActivityQueryData } from '../hooks/use-activity-query'
1010import { useClaudeQuotaQuery } from '../hooks/use-claude-quota-query'
1111import { useSubscriptionQuery } from '../hooks/use-subscription-query'
1212import { useTheme } from '../hooks/use-theme'
13+ import { useUpdatePreference } from '../hooks/use-update-preference'
1314import { usageQueryKeys , useUsageQuery } from '../hooks/use-usage-query'
1415import { WEBSITE_URL } from '../login/constants'
15- import { getAlwaysUseALaCarte , setAlwaysUseALaCarte } from '../utils/settings'
1616import { useChatStore } from '../state/chat-store'
1717import { formatResetTime , formatResetTimeLong } from '../utils/time-format'
1818import {
@@ -122,6 +122,7 @@ export const UsageBanner = ({ showTime }: { showTime: number }) => {
122122 subscriptionInfo = { subscriptionInfo }
123123 rateLimit = { rateLimit }
124124 isLoading = { isSubscriptionLoading }
125+ fallbackToALaCarte = { activeSubscription . fallbackToALaCarte }
125126 />
126127 ) }
127128
@@ -209,21 +210,21 @@ interface SubscriptionUsageSectionProps {
209210 weeklyResetsAt : string
210211 }
211212 isLoading : boolean
213+ fallbackToALaCarte : boolean
212214}
213215
214216const SubscriptionUsageSection : React . FC < SubscriptionUsageSectionProps > = ( {
215217 displayName,
216218 subscriptionInfo,
217219 rateLimit,
218220 isLoading,
221+ fallbackToALaCarte,
219222} ) => {
220223 const theme = useTheme ( )
221- const [ useALaCarte , setUseALaCarte ] = useState ( ( ) => getAlwaysUseALaCarte ( ) )
224+ const updatePreference = useUpdatePreference ( )
222225
223- const handleToggleALaCarte = ( ) => {
224- const newValue = ! useALaCarte
225- setUseALaCarte ( newValue )
226- setAlwaysUseALaCarte ( newValue )
226+ const handleToggleFallbackToALaCarte = ( ) => {
227+ updatePreference . mutate ( { fallbackToALaCarte : ! fallbackToALaCarte } )
227228 }
228229
229230 const blockPercent = useMemo ( ( ) => {
@@ -268,11 +269,11 @@ const SubscriptionUsageSection: React.FC<SubscriptionUsageSectionProps> = ({
268269 < box style = { { flexDirection : 'row' , alignItems : 'center' , gap : 1 , marginTop : 1 } } >
269270 < text style = { { fg : theme . muted } } > When limit reached:</ text >
270271 < text style = { { fg : theme . muted } } >
271- { useALaCarte ? 'spend credits' : 'pause' }
272+ { fallbackToALaCarte ? 'spend credits' : 'pause' }
272273 </ text >
273- < Button onClick = { handleToggleALaCarte } >
274+ < Button onClick = { handleToggleFallbackToALaCarte } >
274275 < text style = { { fg : theme . muted , attributes : TextAttributes . UNDERLINE } } >
275- [{ useALaCarte ? 'switch to pause' : 'switch to spend credits' } ]
276+ [{ fallbackToALaCarte ? 'switch to pause' : 'switch to spend credits' } ]
276277 </ text >
277278 </ Button >
278279 </ box >
0 commit comments