Scrum4Me/components/dashboard/product-list.tsx
janpeter visser d11b114fc1 feat: ST-601-ST-612 M6 polish, beveiliging en launch-ready
- ST-601/602: loading skeletons en error boundary
- ST-603: Sonner toasts op alle CRUD-operaties
- ST-604: DemoTooltip op uitgeschakelde knoppen
- ST-605: KeyboardSensor dnd-kit, Escape sluit modals
- ST-606: min-width banner < 1024px
- ST-607: WCAG AA aria-labels en skip link
- ST-608: rate limiting login (10/min) en registratie (5/uur)
- ST-609: security integratietests cross-user toegang (7 tests)
- ST-610: GitHub Actions CI/CD workflow
- ST-611: README met quickstart, deployment en API-docs
- ST-612: Lars-flow acceptatiechecklist
- fix: settings toont gebruikersnaam i.p.v. interne id
- fix: seed idempotent, testdata altijd gekoppeld aan demo-gebruiker

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 12:36:23 +02:00

99 lines
3.2 KiB
TypeScript

'use client'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
import { useTransition } from 'react'
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
import { restoreProductAction } from '@/actions/products'
interface Product {
id: string
name: string
description: string | null
repo_url: string | null
}
interface ProductListProps {
products: Product[]
isDemo: boolean
showArchived?: boolean
}
export function ProductList({ products, isDemo, showArchived = false }: ProductListProps) {
const router = useRouter()
const [, startTransition] = useTransition()
function handleRestore(id: string) {
startTransition(async () => {
const result = await restoreProductAction(id)
if ('error' in result) toast.error(result.error ?? 'Herstellen mislukt')
else { toast.success('Product hersteld'); router.refresh() }
})
}
if (products.length === 0) {
return (
<div className="bg-surface-container-low rounded-xl border border-border p-12 text-center space-y-3">
<p className="text-muted-foreground">
{showArchived
? 'Geen gearchiveerde producten.'
: 'Je hebt nog geen producten aangemaakt.'}
</p>
{!isDemo && !showArchived && (
<Button variant="outline" nativeButton={false} render={<Link href="/products/new" />}>
Maak je eerste product aan
</Button>
)}
</div>
)
}
return (
<div className="grid gap-3">
{products.map(product => (
<div
key={product.id}
onClick={() => !showArchived && router.push(`/products/${product.id}`)}
className={`group bg-surface-container-low border border-border rounded-xl p-4 transition-colors ${
showArchived ? 'opacity-60' : 'cursor-pointer hover:border-primary'
}`}
>
<div className="flex items-start justify-between gap-4">
<div className="min-w-0">
<p className="font-medium text-foreground group-hover:text-primary transition-colors truncate">
{product.name}
</p>
{product.description && (
<p className="text-sm text-muted-foreground mt-1 line-clamp-1">
{product.description.slice(0, 80)}{product.description.length > 80 ? '…' : ''}
</p>
)}
</div>
<div className="flex items-center gap-3 shrink-0">
{product.repo_url && (
<a
href={product.repo_url}
target="_blank"
rel="noopener noreferrer"
onClick={e => e.stopPropagation()}
className="text-xs text-muted-foreground hover:text-primary underline"
>
Repo
</a>
)}
{showArchived && !isDemo && (
<button
onClick={(e) => { e.stopPropagation(); handleRestore(product.id) }}
className="text-xs text-primary hover:underline"
>
Herstellen
</button>
)}
</div>
</div>
</div>
))}
</div>
)
}