'use client' import type { WebhookEndpointListItem } 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' import { WebhookActions } from './webhook-actions' import { WebhookEnabledSwitch } from './webhook-enabled-switch' interface WebhooksColumnsOptions { onEdit: (webhook: WebhookEndpointListItem) => void onDelete: (webhook: WebhookEndpointListItem) => void } export function createWebhooksColumns({ onEdit, onDelete }: WebhooksColumnsOptions): ColumnDef[] { return [ { accessorKey: 'name', size: 240, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => {row.original.name}, enableHiding: false }, { accessorKey: 'url', size: 320, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => ( {row.original.url} ) }, { accessorKey: 'enabled', size: 110, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => }, { accessorKey: 'eventCount', 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.eventCount} }, { accessorKey: 'lastDeliveryAt', 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.lastDeliveryAt ? ( {row.original.lastDeliverySuccess ? 'Delivered' : 'Failed'} {formatDistanceToNow(new Date(row.original.lastDeliveryAt), { addSuffix: true })} ) : ( ) }, { accessorKey: 'createdAt', size: 120, header: ({ column }) => { const sortDirection = column.getIsSorted() const sortLabel = sortDirection === 'asc' ? 'sorted ascending' : sortDirection === 'desc' ? 'sorted descending' : 'not sorted' return ( ) }, cell: ({ row }) => (
{new Date(row.original.createdAt).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}
) }, { id: 'actions', size: 64, enableResizing: false, meta: { width: '64px' }, header: () => Actions, cell: ({ row }) => (
) } ] }