diff --git a/components/shared/nav-bar.tsx b/components/shared/nav-bar.tsx
index f7cc8a8..9f38668 100644
--- a/components/shared/nav-bar.tsx
+++ b/components/shared/nav-bar.tsx
@@ -1,13 +1,23 @@
'use client'
import Link from 'next/link'
-import { usePathname } from 'next/navigation'
+import { usePathname, useRouter } from 'next/navigation'
+import { useTransition } from 'react'
+import { ChevronDown } from 'lucide-react'
+import { toast } from 'sonner'
import { Badge } from '@/components/ui/badge'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu'
import { AppIcon } from '@/components/shared/app-icon'
import { UserMenu } from '@/components/shared/user-menu'
import { cn } from '@/lib/utils'
-import { useProductStore } from '@/stores/product-store'
+import { setActiveProductAction } from '@/actions/active-product'
interface NavBarProps {
isDemo: boolean
@@ -16,23 +26,83 @@ interface NavBarProps {
username: string
email: string | null
activeProduct: { id: string; name: string } | null
+ products: { id: string; name: string }[]
+ hasActiveSprint: boolean
}
-export function NavBar({ isDemo, roles, userId, username, email, activeProduct: _activeProduct }: NavBarProps) {
+export function NavBar({
+ isDemo,
+ roles,
+ userId,
+ username,
+ email,
+ activeProduct,
+ products,
+ hasActiveSprint,
+}: NavBarProps) {
const pathname = usePathname()
- const currentProduct = useProductStore(s => s.currentProduct)
+ const router = useRouter()
+ const [isPending, startTransition] = useTransition()
- const productMatch = pathname.match(/^\/products\/([^/]+)/)
- const productId = productMatch ? productMatch[1] : null
+ function handleSwitchProduct(productId: string) {
+ startTransition(async () => {
+ const result = await setActiveProductAction(productId)
+ if (result?.error) {
+ toast.error(typeof result.error === 'string' ? result.error : 'Wisselen mislukt')
+ } else {
+ router.push(`/products/${productId}`)
+ }
+ })
+ }
- const sprintHref = productId ? `/products/${productId}/sprint` : null
+ const activeId = activeProduct?.id ?? null
- const navLinks = [
- { href: '/dashboard', label: 'Producten', active: pathname.startsWith('/dashboard') || (pathname.startsWith('/products') && !pathname.includes('/solo')) },
- { href: sprintHref, label: 'Sprint', active: pathname.includes('/sprint') },
- { href: '/solo', label: 'Solo', active: pathname.includes('/solo') },
- { href: '/todos', label: "Todo's", active: pathname.startsWith('/todos') },
- ]
+ // Nav link helpers
+ const disabledSpan = (label: string) => (
+
+ {label}
+
+ )
+
+ const navLink = (href: string, label: string, isActive: boolean) => (
+
+ {label}
+
+ )
+
+ const sprintNode = () => {
+ if (!activeId) return disabledSpan('Sprint')
+ const href = `/products/${activeId}/sprint`
+ const isActive = pathname.includes('/sprint')
+ if (!hasActiveSprint) {
+ return (
+
+
+
+ Sprint
+
+ Geen actieve sprint
+
+
+ )
+ }
+ return navLink(href, 'Sprint', isActive)
+ }
return (
@@ -49,50 +119,63 @@ export function NavBar({ isDemo, roles, userId, username, email, activeProduct:
- {/* Midden: productnaam */}
+ {/* Midden: actief product dropdown */}
- {currentProduct && (
-
-
-
- }>
- {currentProduct.name.length > 20
- ? currentProduct.name.slice(0, 20) + '…'
- : currentProduct.name}
-
- {currentProduct.name}
-
-
+ {activeProduct ? (
+
+
+
+ {activeProduct.name.length > 22
+ ? activeProduct.name.slice(0, 22) + '…'
+ : activeProduct.name}
+
+
+
+
+ {products.map(p => (
+ p.id !== activeProduct.id && handleSwitchProduct(p.id)}
+ className={cn(
+ p.id === activeProduct.id && 'bg-primary-container text-primary-container-foreground font-medium'
+ )}
+ >
+ {p.name}
+
+ ))}
+
+
+
+ Producten beheren →
+
+
+
+
+ ) : (
+ Geen actief product
)}