Scrum4Me/app/(app)/todos/page.tsx
Madhura68 e991f4f185 feat(todos): include team-member products in todos page query
Use productAccessFilter so users who are product members (not just
owners) see those products in the todo form and promote dialogs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 19:17:05 +02:00

46 lines
1.5 KiB
TypeScript

import { cookies } from 'next/headers'
import { getIronSession } from 'iron-session'
import { SessionData, sessionOptions } from '@/lib/session'
import { prisma } from '@/lib/prisma'
import { productAccessFilter } from '@/lib/product-access'
import { TodoList } from '@/components/todos/todo-list'
export default async function TodosPage() {
const session = await getIronSession<SessionData>(await cookies(), sessionOptions)
const todos = await prisma.todo.findMany({
where: { user_id: session.userId, archived: false },
orderBy: { created_at: 'asc' },
include: { product: { select: { name: true } } },
})
const products = await prisma.product.findMany({
where: { ...productAccessFilter(session.userId), archived: false },
orderBy: { name: 'asc' },
include: {
pbis: { orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }], select: { id: true, title: true } },
},
})
return (
<div className="p-6 max-w-2xl mx-auto w-full">
<h1 className="text-xl font-medium text-foreground mb-6">Todo&apos;s</h1>
<TodoList
todos={todos.map(t => ({
id: t.id,
title: t.title,
done: t.done,
created_at: t.created_at.toISOString(),
product_id: t.product_id ?? null,
product_name: t.product?.name ?? null,
}))}
products={products.map(p => ({
id: p.id,
name: p.name,
pbis: p.pbis,
}))}
isDemo={session.isDemo ?? false}
/>
</div>
)
}