Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions frontend/src/components/dashboard/DashboardHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AnimatePresence } from 'framer-motion'
import { toast } from 'sonner'
import { useAuth } from '../../contexts/AuthContext'
import { useRepos, useUserUsage } from '../../hooks/useCachedQuery'
import { API_URL, MAX_FREE_REPOS } from '../../config/api'
import { API_URL } from '../../config/api'
import { extractErrorMessage, isUpgradeError } from '../../lib/api-errors'
import { RepoListView } from './RepoListView'
import { RepoDetailView } from './RepoDetailView'
Expand All @@ -24,6 +24,7 @@ export function DashboardHome() {
const [searchParams, setSearchParams] = useSearchParams()
const { data: repos = [], isLoading: reposLoading, invalidate: refreshRepos } = useRepos(session?.access_token)
const { data: usage } = useUserUsage(session?.access_token, session?.user?.id)
const maxRepos = usage?.repositories?.limit ?? 1
Comment thread
coderabbitai[bot] marked this conversation as resolved.

const [selectedRepo, setSelectedRepo] = useState<string | null>(null)
const [activeTab, setActiveTab] = useState<RepoTab>('overview')
Expand Down Expand Up @@ -223,6 +224,7 @@ export function DashboardHome() {
loading={loading}
reposLoading={reposLoading}
selectedRepo={selectedRepo}
maxRepos={maxRepos}
onSelectRepo={(id) => { setSelectedRepo(id); setActiveTab('overview') }}
onAddClick={() => setShowAddForm(true)}
onGitHubClick={() => setShowGitHubSelector(true)}
Expand Down Expand Up @@ -280,7 +282,7 @@ export function DashboardHome() {
isOpen={showGitHubSelector}
onClose={() => setShowGitHubSelector(false)}
onImport={handleGitHubImport}
maxSelectable={MAX_FREE_REPOS}
maxSelectable={maxRepos}
currentRepoCount={repos.length}
/>

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/dashboard/RepoListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { Plus, Github } from 'lucide-react'
import { Button } from '../ui/button'
import { RepoList } from '../RepoList'
import { DashboardStats } from './DashboardStats'
import { MAX_FREE_REPOS } from '../../config/api'
import type { Repository } from '../../types'

interface RepoListViewProps {
repos: Repository[]
loading: boolean
reposLoading: boolean
selectedRepo: string | null
maxRepos: number
onSelectRepo: (id: string) => void
onAddClick: () => void
onGitHubClick: () => void
Expand All @@ -24,6 +24,7 @@ export function RepoListView({
loading,
reposLoading,
selectedRepo,
maxRepos,
onSelectRepo,
onAddClick,
onGitHubClick,
Expand All @@ -47,15 +48,15 @@ export function RepoListView({
<Button
onClick={onGitHubClick}
variant="outline"
disabled={loading || repos.length >= MAX_FREE_REPOS}
disabled={loading || repos.length >= maxRepos}
className="gap-2"
>
<Github className="w-4 h-4" />
Import from GitHub
</Button>
<Button
onClick={onAddClick}
disabled={loading || repos.length >= MAX_FREE_REPOS}
disabled={loading || repos.length >= maxRepos}
className="bg-primary hover:bg-primary/90 text-primary-foreground gap-2"
>
<Plus className="w-4 h-4" />
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/components/dashboard/TopNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link } from 'react-router-dom'
import { useAuth } from '../../contexts/AuthContext'
import { TIER_FUNCTION_LIMITS, type TierName } from '../../config/api'
import { useUserUsage } from '../../hooks/useCachedQuery'
import { Menu, Search, Github, Sun, Moon, LogOut, Settings, BookOpen, ExternalLink } from 'lucide-react'
import { useTheme } from 'next-themes'
import { Button } from '@/components/ui/button'
Expand All @@ -25,9 +25,10 @@ export function TopNav({ onToggleSidebar, sidebarCollapsed, onOpenCommandPalette

const userEmail = session?.user?.email || 'User'
const userInitial = userEmail.charAt(0).toUpperCase()
const rawTier = session?.user?.user_metadata?.tier as string
const userTier: TierName = rawTier && rawTier in TIER_FUNCTION_LIMITS ? (rawTier as TierName) : 'free'
const tierLabel = `${userTier.charAt(0).toUpperCase()}${userTier.slice(1)} Plan`
const { data: usage } = useUserUsage(session?.access_token, session?.user?.id)
const tierLabel = usage?.tier
? `${usage.tier.charAt(0).toUpperCase()}${usage.tier.slice(1)} Plan`
: ''

const toggleTheme = () => {
setTheme(theme === 'dark' ? 'light' : 'dark')
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/hooks/useCachedQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,20 @@ export function useUserUsage(apiKey: string | undefined, userId?: string) {
const data = await fetchWithAuth(`${API_URL}/users/usage`, apiKey!)
return data as {
tier: string
repositories: {
current: number
limit: number
display: string
}
limits: {
max_files_per_repo: number
max_functions_per_repo: number
playground_searches_per_day: number | null
}
features: {
priority_indexing: boolean
mcp_access: boolean
}
}
},
enabled: !!apiKey,
Expand Down