'use client' import type * as React from 'react' import type { FormSettingsRow } from './forms-settings-columns' import type { ColumnDef } from '@tanstack/react-table' import { DataGrid, DataGridBody, DataGridCell, DataGridHead, DataGridHeader, DataGridRow } from '@admin/components/shared/data-table/data-grid' import { cn } from '@admin/utils/shared/cn' import { flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table' interface FormsSettingsTableProps extends React.HTMLAttributes { columns: ColumnDef[] rows: FormSettingsRow[] onRowClick: (row: FormSettingsRow) => void } export function FormsSettingsTable({ columns, rows, onRowClick, className }: FormsSettingsTableProps) { const table = useReactTable({ data: rows, columns, getCoreRowModel: getCoreRowModel() }) return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())} ))} ))} {table.getRowModel().rows.length ? ( table.getRowModel().rows.map((row) => ( { const target = event.target as HTMLElement if (!event.currentTarget.contains(target)) return if (target.closest('button, a, input, [role="checkbox"]')) return onRowClick(row.original) }} > {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No forms yet. Create a form schema to configure its notifications here. )}
) }