feat: ST-101-ST-110 M1 producten, PBI backlog, iconen en PWA manifest
- Product aanmaken/bewerken/archiveren/herstellen (ST-101, ST-103) - SplitPane component met versleepbare splitter en localStorage (ST-104) - PanelNavBar herbruikbaar paneelheader component (ST-105) - PbiList met prioriteitsgroepen, inline aanmaken, filter en verwijderen (ST-106-ST-110) - StoryPanel placeholder rechter paneel met selectie via Zustand (ST-109) - App iconen geinstalleerd: favicon, apple-icon, PWA manifest (192/512px) - AppIcon SVG component in navigatiebar - Root layout metadata bijgewerkt naar Nederlands Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8017968e60
commit
ffda65490f
23 changed files with 1229 additions and 26 deletions
112
actions/pbis.ts
Normal file
112
actions/pbis.ts
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
'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)
|
||||
}
|
||||
|
||||
async function verifyProductOwnership(productId: string, userId: string) {
|
||||
return prisma.product.findFirst({ where: { id: productId, user_id: userId } })
|
||||
}
|
||||
|
||||
const createPbiSchema = z.object({
|
||||
productId: z.string(),
|
||||
title: z.string().min(1, 'Titel is verplicht').max(200),
|
||||
priority: z.coerce.number().int().min(1).max(4),
|
||||
})
|
||||
|
||||
const updatePbiSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string().min(1, 'Titel is verplicht').max(200),
|
||||
description: z.string().max(2000).optional(),
|
||||
priority: z.coerce.number().int().min(1).max(4),
|
||||
})
|
||||
|
||||
export async function createPbiAction(_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 = createPbiSchema.safeParse({
|
||||
productId: formData.get('productId'),
|
||||
title: formData.get('title'),
|
||||
priority: formData.get('priority'),
|
||||
})
|
||||
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 last = await prisma.pbi.findFirst({
|
||||
where: { product_id: parsed.data.productId, priority: parsed.data.priority },
|
||||
orderBy: { sort_order: 'desc' },
|
||||
})
|
||||
const sort_order = (last?.sort_order ?? 0) + 1.0
|
||||
|
||||
const pbi = await prisma.pbi.create({
|
||||
data: {
|
||||
product_id: parsed.data.productId,
|
||||
title: parsed.data.title,
|
||||
priority: parsed.data.priority,
|
||||
sort_order,
|
||||
},
|
||||
})
|
||||
|
||||
revalidatePath(`/products/${parsed.data.productId}`)
|
||||
return { success: true, pbi }
|
||||
}
|
||||
|
||||
export async function updatePbiAction(_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 = updatePbiSchema.safeParse({
|
||||
id: formData.get('id'),
|
||||
title: formData.get('title'),
|
||||
description: formData.get('description') || undefined,
|
||||
priority: formData.get('priority'),
|
||||
})
|
||||
if (!parsed.success) return { error: parsed.error.flatten().fieldErrors }
|
||||
|
||||
const pbi = await prisma.pbi.findFirst({
|
||||
where: { id: parsed.data.id },
|
||||
include: { product: true },
|
||||
})
|
||||
if (!pbi || pbi.product.user_id !== session.userId) return { error: 'PBI niet gevonden' }
|
||||
|
||||
await prisma.pbi.update({
|
||||
where: { id: parsed.data.id },
|
||||
data: {
|
||||
title: parsed.data.title,
|
||||
description: parsed.data.description ?? null,
|
||||
priority: parsed.data.priority,
|
||||
},
|
||||
})
|
||||
|
||||
revalidatePath(`/products/${pbi.product_id}`)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function deletePbiAction(id: string) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
|
||||
const pbi = await prisma.pbi.findFirst({
|
||||
where: { id },
|
||||
include: { product: true },
|
||||
})
|
||||
if (!pbi || pbi.product.user_id !== session.userId) return { error: 'PBI niet gevonden' }
|
||||
|
||||
await prisma.pbi.delete({ where: { id } })
|
||||
|
||||
revalidatePath(`/products/${pbi.product_id}`)
|
||||
return { success: true }
|
||||
}
|
||||
139
actions/products.ts
Normal file
139
actions/products.ts
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
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'
|
||||
|
||||
const productSchema = z.object({
|
||||
name: z.string().min(1, 'Naam is verplicht').max(100, 'Naam mag maximaal 100 tekens bevatten'),
|
||||
description: z.string().max(1000, 'Beschrijving mag maximaal 1000 tekens bevatten').optional(),
|
||||
repo_url: z
|
||||
.string()
|
||||
.url('Voer een geldige URL in (inclusief https://)')
|
||||
.optional()
|
||||
.or(z.literal('')),
|
||||
definition_of_done: z
|
||||
.string()
|
||||
.min(1, 'Definition of Done is verplicht')
|
||||
.max(500, 'Definition of Done mag maximaal 500 tekens bevatten'),
|
||||
})
|
||||
|
||||
async function getSession() {
|
||||
return getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
}
|
||||
|
||||
export async function createProductAction(_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 = productSchema.safeParse({
|
||||
name: formData.get('name'),
|
||||
description: formData.get('description') || undefined,
|
||||
repo_url: formData.get('repo_url') || undefined,
|
||||
definition_of_done: formData.get('definition_of_done'),
|
||||
})
|
||||
|
||||
if (!parsed.success) {
|
||||
return { error: parsed.error.flatten().fieldErrors }
|
||||
}
|
||||
|
||||
const existing = await prisma.product.findFirst({
|
||||
where: { user_id: session.userId, name: parsed.data.name },
|
||||
})
|
||||
if (existing) return { error: { name: ['Een product met deze naam bestaat al'] } }
|
||||
|
||||
const product = await prisma.product.create({
|
||||
data: {
|
||||
user_id: session.userId,
|
||||
name: parsed.data.name,
|
||||
description: parsed.data.description ?? null,
|
||||
repo_url: parsed.data.repo_url || null,
|
||||
definition_of_done: parsed.data.definition_of_done,
|
||||
},
|
||||
})
|
||||
|
||||
redirect(`/products/${product.id}`)
|
||||
}
|
||||
|
||||
export async function updateProductAction(_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
|
||||
if (!id) return { error: 'Product niet gevonden' }
|
||||
|
||||
const parsed = productSchema.safeParse({
|
||||
name: formData.get('name'),
|
||||
description: formData.get('description') || undefined,
|
||||
repo_url: formData.get('repo_url') || undefined,
|
||||
definition_of_done: formData.get('definition_of_done'),
|
||||
})
|
||||
|
||||
if (!parsed.success) {
|
||||
return { error: parsed.error.flatten().fieldErrors }
|
||||
}
|
||||
|
||||
// Verify ownership
|
||||
const product = await prisma.product.findFirst({
|
||||
where: { id, user_id: session.userId },
|
||||
})
|
||||
if (!product) return { error: 'Product niet gevonden' }
|
||||
|
||||
// Check unique name (excluding self)
|
||||
const duplicate = await prisma.product.findFirst({
|
||||
where: { user_id: session.userId, name: parsed.data.name, NOT: { id } },
|
||||
})
|
||||
if (duplicate) return { error: { name: ['Een product met deze naam bestaat al'] } }
|
||||
|
||||
await prisma.product.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: parsed.data.name,
|
||||
description: parsed.data.description ?? null,
|
||||
repo_url: parsed.data.repo_url || null,
|
||||
definition_of_done: parsed.data.definition_of_done,
|
||||
},
|
||||
})
|
||||
|
||||
revalidatePath(`/products/${id}`)
|
||||
revalidatePath('/dashboard')
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function archiveProductAction(id: string) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
|
||||
const product = await prisma.product.findFirst({
|
||||
where: { id, user_id: session.userId },
|
||||
})
|
||||
if (!product) return { error: 'Product niet gevonden' }
|
||||
|
||||
await prisma.product.update({ where: { id }, data: { archived: true } })
|
||||
|
||||
revalidatePath('/dashboard')
|
||||
redirect('/dashboard')
|
||||
}
|
||||
|
||||
export async function restoreProductAction(id: string) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
|
||||
const product = await prisma.product.findFirst({
|
||||
where: { id, user_id: session.userId },
|
||||
})
|
||||
if (!product) return { error: 'Product niet gevonden' }
|
||||
|
||||
await prisma.product.update({ where: { id }, data: { archived: false } })
|
||||
|
||||
revalidatePath('/dashboard')
|
||||
return { success: true }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue