From d92e548f8854686309921de7770b7c017ce1eceb Mon Sep 17 00:00:00 2001 From: janpeter visser Date: Fri, 24 Apr 2026 11:51:27 +0200 Subject: [PATCH] feat: ST-301-ST-312 M3 Sprint Backlog en Sprint Planning - useSprintStore met sprintStoryOrder/taskOrder (ST-301) - Sprint aanmaken modal met Sprint Goal validatie (ST-302) - Sprint Backlog pagina SplitPane layout met Sprint Goal header (ST-303) - Stories toevoegen aan Sprint via knop in rechterpaneel (ST-304) - Sprint Backlog volgorde aanpassen via dnd-kit (ST-305) - Story uit Sprint verwijderen met status terug naar OPEN (ST-306) - Sprint Planning pagina SplitPane met story selectie (ST-307) - Taken aanmaken inline in rechterpaneel (ST-308) - Taak drag-and-drop verticaal met optimistische update (ST-309) - Taakstatus toggle TO_DO/IN_PROGRESS/DONE met voortgangsindicator (ST-310) - Taak inline bewerken en verwijderen (ST-311) - Sprint afronden dialoog met per-story Done/Terug keuze (ST-312) Co-Authored-By: Claude Sonnet 4.6 --- actions/sprints.ts | 181 +++++++++++++ actions/tasks.ts | 141 ++++++++++ app/(app)/products/[id]/page.tsx | 26 +- app/(app)/products/[id]/sprint/page.tsx | 119 +++++++++ .../products/[id]/sprint/planning/page.tsx | 135 ++++++++++ components/sprint/planning-left.tsx | 57 ++++ components/sprint/planning-right-client.tsx | 39 +++ components/sprint/sprint-backlog.tsx | 246 ++++++++++++++++++ components/sprint/sprint-header.tsx | 144 ++++++++++ components/sprint/start-sprint-button.tsx | 96 +++++++ components/sprint/task-list.tsx | 245 +++++++++++++++++ stores/sprint-store.ts | 57 ++++ 12 files changed, 1480 insertions(+), 6 deletions(-) create mode 100644 actions/sprints.ts create mode 100644 actions/tasks.ts create mode 100644 app/(app)/products/[id]/sprint/page.tsx create mode 100644 app/(app)/products/[id]/sprint/planning/page.tsx create mode 100644 components/sprint/planning-left.tsx create mode 100644 components/sprint/planning-right-client.tsx create mode 100644 components/sprint/sprint-backlog.tsx create mode 100644 components/sprint/sprint-header.tsx create mode 100644 components/sprint/start-sprint-button.tsx create mode 100644 components/sprint/task-list.tsx create mode 100644 stores/sprint-store.ts diff --git a/actions/sprints.ts b/actions/sprints.ts new file mode 100644 index 0000000..583fffb --- /dev/null +++ b/actions/sprints.ts @@ -0,0 +1,181 @@ +'use server' + +import { revalidatePath } from 'next/cache' +import { cookies } from 'next/headers' +import { getIronSession } from 'iron-session' +import { z } from 'zod' +import { prisma } from '@/lib/prisma' +import { SessionData, sessionOptions } from '@/lib/session' + +async function getSession() { + return getIronSession(await cookies(), sessionOptions) +} + +async function verifyProductOwnership(productId: string, userId: string) { + return prisma.product.findFirst({ where: { id: productId, user_id: userId } }) +} + +// --- Sprint --- + +export async function createSprintAction(_prevState: unknown, formData: FormData) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const parsed = z.object({ + productId: z.string(), + sprint_goal: z.string().min(1, 'Sprint Goal is verplicht').max(500), + }).safeParse({ + productId: formData.get('productId'), + sprint_goal: formData.get('sprint_goal'), + }) + if (!parsed.success) return { error: parsed.error.flatten().fieldErrors } + + const product = await verifyProductOwnership(parsed.data.productId, session.userId) + if (!product) return { error: 'Product niet gevonden' } + + const existing = await prisma.sprint.findFirst({ + where: { product_id: parsed.data.productId, status: 'ACTIVE' }, + }) + if (existing) return { error: 'Er is al een actieve Sprint voor dit product', sprintId: existing.id } + + const sprint = await prisma.sprint.create({ + data: { + product_id: parsed.data.productId, + sprint_goal: parsed.data.sprint_goal, + status: 'ACTIVE', + }, + }) + + revalidatePath(`/products/${parsed.data.productId}`) + return { success: true, sprintId: sprint.id } +} + +export async function updateSprintGoalAction(_prevState: unknown, formData: FormData) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const id = formData.get('id') as string + const sprint_goal = formData.get('sprint_goal') as string + if (!sprint_goal?.trim()) return { error: 'Sprint Goal is verplicht' } + + const sprint = await prisma.sprint.findFirst({ + where: { id, product: { user_id: session.userId } }, + }) + if (!sprint) return { error: 'Sprint niet gevonden' } + + await prisma.sprint.update({ where: { id }, data: { sprint_goal } }) + revalidatePath(`/products/${sprint.product_id}/sprint`) + return { success: true } +} + +export async function addStoryToSprintAction(sprintId: string, storyId: string) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const sprint = await prisma.sprint.findFirst({ + where: { id: sprintId, product: { user_id: session.userId } }, + }) + if (!sprint) return { error: 'Sprint niet gevonden' } + + const story = await prisma.story.findFirst({ + where: { id: storyId, product: { user_id: session.userId } }, + }) + if (!story) return { error: 'Story niet gevonden' } + + // Sort order = last in sprint + 1 + const last = await prisma.story.findFirst({ + where: { sprint_id: sprintId }, + orderBy: { sort_order: 'desc' }, + }) + + await prisma.story.update({ + where: { id: storyId }, + data: { sprint_id: sprintId, status: 'IN_SPRINT', sort_order: (last?.sort_order ?? 0) + 1.0 }, + }) + + revalidatePath(`/products/${sprint.product_id}/sprint`) + revalidatePath(`/products/${sprint.product_id}`) + return { success: true } +} + +export async function removeStoryFromSprintAction(storyId: string) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const story = await prisma.story.findFirst({ + where: { id: storyId, product: { user_id: session.userId } }, + include: { sprint: true }, + }) + if (!story) return { error: 'Story niet gevonden' } + + const productId = story.product_id + + await prisma.story.update({ + where: { id: storyId }, + data: { sprint_id: null, status: 'OPEN' }, + }) + + revalidatePath(`/products/${productId}/sprint`) + revalidatePath(`/products/${productId}`) + return { success: true } +} + +export async function reorderSprintStoriesAction(sprintId: string, orderedIds: string[]) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const sprint = await prisma.sprint.findFirst({ + where: { id: sprintId, product: { user_id: session.userId } }, + }) + if (!sprint) return { error: 'Sprint niet gevonden' } + + await prisma.$transaction( + orderedIds.map((id, i) => + prisma.story.update({ where: { id }, data: { sort_order: i + 1.0 } }) + ) + ) + + revalidatePath(`/products/${sprint.product_id}/sprint`) + return { success: true } +} + +export async function completeSprintAction( + sprintId: string, + decisions: Record +) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const sprint = await prisma.sprint.findFirst({ + where: { id: sprintId, product: { user_id: session.userId } }, + }) + if (!sprint) return { error: 'Sprint niet gevonden' } + + await prisma.$transaction([ + // Update all story statuses based on decisions + ...Object.entries(decisions).map(([storyId, status]) => + prisma.story.update({ + where: { id: storyId }, + data: { + status, + sprint_id: status === 'OPEN' ? null : undefined, + }, + }) + ), + // Close the sprint + prisma.sprint.update({ + where: { id: sprintId }, + data: { status: 'COMPLETED', completed_at: new Date() }, + }), + ]) + + revalidatePath(`/products/${sprint.product_id}`) + revalidatePath(`/products/${sprint.product_id}/sprint`) + return { success: true } +} diff --git a/actions/tasks.ts b/actions/tasks.ts new file mode 100644 index 0000000..1b8a2cf --- /dev/null +++ b/actions/tasks.ts @@ -0,0 +1,141 @@ +'use server' + +import { revalidatePath } from 'next/cache' +import { cookies } from 'next/headers' +import { getIronSession } from 'iron-session' +import { z } from 'zod' +import { prisma } from '@/lib/prisma' +import { SessionData, sessionOptions } from '@/lib/session' + +async function getSession() { + return getIronSession(await cookies(), sessionOptions) +} + +const taskSchema = z.object({ + title: z.string().min(1, 'Titel is verplicht').max(200), + description: z.string().max(1000).optional(), + priority: z.coerce.number().int().min(1).max(4), +}) + +export async function createTaskAction(_prevState: unknown, formData: FormData) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const storyId = formData.get('storyId') as string + const sprintId = formData.get('sprintId') as string + + const parsed = taskSchema.safeParse({ + title: formData.get('title'), + description: formData.get('description') || undefined, + priority: formData.get('priority') ?? 2, + }) + if (!parsed.success) return { error: parsed.error.flatten().fieldErrors } + + const story = await prisma.story.findFirst({ + where: { id: storyId, product: { user_id: session.userId } }, + }) + if (!story) return { error: 'Story niet gevonden' } + + const last = await prisma.task.findFirst({ + where: { story_id: storyId }, + orderBy: { sort_order: 'desc' }, + }) + + const task = await prisma.task.create({ + data: { + story_id: storyId, + sprint_id: sprintId || null, + title: parsed.data.title, + description: parsed.data.description ?? null, + priority: parsed.data.priority, + sort_order: (last?.sort_order ?? 0) + 1.0, + status: 'TO_DO', + }, + }) + + revalidatePath(`/products/${story.product_id}/sprint/planning`) + return { success: true, task } +} + +export async function updateTaskAction(_prevState: unknown, formData: FormData) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const id = formData.get('id') as string + const parsed = taskSchema.safeParse({ + title: formData.get('title'), + description: formData.get('description') || undefined, + priority: formData.get('priority'), + }) + if (!parsed.success) return { error: parsed.error.flatten().fieldErrors } + + const task = await prisma.task.findFirst({ + where: { id }, + include: { story: { include: { product: true } } }, + }) + if (!task || task.story.product.user_id !== session.userId) return { error: 'Taak niet gevonden' } + + await prisma.task.update({ + where: { id }, + data: { title: parsed.data.title, description: parsed.data.description ?? null, priority: parsed.data.priority }, + }) + + revalidatePath(`/products/${task.story.product_id}/sprint/planning`) + return { success: true } +} + +export async function updateTaskStatusAction(id: string, status: 'TO_DO' | 'IN_PROGRESS' | 'DONE') { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const task = await prisma.task.findFirst({ + where: { id }, + include: { story: { include: { product: true } } }, + }) + if (!task || task.story.product.user_id !== session.userId) return { error: 'Taak niet gevonden' } + + await prisma.task.update({ where: { id }, data: { status } }) + + revalidatePath(`/products/${task.story.product_id}/sprint/planning`) + return { success: true } +} + +export async function deleteTaskAction(id: string) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const task = await prisma.task.findFirst({ + where: { id }, + include: { story: { include: { product: true } } }, + }) + if (!task || task.story.product.user_id !== session.userId) return { error: 'Taak niet gevonden' } + + await prisma.task.delete({ where: { id } }) + + revalidatePath(`/products/${task.story.product_id}/sprint/planning`) + return { success: true } +} + +export async function reorderTasksAction(storyId: string, orderedIds: string[]) { + const session = await getSession() + if (!session.userId) return { error: 'Niet ingelogd' } + if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } + + const story = await prisma.story.findFirst({ + where: { id: storyId, product: { user_id: session.userId } }, + }) + if (!story) return { error: 'Story niet gevonden' } + + await prisma.$transaction( + orderedIds.map((id, i) => + prisma.task.update({ where: { id }, data: { sort_order: i + 1.0 } }) + ) + ) + + revalidatePath(`/products/${story.product_id}/sprint/planning`) + return { success: true } +} diff --git a/app/(app)/products/[id]/page.tsx b/app/(app)/products/[id]/page.tsx index 03e6204..e6d35d2 100644 --- a/app/(app)/products/[id]/page.tsx +++ b/app/(app)/products/[id]/page.tsx @@ -7,6 +7,7 @@ import { SplitPane } from '@/components/split-pane/split-pane' import { PbiList } from '@/components/backlog/pbi-list' import { StoryPanel } from '@/components/backlog/story-panel' import type { Story } from '@/components/backlog/story-panel' +import { StartSprintButton } from '@/components/sprint/start-sprint-button' import Link from 'next/link' interface Props { @@ -22,6 +23,10 @@ export default async function ProductBacklogPage({ params }: Props) { }) if (!product) notFound() + const activeSprint = await prisma.sprint.findFirst({ + where: { product_id: id, status: 'ACTIVE' }, + }) + const pbis = await prisma.pbi.findMany({ where: { product_id: id }, orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }], @@ -60,12 +65,21 @@ export default async function ProductBacklogPage({ params }: Props) {

{product.description}

)} - - Instellingen - +
+ {activeSprint ? ( + + Sprint actief → + + ) : ( + !isDemo && + )} + + Instellingen + +
{/* Split pane */} diff --git a/app/(app)/products/[id]/sprint/page.tsx b/app/(app)/products/[id]/sprint/page.tsx new file mode 100644 index 0000000..f6c15de --- /dev/null +++ b/app/(app)/products/[id]/sprint/page.tsx @@ -0,0 +1,119 @@ +import { notFound, redirect } from 'next/navigation' +import { cookies } from 'next/headers' +import { getIronSession } from 'iron-session' +import { SessionData, sessionOptions } from '@/lib/session' +import { prisma } from '@/lib/prisma' +import { SplitPane } from '@/components/split-pane/split-pane' +import { SprintBacklogLeft, SprintBacklogRight } from '@/components/sprint/sprint-backlog' +import { SprintHeader } from '@/components/sprint/sprint-header' +import type { SprintStory, PbiWithStories } from '@/components/sprint/sprint-backlog' +import Link from 'next/link' + +interface Props { + params: Promise<{ id: string }> +} + +export default async function SprintBacklogPage({ params }: Props) { + const { id } = await params + const session = await getIronSession(await cookies(), sessionOptions) + + const product = await prisma.product.findFirst({ + where: { id, user_id: session.userId }, + }) + if (!product) notFound() + + const sprint = await prisma.sprint.findFirst({ + where: { product_id: id, status: 'ACTIVE' }, + }) + if (!sprint) redirect(`/products/${id}`) + + // Stories in this sprint + const sprintStories = await prisma.story.findMany({ + where: { sprint_id: sprint.id }, + orderBy: { sort_order: 'asc' }, + include: { tasks: { select: { id: true, status: true } } }, + }) + + const sprintStoryItems: SprintStory[] = sprintStories.map(s => ({ + id: s.id, + title: s.title, + priority: s.priority, + status: s.status, + taskCount: s.tasks.length, + doneCount: s.tasks.filter(t => t.status === 'DONE').length, + })) + + // All PBIs with their non-sprint stories for the right panel + const pbis = await prisma.pbi.findMany({ + where: { product_id: id }, + orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }], + include: { + stories: { + orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }], + }, + }, + }) + + const pbisWithStories: PbiWithStories[] = pbis + .filter(pbi => pbi.stories.length > 0) + .map(pbi => ({ + id: pbi.id, + title: pbi.title, + stories: pbi.stories.map(s => ({ + id: s.id, + title: s.title, + priority: s.priority, + status: s.status, + taskCount: 0, + doneCount: 0, + })), + })) + + const sprintStoryIds = new Set(sprintStories.map(s => s.id)) + const isDemo = session.isDemo ?? false + + return ( +
+ + +
+ {}} + /> + } + right={ + {}} + /> + } + /> +
+ +
+ + Sprint Planning → + + + ← Product Backlog + +
+
+ ) +} diff --git a/app/(app)/products/[id]/sprint/planning/page.tsx b/app/(app)/products/[id]/sprint/planning/page.tsx new file mode 100644 index 0000000..dae6818 --- /dev/null +++ b/app/(app)/products/[id]/sprint/planning/page.tsx @@ -0,0 +1,135 @@ +import { notFound, redirect } from 'next/navigation' +import { cookies } from 'next/headers' +import { getIronSession } from 'iron-session' +import { SessionData, sessionOptions } from '@/lib/session' +import { prisma } from '@/lib/prisma' +import { SplitPane } from '@/components/split-pane/split-pane' +import { PlanningLeft } from '@/components/sprint/planning-left' +import { TaskList } from '@/components/sprint/task-list' +import type { Task } from '@/components/sprint/task-list' +import { SprintHeader } from '@/components/sprint/sprint-header' +import type { SprintStory } from '@/components/sprint/sprint-backlog' +import Link from 'next/link' + +interface Props { + params: Promise<{ id: string }> +} + +export default async function SprintPlanningPage({ params }: Props) { + const { id } = await params + const session = await getIronSession(await cookies(), sessionOptions) + + const product = await prisma.product.findFirst({ + where: { id, user_id: session.userId }, + }) + if (!product) notFound() + + const sprint = await prisma.sprint.findFirst({ + where: { product_id: id, status: 'ACTIVE' }, + }) + if (!sprint) redirect(`/products/${id}`) + + const sprintStories = await prisma.story.findMany({ + where: { sprint_id: sprint.id }, + orderBy: { sort_order: 'asc' }, + include: { + tasks: { + orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }], + }, + }, + }) + + const sprintStoryItems: SprintStory[] = sprintStories.map(s => ({ + id: s.id, + title: s.title, + priority: s.priority, + status: s.status, + taskCount: s.tasks.length, + doneCount: s.tasks.filter(t => t.status === 'DONE').length, + })) + + // Tasks by story + const tasksByStory: Record = {} + for (const story of sprintStories) { + tasksByStory[story.id] = story.tasks.map(t => ({ + id: t.id, + title: t.title, + description: t.description, + priority: t.priority, + status: t.status, + story_id: t.story_id, + sprint_id: t.sprint_id, + })) + } + + const isDemo = session.isDemo ?? false + + return ( +
+ + +
+ + } + right={ + + } + /> +
+ +
+ + ← Sprint Backlog + +
+
+ ) +} + +// Right panel — shows tasks of selected story +function PlanningRight({ + sprintId, + productId, + stories, + tasksByStory, + isDemo, +}: { + sprintId: string + productId: string + stories: SprintStory[] + tasksByStory: Record + isDemo: boolean +}) { + // This is a Server Component wrapper — PlanningLeft manages selection via URL/store + // We render TaskList for the first story if only one, or show instruction + // The actual selection is client-side via PlanningLeft + return ( + + ) +} + +// We need a client component for the right side that reads selection store +import { PlanningRightClient } from '@/components/sprint/planning-right-client' diff --git a/components/sprint/planning-left.tsx b/components/sprint/planning-left.tsx new file mode 100644 index 0000000..73b3917 --- /dev/null +++ b/components/sprint/planning-left.tsx @@ -0,0 +1,57 @@ +'use client' + +import { useSelectionStore } from '@/stores/selection-store' +import { PanelNavBar } from '@/components/shared/panel-nav-bar' +import { Badge } from '@/components/ui/badge' +import { cn } from '@/lib/utils' +import type { SprintStory } from './sprint-backlog' + +const PRIORITY_COLORS: Record = { + 1: 'bg-priority-critical/15 text-priority-critical border-priority-critical/30', + 2: 'bg-priority-high/15 text-priority-high border-priority-high/30', + 3: 'bg-priority-medium/15 text-priority-medium border-priority-medium/30', + 4: 'bg-priority-low/15 text-priority-low border-priority-low/30', +} +const PRIORITY_LABELS: Record = { 1: 'Kritiek', 2: 'Hoog', 3: 'Gemiddeld', 4: 'Laag' } + +interface PlanningLeftProps { + stories: SprintStory[] +} + +export function PlanningLeft({ stories }: PlanningLeftProps) { + const { selectedStoryId, selectStory } = useSelectionStore() + + return ( +
+ +
+ {stories.length === 0 ? ( +

+ Geen stories in de Sprint. +

+ ) : ( + stories.map(story => ( +
selectStory(story.id)} + className={cn( + 'flex items-center gap-3 px-4 py-2.5 border-b border-border cursor-pointer transition-colors hover:bg-surface-container', + selectedStoryId === story.id && 'bg-primary-container text-primary-container-foreground' + )} + > +
+

{story.title}

+
+ + {PRIORITY_LABELS[story.priority]} + + {story.doneCount}/{story.taskCount} klaar +
+
+
+ )) + )} +
+
+ ) +} diff --git a/components/sprint/planning-right-client.tsx b/components/sprint/planning-right-client.tsx new file mode 100644 index 0000000..2c5ad2a --- /dev/null +++ b/components/sprint/planning-right-client.tsx @@ -0,0 +1,39 @@ +'use client' + +import { useSelectionStore } from '@/stores/selection-store' +import { TaskList } from './task-list' +import type { Task } from './task-list' +import type { SprintStory } from './sprint-backlog' + +interface PlanningRightClientProps { + sprintId: string + productId: string + stories: SprintStory[] + tasksByStory: Record + isDemo: boolean +} + +export function PlanningRightClient({ sprintId, productId, stories, tasksByStory, isDemo }: PlanningRightClientProps) { + const { selectedStoryId } = useSelectionStore() + + const story = stories.find(s => s.id === selectedStoryId) + const tasks = selectedStoryId ? (tasksByStory[selectedStoryId] ?? []) : [] + + if (!selectedStoryId || !story) { + return ( +
+

Selecteer een story om de taken te bekijken.

+
+ ) + } + + return ( + + ) +} diff --git a/components/sprint/sprint-backlog.tsx b/components/sprint/sprint-backlog.tsx new file mode 100644 index 0000000..d5e89f7 --- /dev/null +++ b/components/sprint/sprint-backlog.tsx @@ -0,0 +1,246 @@ +'use client' + +import { useState, useTransition, useEffect } from 'react' +import { useRouter } from 'next/navigation' +import { + DndContext, DragEndEvent, DragOverEvent, DragStartEvent, DragOverlay, + PointerSensor, useSensor, useSensors, closestCenter, +} from '@dnd-kit/core' +import { + SortableContext, useSortable, verticalListSortingStrategy, arrayMove, +} from '@dnd-kit/sortable' +import { CSS } from '@dnd-kit/utilities' +import { toast } from 'sonner' +import { Button } from '@/components/ui/button' +import { Badge } from '@/components/ui/badge' +import { PanelNavBar } from '@/components/shared/panel-nav-bar' +import { useSprintStore } from '@/stores/sprint-store' +import { + addStoryToSprintAction, + removeStoryFromSprintAction, + reorderSprintStoriesAction, +} from '@/actions/sprints' +import { cn } from '@/lib/utils' + +const STATUS_COLORS: Record = { + OPEN: 'bg-status-todo/15 text-status-todo border-status-todo/30', + IN_SPRINT: 'bg-status-in-progress/15 text-status-in-progress border-status-in-progress/30', + DONE: 'bg-status-done/15 text-status-done border-status-done/30', +} +const STATUS_LABELS: Record = { OPEN: 'Open', IN_SPRINT: 'In Sprint', DONE: 'Klaar' } + +const PRIORITY_COLORS: Record = { + 1: 'bg-priority-critical/15 text-priority-critical border-priority-critical/30', + 2: 'bg-priority-high/15 text-priority-high border-priority-high/30', + 3: 'bg-priority-medium/15 text-priority-medium border-priority-medium/30', + 4: 'bg-priority-low/15 text-priority-low border-priority-low/30', +} +const PRIORITY_LABELS: Record = { 1: 'Kritiek', 2: 'Hoog', 3: 'Gemiddeld', 4: 'Laag' } + +export interface SprintStory { + id: string + title: string + priority: number + status: string + taskCount: number + doneCount: number +} + +export interface PbiWithStories { + id: string + title: string + stories: SprintStory[] +} + +// --- Left panel: Sprint Backlog --- +function SortableSprintRow({ + story, isDemo, onRemove, onClick, +}: { story: SprintStory; isDemo: boolean; onRemove: () => void; onClick: () => void }) { + const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: story.id }) + const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.4 : 1 } + + return ( +
+ {!isDemo && ( + e.stopPropagation()} + className="text-muted-foreground cursor-grab active:cursor-grabbing shrink-0 select-none text-sm"> + ⠿ + + )} +
+

{story.title}

+
+ + {PRIORITY_LABELS[story.priority]} + + {story.doneCount}/{story.taskCount} klaar +
+
+ {!isDemo && ( + + )} +
+ ) +} + +interface SprintBacklogLeftProps { + sprintId: string + stories: SprintStory[] + isDemo: boolean + onSelectStory: (id: string) => void + selectedStoryId: string | null +} + +export function SprintBacklogLeft({ sprintId, stories, isDemo, onSelectStory, selectedStoryId }: SprintBacklogLeftProps) { + const { sprintStoryOrder, initSprint, reorderSprintStories, rollbackSprint, removeStoryFromSprint } = useSprintStore() + const [, startTransition] = useTransition() + + const idKey = stories.map(s => s.id).join(',') + useEffect(() => { + initSprint(sprintId, idKey ? idKey.split(',') : []) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [sprintId, idKey]) + + const storyMap = Object.fromEntries(stories.map(s => [s.id, s])) + const order = sprintStoryOrder[sprintId] ?? stories.map(s => s.id) + const orderedStories = order.map(id => storyMap[id]).filter(Boolean) + + const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 5 } })) + + function handleDragEnd(event: DragEndEvent) { + const { active, over } = event + if (!over || active.id === over.id) return + const prevOrder = [...order] + const newOrder = arrayMove([...order], order.indexOf(active.id as string), order.indexOf(over.id as string)) + reorderSprintStories(sprintId, newOrder) + startTransition(async () => { + const result = await reorderSprintStoriesAction(sprintId, newOrder) + if (!result.success) { rollbackSprint(sprintId, prevOrder); toast.error('Volgorde opslaan mislukt') } + }) + } + + function handleRemove(storyId: string) { + removeStoryFromSprint(sprintId, storyId) + startTransition(async () => { + const result = await removeStoryFromSprintAction(storyId) + if (!result.success) toast.error('Verwijderen mislukt') + }) + } + + return ( +
+ +
+ {orderedStories.length === 0 ? ( +

+ Geen stories in de Sprint. Sleep stories vanuit het rechterpaneel. +

+ ) : ( + + s.id)} strategy={verticalListSortingStrategy}> + {orderedStories.map(story => ( + handleRemove(story.id)} + onClick={() => onSelectStory(story.id)} + /> + ))} + + + )} +
+
+ ) +} + +// --- Right panel: Product Backlog stories grouped by PBI (droppable source) --- +interface SprintBacklogRightProps { + sprintId: string + pbisWithStories: PbiWithStories[] + sprintStoryIds: Set + isDemo: boolean + onStoryAdded: (storyId: string) => void +} + +export function SprintBacklogRight({ sprintId, pbisWithStories, sprintStoryIds, isDemo, onStoryAdded }: SprintBacklogRightProps) { + const [collapsed, setCollapsed] = useState>(new Set()) + const [, startTransition] = useTransition() + const { addStoryToSprint } = useSprintStore() + const router = useRouter() + + function toggle(pbiId: string) { + setCollapsed(prev => { + const next = new Set(prev) + next.has(pbiId) ? next.delete(pbiId) : next.add(pbiId) + return next + }) + } + + function handleAdd(storyId: string) { + addStoryToSprint(sprintId, storyId) + onStoryAdded(storyId) + startTransition(async () => { + const result = await addStoryToSprintAction(sprintId, storyId) + if (!result.success) { + toast.error(result.error ?? 'Toevoegen mislukt') + router.refresh() + } + }) + } + + return ( +
+ +
+ {pbisWithStories.map(pbi => ( +
+ + + {!collapsed.has(pbi.id) && pbi.stories.map(story => { + const inSprint = sprintStoryIds.has(story.id) + return ( +
+
+

{story.title}

+ + {STATUS_LABELS[story.status]} + +
+ {!inSprint && !isDemo && ( + + )} + {inSprint && In Sprint} +
+ ) + })} +
+ ))} +
+
+ ) +} diff --git a/components/sprint/sprint-header.tsx b/components/sprint/sprint-header.tsx new file mode 100644 index 0000000..14382cf --- /dev/null +++ b/components/sprint/sprint-header.tsx @@ -0,0 +1,144 @@ +'use client' + +import { useState, useTransition, useActionState } from 'react' +import { useFormStatus } from 'react-dom' +import { Button } from '@/components/ui/button' +import { Textarea } from '@/components/ui/textarea' +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog' +import { updateSprintGoalAction, completeSprintAction } from '@/actions/sprints' +import type { SprintStory } from './sprint-backlog' + +interface Sprint { + id: string + sprint_goal: string + status: string +} + +interface SprintHeaderProps { + productId: string + productName: string + sprint: Sprint + isDemo: boolean + sprintStories: SprintStory[] +} + +function SaveGoalButton() { + const { pending } = useFormStatus() + return +} + +export function SprintHeader({ productId, productName, sprint, isDemo, sprintStories }: SprintHeaderProps) { + const [editingGoal, setEditingGoal] = useState(false) + const [completeOpen, setCompleteOpen] = useState(false) + const [decisions, setDecisions] = useState>({}) + const [isCompleting, startCompleting] = useTransition() + + const [, goalFormAction] = useActionState( + async (_prev: unknown, fd: FormData) => { + const result = await updateSprintGoalAction(_prev, fd) + if (result?.success) setEditingGoal(false) + return result + }, + undefined + ) + + function setDecision(storyId: string, value: 'DONE' | 'OPEN') { + setDecisions(prev => ({ ...prev, [storyId]: value })) + } + + function handleComplete() { + // Default: stories without explicit decision → OPEN + const finalDecisions: Record = {} + sprintStories.forEach(s => { + finalDecisions[s.id] = decisions[s.id] ?? 'OPEN' + }) + + startCompleting(async () => { + await completeSprintAction(sprint.id, finalDecisions) + setCompleteOpen(false) + }) + } + + return ( +
+
+
+
+ {productName} + + Sprint actief +
+ + {editingGoal ? ( +
+ +