'use client' import type { WebhookDeliveryEntry } from '@admin/actions/webhooks' import type { ColumnDef } from '@tanstack/react-table' import { SortIndicator } from '@admin/components/shared/sort-indicator' import { Badge } from '@admin/components/ui/badge' import { Button } from '@admin/components/ui/button' import { formatDistanceToNow } from 'date-fns' export const logsColumns: ColumnDef[] = [ { accessorKey: 'statusCode', meta: { label: 'Status' }, size: 110, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => ( {row.original.statusCode ?? 'error'} ) }, { accessorKey: 'event', meta: { label: 'Event' }, size: 260, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => {row.original.event} }, { accessorKey: 'webhookName', meta: { label: 'Endpoint' }, size: 220, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => {row.original.webhookName} }, { accessorKey: 'attempt', meta: { label: 'Attempt' }, size: 100, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => {row.original.attempt} }, { accessorKey: 'durationMs', meta: { label: 'Duration' }, size: 110, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => ( {row.original.durationMs} ms ) }, { accessorKey: 'createdAt', meta: { label: 'When', mobile: 'labelled' }, size: 160, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => ( {formatDistanceToNow(new Date(row.original.createdAt), { addSuffix: true })} ) } ]