Skip to content

Commit 83f1139

Browse files
feat(usage-indicator): added ability to see current usage (#925)
* feat(usage-indicator): added ability to see current usage * feat(billing): added billing ennabled flag for usage indicator, enforcement of billing usage --------- Co-authored-by: waleedlatif1 <walif6@gmail.com>
1 parent 56ede1c commit 83f1139

File tree

18 files changed

+632
-175
lines changed

18 files changed

+632
-175
lines changed

apps/sim/app/api/chat/route.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ describe('Chat API Route', () => {
245245
NODE_ENV: 'development',
246246
NEXT_PUBLIC_APP_URL: 'http://localhost:3000',
247247
},
248+
isTruthy: (value: string | boolean | number | undefined) =>
249+
typeof value === 'string' ? value === 'true' || value === '1' : Boolean(value),
248250
}))
249251

250252
const validData = {
@@ -287,6 +289,8 @@ describe('Chat API Route', () => {
287289
NODE_ENV: 'development',
288290
NEXT_PUBLIC_APP_URL: 'http://localhost:3000',
289291
},
292+
isTruthy: (value: string | boolean | number | undefined) =>
293+
typeof value === 'string' ? value === 'true' || value === '1' : Boolean(value),
290294
}))
291295

292296
const validData = {

apps/sim/app/api/knowledge/search/route.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ vi.mock('@/lib/env', () => ({
3030
env: {
3131
OPENAI_API_KEY: 'test-api-key',
3232
},
33+
isTruthy: (value: string | boolean | number | undefined) =>
34+
typeof value === 'string' ? value === 'true' || value === '1' : Boolean(value),
3335
}))
3436

3537
vi.mock('@/lib/documents/utils', () => ({

apps/sim/app/api/knowledge/utils.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ vi.mock('drizzle-orm', () => ({
1515
sql: (strings: TemplateStringsArray, ...expr: any[]) => ({ strings, expr }),
1616
}))
1717

18-
vi.mock('@/lib/env', () => ({ env: { OPENAI_API_KEY: 'test-key' } }))
18+
vi.mock('@/lib/env', () => ({
19+
env: { OPENAI_API_KEY: 'test-key' },
20+
isTruthy: (value: string | boolean | number | undefined) =>
21+
typeof value === 'string' ? value === 'true' || value === '1' : Boolean(value),
22+
}))
1923

2024
vi.mock('@/lib/documents/utils', () => ({
2125
retryWithExponentialBackoff: (fn: any) => fn(),

apps/sim/app/globals.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989

9090
/* Base Component Properties */
9191
--base-muted-foreground: #737373;
92+
93+
/* Gradient Colors */
94+
--gradient-primary: 263 85% 70%; /* More vibrant purple */
95+
--gradient-secondary: 336 95% 65%; /* More vibrant pink */
9296
}
9397

9498
/* Dark Mode Theme */
@@ -145,6 +149,10 @@
145149

146150
/* Base Component Properties */
147151
--base-muted-foreground: #a3a3a3;
152+
153+
/* Gradient Colors - Adjusted for dark mode */
154+
--gradient-primary: 263 90% 75%; /* More vibrant purple for dark mode */
155+
--gradient-secondary: 336 100% 72%; /* More vibrant pink for dark mode */
148156
}
149157
}
150158

@@ -325,6 +333,13 @@ input[type="search"]::-ms-clear {
325333
background: transparent;
326334
}
327335

336+
/* Gradient Text Utility - Use with Tailwind gradient directions */
337+
.gradient-text {
338+
-webkit-background-clip: text;
339+
-webkit-text-fill-color: transparent;
340+
background-clip: text;
341+
}
342+
328343
/* Animation Classes */
329344
.animate-pulse-ring {
330345
animation: pulse-ring 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ export { FolderTree } from './folder-tree/folder-tree'
33
export { HelpModal } from './help-modal/help-modal'
44
export { LogsFilters } from './logs-filters/logs-filters'
55
export { SettingsModal } from './settings-modal/settings-modal'
6+
export { SubscriptionModal } from './subscription-modal/subscription-modal'
67
export { Toolbar } from './toolbar/toolbar'
8+
export { UsageIndicator } from './usage-indicator/usage-indicator'
79
export { WorkflowContextMenu } from './workflow-context-menu/workflow-context-menu'
810
export { WorkflowList } from './workflow-list/workflow-list'
911
export { WorkspaceHeader } from './workspace-header/workspace-header'

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/settings-navigation/settings-navigation.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
UserCircle,
99
Users,
1010
} from 'lucide-react'
11-
import { isDev } from '@/lib/environment'
11+
import { isBillingEnabled } from '@/lib/environment'
1212
import { cn } from '@/lib/utils'
1313
import { useSubscriptionStore } from '@/stores/subscription/store'
1414

@@ -40,7 +40,7 @@ type NavigationItem = {
4040
| 'privacy'
4141
label: string
4242
icon: React.ComponentType<{ className?: string }>
43-
hideInDev?: boolean
43+
hideWhenBillingDisabled?: boolean
4444
requiresTeam?: boolean
4545
}
4646

@@ -79,13 +79,13 @@ const allNavigationItems: NavigationItem[] = [
7979
id: 'subscription',
8080
label: 'Subscription',
8181
icon: CreditCard,
82-
hideInDev: true,
82+
hideWhenBillingDisabled: true,
8383
},
8484
{
8585
id: 'team',
8686
label: 'Team',
8787
icon: Users,
88-
hideInDev: true,
88+
hideWhenBillingDisabled: true,
8989
requiresTeam: true,
9090
},
9191
]
@@ -99,7 +99,7 @@ export function SettingsNavigation({
9999
const subscription = getSubscriptionStatus()
100100

101101
const navigationItems = allNavigationItems.filter((item) => {
102-
if (item.hideInDev && isDev) {
102+
if (item.hideWhenBillingDisabled && !isBillingEnabled) {
103103
return false
104104
}
105105

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/settings-modal/settings-modal.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useEffect, useRef, useState } from 'react'
44
import { X } from 'lucide-react'
55
import { Button, Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui'
6-
import { client } from '@/lib/auth-client'
6+
import { isBillingEnabled } from '@/lib/environment'
77
import { createLogger } from '@/lib/logs/console/logger'
88
import { cn } from '@/lib/utils'
99
import {
@@ -82,7 +82,14 @@ export function SettingsModal({ open, onOpenChange }: SettingsModalProps) {
8282
}
8383
}, [onOpenChange])
8484

85-
const isSubscriptionEnabled = !!client.subscription
85+
// Redirect away from billing tabs if billing is disabled
86+
useEffect(() => {
87+
if (!isBillingEnabled && (activeSection === 'subscription' || activeSection === 'team')) {
88+
setActiveSection('general')
89+
}
90+
}, [activeSection])
91+
92+
const isSubscriptionEnabled = isBillingEnabled
8693

8794
return (
8895
<Dialog open={open} onOpenChange={onOpenChange}>
@@ -134,9 +141,11 @@ export function SettingsModal({ open, onOpenChange }: SettingsModalProps) {
134141
<Subscription onOpenChange={onOpenChange} />
135142
</div>
136143
)}
137-
<div className={cn('h-full', activeSection === 'team' ? 'block' : 'hidden')}>
138-
<TeamManagement />
139-
</div>
144+
{isBillingEnabled && (
145+
<div className={cn('h-full', activeSection === 'team' ? 'block' : 'hidden')}>
146+
<TeamManagement />
147+
</div>
148+
)}
140149
<div className={cn('h-full', activeSection === 'privacy' ? 'block' : 'hidden')}>
141150
<Privacy />
142151
</div>

0 commit comments

Comments
 (0)