'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 { Badge } from '@/components/ui/badge' import { CodeBadge } from '@/components/shared/code-badge' import { DemoTooltip } from '@/components/shared/demo-tooltip' import { restoreProductAction } from '@/actions/products' import { setActiveProductAction } from '@/actions/active-product' interface Product { id: string name: string code: string | null description: string | null repo_url: string | null } interface ProductListProps { products: Product[] isDemo: boolean showArchived?: boolean activeProductId: string | null } export function ProductList({ products, isDemo, showArchived = false, activeProductId }: 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() } }) } function handleActivate(id: string) { startTransition(async () => { const result = await setActiveProductAction(id) if (result?.error) toast.error(typeof result.error === 'string' ? result.error : 'Activeren mislukt') else router.push(`/products/${id}`) }) } if (products.length === 0) { return (
{showArchived ? 'Geen gearchiveerde producten.' : 'Je hebt nog geen producten aangemaakt.'}
{product.name}
{product.description.slice(0, 80)}{product.description.length > 80 ? '…' : ''}
)}