diff --git a/actions/todos.ts b/actions/todos.ts index c4252f5..ecfde5f 100644 --- a/actions/todos.ts +++ b/actions/todos.ts @@ -18,10 +18,12 @@ export async function createTodoAction(_prevState: unknown, formData: FormData) if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' } const title = (formData.get('title') as string)?.trim() + const description = (formData.get('description') as string)?.trim() || null const raw = (formData.get('productId') as string)?.trim() const productId = (raw && raw !== 'all') ? raw : null if (!title) return { error: 'Titel is verplicht' } + if (description && description.length > 2000) return { error: 'Beschrijving is langer dan 2000 tekens' } if (productId) { const product = await prisma.product.findFirst({ @@ -30,7 +32,9 @@ export async function createTodoAction(_prevState: unknown, formData: FormData) if (!product) return { error: 'Product niet gevonden' } } - await prisma.todo.create({ data: { user_id: session.userId, product_id: productId, title } }) + await prisma.todo.create({ + data: { user_id: session.userId, product_id: productId, title, description }, + }) revalidatePath('/todos') return { success: true } } @@ -66,12 +70,14 @@ export async function updateTodoAction(_prevState: unknown, formData: FormData) const id = (formData.get('id') as string)?.trim() const title = (formData.get('title') as string)?.trim() + const description = (formData.get('description') as string)?.trim() || null const raw = (formData.get('productId') as string)?.trim() const productId = raw || null const done = formData.get('done') === 'on' if (!id) return { error: 'Ongeldige todo' } if (!title) return { error: 'Titel is verplicht' } + if (description && description.length > 2000) return { error: 'Beschrijving is langer dan 2000 tekens' } const todo = await prisma.todo.findFirst({ where: { id, user_id: session.userId }, @@ -87,7 +93,7 @@ export async function updateTodoAction(_prevState: unknown, formData: FormData) await prisma.todo.update({ where: { id }, - data: { title, product_id: productId, done }, + data: { title, description, product_id: productId, done }, }) revalidatePath('/todos') return { success: true }