'use client' import { useTransition } from 'react' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table' import { cancelJobAction, deleteJobAction } from '@/actions/admin/jobs' type Job = { id: string kind: string status: string created_at: Date user: { username: string } product: { name: string } branch: string | null pr_url: string | null error: string | null } const STATUS_CLASS: Record = { QUEUED: 'bg-secondary text-secondary-foreground', CLAIMED: 'bg-status-in-progress text-white border-transparent', RUNNING: 'bg-warning text-warning-foreground border-transparent', DONE: 'bg-status-done text-white border-transparent', FAILED: 'bg-priority-high text-white border-transparent', CANCELLED: 'bg-muted text-muted-foreground', SKIPPED: 'bg-muted/60 text-muted-foreground italic border-transparent', } const KIND_LABEL: Record = { TASK_IMPLEMENTATION: 'Taak', IDEA_GRILL: 'Idee Grill', IDEA_MAKE_PLAN: 'Idee Plan', } const ACTIVE_STATUSES = new Set(['QUEUED', 'CLAIMED', 'RUNNING']) function JobRow({ job }: { job: Job }) { const [pending, startTransition] = useTransition() function handleCancel() { startTransition(() => cancelJobAction(job.id)) } function handleDelete() { startTransition(() => deleteJobAction(job.id)) } return ( {job.id.slice(0, 8)} {job.user.username} {job.product.name} {KIND_LABEL[job.kind] ?? job.kind} {job.status} {job.branch ?? '—'} {new Date(job.created_at).toLocaleString('nl-NL', { dateStyle: 'short', timeStyle: 'short' })} {job.error && ( {job.error} )}
{ACTIVE_STATUSES.has(job.status) && ( )}
) } export function JobsTable({ jobs }: { jobs: Job[] }) { return ( ID Gebruiker Product Type Status Branch Aangemaakt Fout Acties {jobs.length === 0 && ( Geen jobs gevonden )} {jobs.map(job => ( ))}
) }