import { swrFetcher } from "@/api/api" import { deleteNotificationGroups } from "@/api/notification-group" import { ActionButtonGroup } from "@/components/action-button-group" import { GroupTab } from "@/components/group-tab" import { HeaderButtonGroup } from "@/components/header-button-group" import { NotificationGroupCard } from "@/components/notification-group" import { Checkbox } from "@/components/ui/checkbox" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { ModelNotificationGroupResponseItem } from "@/types" import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table" import { useEffect, useMemo } from "react" import { useTranslation } from "react-i18next" import { toast } from "sonner" import useSWR from "swr" export default function NotificationGroupPage() { const { t } = useTranslation() const { data, mutate, error, isLoading } = useSWR( "/api/v1/notification-group", swrFetcher, ) useEffect(() => { if (error) toast(t("Error"), { description: t("Results.ErrorFetchingResource", { error: error.message, }), }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [error]) const columns: ColumnDef[] = [ { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label="Select all" /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label="Select row" /> ), enableSorting: false, enableHiding: false, }, { header: "ID", accessorKey: "id", accessorFn: (row) => row.group.id, }, { header: t("Name"), accessorKey: "name", accessorFn: (row) => row.group.name, cell: ({ row }) => { const s = row.original return
{s.group.name}
}, }, { header: t("Notifier") + "(ID)", accessorKey: "notifications", accessorFn: (row) => row.notifications, }, { id: "actions", header: t("Actions"), cell: ({ row }) => { const s = row.original return ( ) }, }, ] const dataCache = useMemo(() => { return data ?? [] }, [data]) const table = useReactTable({ data: dataCache, columns, getCoreRowModel: getCoreRowModel(), }) const selectedRows = table.getSelectedRowModel().rows return (
r.original.group.id), mutate: mutate, }} >
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ) })} ))} {isLoading ? ( {t("Loading")}... ) : table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( {t("NoResults")} )}
) }