@@ -4,12 +4,13 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
44import { Table , TableBody , TableCell , TableHead , TableHeader , TableRow } from "@/components/ui/table" ;
55import { Badge } from "@/components/ui/badge" ;
66import { Button } from "@/components/ui/button" ;
7- import { TrendingUp , TrendingDown , RefreshCw , Loader2 , Eye , Activity , Clock , AlertCircle , AlertTriangle } from "lucide-react" ;
7+ import { TrendingUp , TrendingDown , RefreshCw , Loader2 , Eye , Activity , Clock , AlertCircle , AlertTriangle , Lock } from "lucide-react" ;
88import { alpacaAPI } from "@/lib/alpaca" ;
99import { useAuth } from "@/lib/auth" ;
1010import { supabase } from "@/lib/supabase" ;
1111import { useToast } from "@/hooks/use-toast" ;
1212import { useAlpacaConnectionStore } from "@/hooks/useAlpacaConnection" ;
13+ import { useRBAC } from "@/hooks/useRBAC" ;
1314import {
1415 AlertDialog ,
1516 AlertDialogContent ,
@@ -52,6 +53,7 @@ export default function PortfolioPositions({ onSelectStock, selectedStock }: Por
5253 const { apiSettings, isAuthenticated, user } = useAuth ( ) ;
5354 const { toast } = useToast ( ) ;
5455 const { isConnected : isAlpacaConnected } = useAlpacaConnectionStore ( ) ;
56+ const { hasRebalanceAccess } = useRBAC ( ) ;
5557 const [ positions , setPositions ] = useState < Position [ ] > ( [ ] ) ;
5658 const [ loading , setLoading ] = useState ( false ) ;
5759 const [ error , setError ] = useState < string | null > ( null ) ;
@@ -63,6 +65,7 @@ export default function PortfolioPositions({ onSelectStock, selectedStock }: Por
6365 const [ runningRebalance , setRunningRebalance ] = useState < string | null > ( null ) ; // Store rebalance_request_id
6466 const [ runningAnalysesCount , setRunningAnalysesCount ] = useState ( 0 ) ;
6567 const [ showAnalysisAlert , setShowAnalysisAlert ] = useState ( false ) ;
68+ const [ showRebalanceAccessAlert , setShowRebalanceAccessAlert ] = useState ( false ) ;
6669
6770 // Use ref to track previous running rebalance
6871 const previousRunningRef = useRef < string | null > ( null ) ;
@@ -73,6 +76,12 @@ export default function PortfolioPositions({ onSelectStock, selectedStock }: Por
7376 return ;
7477 }
7578
79+ // Check if user has rebalance access
80+ if ( ! hasRebalanceAccess ( ) ) {
81+ setShowRebalanceAccessAlert ( true ) ;
82+ return ;
83+ }
84+
7685 // Check if there are running analyses
7786 if ( runningAnalysesCount > 0 ) {
7887 setShowAnalysisAlert ( true ) ;
@@ -379,6 +388,11 @@ export default function PortfolioPositions({ onSelectStock, selectedStock }: Por
379388 < AlertTriangle className = "h-4 w-4 mr-1" />
380389 Connection Error
381390 </ >
391+ ) : ! hasRebalanceAccess ( ) ? (
392+ < >
393+ < Lock className = "h-4 w-4 mr-1" />
394+ Rebalance
395+ </ >
382396 ) : (
383397 < >
384398 < RefreshCw className = "h-4 w-4 mr-1" />
@@ -667,6 +681,31 @@ export default function PortfolioPositions({ onSelectStock, selectedStock }: Por
667681 </ AlertDialogFooter >
668682 </ AlertDialogContent >
669683 </ AlertDialog >
684+
685+ { /* No Rebalance Access Alert Dialog */ }
686+ < AlertDialog open = { showRebalanceAccessAlert } onOpenChange = { setShowRebalanceAccessAlert } >
687+ < AlertDialogContent >
688+ < AlertDialogHeader >
689+ < AlertDialogTitle className = "flex items-center gap-2" >
690+ < Lock className = "h-5 w-5 text-yellow-500" />
691+ Rebalance Access Required
692+ </ AlertDialogTitle >
693+ < AlertDialogDescription className = "space-y-2" >
694+ < p >
695+ Your current subscription plan doesn't include portfolio rebalancing features.
696+ </ p >
697+ < p >
698+ Please upgrade your plan to access portfolio rebalancing capabilities.
699+ </ p >
700+ </ AlertDialogDescription >
701+ </ AlertDialogHeader >
702+ < AlertDialogFooter >
703+ < AlertDialogAction onClick = { ( ) => setShowRebalanceAccessAlert ( false ) } >
704+ OK
705+ </ AlertDialogAction >
706+ </ AlertDialogFooter >
707+ </ AlertDialogContent >
708+ </ AlertDialog >
670709 </ >
671710 ) ;
672711}
0 commit comments