@@ -49,7 +49,7 @@ interface StandaloneWatchlistProps {
4949
5050export default function StandaloneWatchlist ( { onSelectStock, selectedStock } : StandaloneWatchlistProps ) {
5151 const { user, isAuthenticated, apiSettings } = useAuth ( ) ;
52- const { getMaxParallelAnalysis } = useRBAC ( ) ;
52+ const { getMaxParallelAnalysis, getMaxWatchlistStocks } = useRBAC ( ) ;
5353 const { toast } = useToast ( ) ;
5454 const { isConnected : isAlpacaConnected } = useAlpacaConnectionStore ( ) ;
5555 const [ watchlist , setWatchlist ] = useState < WatchlistItem [ ] > ( [ ] ) ;
@@ -60,8 +60,16 @@ export default function StandaloneWatchlist({ onSelectStock, selectedStock }: St
6060 const [ showLimitAlert , setShowLimitAlert ] = useState ( false ) ;
6161 const [ showRebalanceAlert , setShowRebalanceAlert ] = useState ( false ) ;
6262 const [ hasRunningRebalance , setHasRunningRebalance ] = useState ( false ) ;
63+ const [ showWatchlistLimitAlert , setShowWatchlistLimitAlert ] = useState ( false ) ;
6364
6465 const maxParallelAnalysis = getMaxParallelAnalysis ( ) ;
66+ const maxWatchlistStocks = getMaxWatchlistStocks ( ) ;
67+
68+ // Debug: Log the watchlist limit
69+ useEffect ( ( ) => {
70+ console . log ( '[StandaloneWatchlist] Max watchlist stocks:' , maxWatchlistStocks ) ;
71+ console . log ( '[StandaloneWatchlist] Current watchlist length:' , watchlist . length ) ;
72+ } , [ maxWatchlistStocks , watchlist . length ] ) ;
6573
6674 // Fetch stock data including description and price using Alpaca
6775 const fetchStockData = async ( ticker : string ) => {
@@ -331,6 +339,13 @@ export default function StandaloneWatchlist({ onSelectStock, selectedStock }: St
331339 if ( ! user || ! newTicker ) return ;
332340
333341 const ticker = newTicker . toUpperCase ( ) ;
342+
343+ // Check if user has reached watchlist limit first
344+ if ( watchlist . length >= maxWatchlistStocks && maxWatchlistStocks > 0 ) {
345+ setShowWatchlistLimitAlert ( true ) ;
346+ return ;
347+ }
348+
334349 if ( watchlist . find ( item => item . ticker === ticker ) ) {
335350 toast ( {
336351 title : "Already in watchlist" ,
@@ -591,7 +606,12 @@ export default function StandaloneWatchlist({ onSelectStock, selectedStock }: St
591606 < >
592607 < Card >
593608 < CardHeader className = "flex flex-row items-center justify-between" >
594- < CardTitle > Watchlist</ CardTitle >
609+ < div className = "flex items-center gap-2" >
610+ < CardTitle > Watchlist</ CardTitle >
611+ < span className = "text-sm text-muted-foreground" >
612+ ({ watchlist . length } /{ maxWatchlistStocks } )
613+ </ span >
614+ </ div >
595615 < Button size = "sm" variant = "outline" onClick = { refreshPrices } >
596616 < RefreshCw className = "h-4 w-4 mr-1" />
597617 Refresh
@@ -605,14 +625,13 @@ export default function StandaloneWatchlist({ onSelectStock, selectedStock }: St
605625 value = { newTicker }
606626 onChange = { setNewTicker }
607627 placeholder = "Add ticker to watchlist"
608- onKeyPress = { ( e : React . KeyboardEvent ) => {
609- if ( e . key === 'Enter' ) {
610- addToWatchlist ( ) ;
611- }
612- } }
613628 />
614629 </ div >
615- < Button onClick = { addToWatchlist } disabled = { ! newTicker } >
630+ < Button
631+ onClick = { addToWatchlist }
632+ disabled = { ! newTicker }
633+ title = "Add to watchlist"
634+ >
616635 < Plus className = "h-4 w-4" />
617636 </ Button >
618637 </ div >
@@ -825,6 +844,31 @@ export default function StandaloneWatchlist({ onSelectStock, selectedStock }: St
825844 </ AlertDialogFooter >
826845 </ AlertDialogContent >
827846 </ AlertDialog >
847+
848+ { /* Watchlist Limit Alert Dialog */ }
849+ < AlertDialog open = { showWatchlistLimitAlert } onOpenChange = { setShowWatchlistLimitAlert } >
850+ < AlertDialogContent >
851+ < AlertDialogHeader >
852+ < AlertDialogTitle className = "flex items-center gap-2" >
853+ < AlertCircle className = "h-5 w-5 text-yellow-500" />
854+ Watchlist Limit Reached
855+ </ AlertDialogTitle >
856+ < AlertDialogDescription className = "space-y-2" >
857+ < p >
858+ You have reached your maximum limit of { maxWatchlistStocks } stocks in your watchlist.
859+ </ p >
860+ < p >
861+ Please remove some stocks from your watchlist before adding new ones.
862+ </ p >
863+ </ AlertDialogDescription >
864+ </ AlertDialogHeader >
865+ < AlertDialogFooter >
866+ < AlertDialogAction onClick = { ( ) => setShowWatchlistLimitAlert ( false ) } >
867+ OK
868+ </ AlertDialogAction >
869+ </ AlertDialogFooter >
870+ </ AlertDialogContent >
871+ </ AlertDialog >
828872 </ >
829873 ) ;
830874}
0 commit comments