"use client"; import * as React from "react"; import { ColumnDef, ColumnFiltersState, PaginationState, SortingState, VisibilityState, flexRender, getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge, ChevronLeft, ChevronRight, Eye, MoreVertical, Search, SquarePen, Trash2, TrendingDown, TrendingUp, } from "lucide-react"; import { cn } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; export type CompanyData = { no: number; title: string; startDate: string; endDate: string; startTime: string; address: string; speakerName: string; uploaderName: string; status: string; }; import { data } from "./data"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; import { paginationBlog } from "@/service/blog/blog"; import { paginationSchedule } from "@/service/schedule/schedule"; export const columns: ColumnDef[] = [ { accessorKey: "no", header: "No", cell: ({ row }) => (

{row.getValue("no")}

), }, { accessorKey: "title", header: "Judul", cell: ({ row }) => (

{row.getValue("title")}

), }, { accessorKey: "startDate", header: "Tanggal Mulai ", cell: ({ row }) => ( {row.getValue("startDate")} ), }, { accessorKey: "endDate", header: "Tanggal Selesai", cell: ({ row }) => ( {row.getValue("endDate")} ), }, { accessorKey: "startTime", header: "Waktu", cell: ({ row }) => ( {row.getValue("startTime")} ), }, { accessorKey: "address", header: "Lokasi", cell: ({ row }) => ( {row.getValue("address")} ), }, { accessorKey: "status", header: "Status", cell: ({ row }) => { return ( {row.getValue("status")} ); }, }, { accessorKey: "speakerName", header: "Disampaikan oleh", cell: ({ row }) => ( {row.getValue("speakerName")} ), }, { accessorKey: "uploaderName", header: "Sumber ", cell: ({ row }) => ( {row.getValue("uploaderName")} ), }, { id: "actions", accessorKey: "action", header: "Actions", enableHiding: false, cell: ({ row }) => { return ( View Edit Delete ); }, }, ]; const PressConTable = () => { const [pressconTable, setPressConTable] = React.useState([]); const [sorting, setSorting] = React.useState([]); const [columnFilters, setColumnFilters] = React.useState( [] ); const [columnVisibility, setColumnVisibility] = React.useState({}); const [rowSelection, setRowSelection] = React.useState({}); const [pagination, setPagination] = React.useState({ pageIndex: 0, pageSize: 10, }); const [page, setPage] = React.useState(1); const [totalPage, setTotalPage] = React.useState(1); const [limit, setLimit] = React.useState(10); const table = useReactTable({ data: pressconTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), onColumnVisibilityChange: setColumnVisibility, onRowSelectionChange: setRowSelection, onPaginationChange: setPagination, state: { sorting, columnFilters, columnVisibility, rowSelection, pagination, }, }); React.useEffect(() => { initState(); }, [page, limit]); async function initState() { try { const res = await paginationSchedule(limit, page, 1); const data = res.data.data.content.map((item: any, index: number) => ({ no: (page - 1) * limit + index + 1, title: item.title, startDate: item.startDate, endDate: item.endDate, startTime: item.startTime, address: item.address, uploaderName: item.uploaderName, speakerName: item.speakerName, })); setPressConTable(data); setTotalPage(res.data.totalPages); } catch (error) { console.error("Error fetching tasks:", error); } } return (
) => table.getColumn("status")?.setFilterValue(event.target.value) } className="max-w-sm " />
{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) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No results. )}
{table.getPageOptions().map((page, pageIndex) => ( ))}
); }; export default PressConTable;