Skip to content

Commit b5b2855

Browse files
authored
fix(overage): fix pill calculation in the usage indicator to be consistent across views (#2034)
1 parent a81f384 commit b5b2855

File tree

1 file changed

+11
-9
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator

1 file changed

+11
-9
lines changed

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getSubscriptionStatus,
1111
getUsage,
1212
} from '@/lib/subscription/helpers'
13+
import { isUsageAtLimit, USAGE_PILL_COLORS } from '@/lib/subscription/usage-visualization'
1314
import { useSubscriptionData } from '@/hooks/queries/subscription'
1415
import { MIN_SIDEBAR_WIDTH, useSidebarStore } from '@/stores/sidebar/store'
1516

@@ -116,11 +117,12 @@ export function UsageIndicator({ onClick }: UsageIndicatorProps) {
116117

117118
/**
118119
* Calculate which pills should be filled based on usage percentage.
119-
* Uses Math.ceil heuristic with dynamic pill count (6-8).
120-
* This ensures consistent calculation logic while maintaining responsive pill count.
120+
* Uses a percentage-based heuristic with dynamic pill count (6-8).
121+
* The warning/limit (red) state is derived from shared usage visualization utilities
122+
* so it is consistent with other parts of the app (e.g. UsageHeader).
121123
*/
122124
const filledPillsCount = Math.ceil((progressPercentage / 100) * pillCount)
123-
const isAlmostOut = filledPillsCount === pillCount
125+
const isAtLimit = isUsageAtLimit(progressPercentage)
124126

125127
const [isHovered, setIsHovered] = useState(false)
126128
const [wavePosition, setWavePosition] = useState<number | null>(null)
@@ -286,17 +288,17 @@ export function UsageIndicator({ onClick }: UsageIndicatorProps) {
286288
const isFilled = i < filledPillsCount
287289

288290
const baseColor = isFilled
289-
? isBlocked || isAlmostOut
290-
? '#ef4444'
291-
: '#34B5FF'
292-
: '#414141'
291+
? isBlocked || isAtLimit
292+
? USAGE_PILL_COLORS.AT_LIMIT
293+
: USAGE_PILL_COLORS.FILLED
294+
: USAGE_PILL_COLORS.UNFILLED
293295

294296
let backgroundColor = baseColor
295297
let backgroundImage: string | undefined
296298

297299
if (isHovered && wavePosition !== null && pillCount > 0 && subscription.isFree) {
298-
const grayColor = '#414141'
299-
const activeColor = isAlmostOut ? '#ef4444' : '#34B5FF'
300+
const grayColor = USAGE_PILL_COLORS.UNFILLED
301+
const activeColor = isAtLimit ? USAGE_PILL_COLORS.AT_LIMIT : USAGE_PILL_COLORS.FILLED
300302

301303
/**
302304
* Single-pass wave: travel from {@link startAnimationIndex} to the end

0 commit comments

Comments
 (0)