+ {/* Midden: actief product dropdown */}
+
{activeProduct ? (
Geen actief product
)}
-
- {activeProduct && (
- sprints.length === 0 ? (
-
-
-
- Geen sprints
-
- Maak een sprint aan vanuit de Product Backlog
-
-
- ) : (
-
-
-
- {activeSprint ? activeSprint.code : 'Selecteer sprint'}
-
- {activeSprint && (
-
- {buildingSet.has(activeSprint.id) ? 'BUILDING' : SPRINT_STATUS_LABEL[activeSprint.status]}
-
- )}
-
-
-
- {sprints.map(s => (
- handleSwitchSprint(s.id)}
- className={cn(
- 'flex items-center justify-between gap-2',
- s.id === activeSprint?.id && 'bg-primary-container text-primary-container-foreground font-medium',
- )}
- >
- {s.code}
-
- {buildingSet.has(s.id) ? 'BUILDING' : SPRINT_STATUS_LABEL[s.status]}
-
-
- ))}
-
-
- )
- )}
{/* Rechts: solo-status + notifications + account-menu */}
diff --git a/components/sprint/sprint-switcher.tsx b/components/sprint/sprint-switcher.tsx
new file mode 100644
index 0000000..6f5fbbd
--- /dev/null
+++ b/components/sprint/sprint-switcher.tsx
@@ -0,0 +1,84 @@
+'use client'
+
+import { useTransition } from 'react'
+import { usePathname, useRouter } from 'next/navigation'
+import { ChevronDown } from 'lucide-react'
+import { toast } from 'sonner'
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from '@/components/ui/dropdown-menu'
+import { cn } from '@/lib/utils'
+import { setActiveSprintAction } from '@/actions/active-sprint'
+
+type SprintItem = { id: string; code: string }
+
+interface SprintSwitcherProps {
+ productId: string
+ sprints: SprintItem[]
+ activeSprintId: string | null
+ className?: string
+}
+
+export function SprintSwitcher({
+ productId,
+ sprints,
+ activeSprintId,
+ className,
+}: SprintSwitcherProps) {
+ const router = useRouter()
+ const pathname = usePathname()
+ const [isPending, startTransition] = useTransition()
+
+ if (sprints.length === 0) return null
+
+ const active = sprints.find(s => s.id === activeSprintId) ?? sprints[0]
+
+ function handleSwitch(sprintId: string) {
+ if (sprintId === active.id) return
+ startTransition(async () => {
+ const result = await setActiveSprintAction(productId, sprintId)
+ if (result?.error) {
+ toast.error(typeof result.error === 'string' ? result.error : 'Wisselen mislukt')
+ return
+ }
+ if (pathname.includes('/sprint')) {
+ router.push(`/products/${productId}/sprint/${sprintId}`)
+ } else {
+ router.refresh()
+ }
+ })
+ }
+
+ return (
+
+
+
+ {active.code.length > 22 ? active.code.slice(0, 22) + '…' : active.code}
+
+
+
+
+ {sprints.map(s => (
+ handleSwitch(s.id)}
+ className={cn(
+ s.id === active.id && 'bg-primary-container text-primary-container-foreground font-medium',
+ )}
+ >
+ {s.code}
+
+ ))}
+
+
+ )
+}