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 <noreply@anthropic.com>
This commit is contained in:
Janpeter Visser 2026-04-24 11:51:27 +02:00
parent 4dd62c199c
commit d92e548f88
12 changed files with 1480 additions and 6 deletions

141
actions/tasks.ts Normal file
View file

@ -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<SessionData>(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 }
}