'use client' import * as React from 'react' import { EntityFiltersBar } from '@admin/components/shared/entity-filters-bar' import { PageHeader } from '@admin/components/shared/page-header' import { useWebhookOptions } from '@admin/hooks/use-webhooks' import { useIsFetching } from '@tanstack/react-query' import { parseAsInteger, parseAsString, useQueryState, useQueryStates } from 'nuqs' import { logsColumns } from './webhooks-logs-columns' import { WebhooksLogsTable } from './webhooks-logs-table' const filterParsers = { status: parseAsString.withDefault(''), endpoint: parseAsString.withDefault(''), createdAtFrom: parseAsString.withDefault(''), createdAtTo: parseAsString.withDefault('') } as const export function WebhooksLogsPageContent() { const isSearchFetching = useIsFetching({ queryKey: ['webhook-deliveries'] }) > 0 const [search, setSearch] = useQueryState('q', parseAsString.withDefault('')) const [, setPageIndex] = useQueryState('page', parseAsInteger.withDefault(0)) const [filterValues, setFilters] = useQueryStates(filterParsers) const status = filterValues.status const endpoint = filterValues.endpoint const createdAtFrom = filterValues.createdAtFrom const createdAtTo = filterValues.createdAtTo const { data: endpointOptions } = useWebhookOptions() const activeFilterCount = [search, status, endpoint, createdAtFrom || createdAtTo].filter( Boolean ).length function handleSearch(value: string | null) { React.startTransition(() => { void setPageIndex(0) void setSearch(value) }) } function handleClearAll() { React.startTransition(() => { void setPageIndex(0) void setSearch(null) void setFilters({ status: null, endpoint: null, createdAtFrom: null, createdAtTo: null }) }) } const filters = [ { key: 'status', label: 'Status', type: 'select' as const, value: status, options: [ { label: 'Delivered', value: 'success' }, { label: 'Failed', value: 'failed' } ] }, { key: 'endpoint', label: 'Webhooks', type: 'select' as const, value: endpoint, options: (endpointOptions?.webhooks ?? []).map((webhook) => ({ label: webhook.name, value: webhook.id })) }, { key: 'createdAt', label: 'Created', type: 'date-range' as const, from: createdAtFrom, to: createdAtTo } ] return ( { React.startTransition(() => { void setPageIndex(0) void setFilters(updates) }) }} onClearAll={handleClearAll} search={search} searchPlaceholder="Search deliveries..." isPending={isSearchFetching} onSearch={handleSearch} />
) }