"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 { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Input } from "@/components/ui/input"; import { InputGroup, InputGroupText } from "@/components/ui/input-group"; import { Link } from "@/components/navigation"; import { listTask } from "@/service/ppid-categories-services"; import { title } from "process"; import search from "../../app/chat/components/search"; import { format } from "date-fns"; export type CompanyData = { no: number; title: string; uniqueCode: string; assignmentMainType: string; assignmentType: string; createdAt: string; isDone: string; }; export const columns: ColumnDef[] = [ { accessorKey: "no", header: "No", cell: ({ row }) => (

{row.getValue("no")}

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

{row.getValue("title")}

), }, { accessorKey: "uniqueCode", header: "Kode ", cell: ({ row }) => ( {row.getValue("uniqueCode")} ), }, { accessorKey: "assignmentMainType", header: "Tipe Tugas ", cell: ({ row }) => ( {row.getValue("assignmentMainType")} ), }, { accessorKey: "assignmentType", header: "Jenis Tugas ", cell: ({ row }) => ( {row.getValue("assignmentType")} ), }, { accessorKey: "createdAt", header: "Tanggal Unggah", cell: ({ row }) => { const createdAt = row.getValue("createdAt") as | string | number | undefined; const formattedDate = createdAt && !isNaN(new Date(createdAt).getTime()) ? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss") : "-"; return {formattedDate}; }, }, { accessorKey: "isDone", header: "Status", cell: ({ row }) => { const isDone = row.getValue("isDone"); return (
); }, }, { id: "actions", accessorKey: "action", header: "Actions", enableHiding: false, cell: ({ row }) => { return ( View Delete ); }, }, ]; const TaskTable = () => { const [sorting, setSorting] = React.useState([]); const [taskTable, setTaskTable] = 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 [search, setSearch] = React.useState(title); const table = useReactTable({ data: taskTable, columns, onSortingChange: setSorting, onColumnFiltersChange: setColumnFilters, onPaginationChange: setPagination, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), state: { sorting, columnFilters, pagination, }, }); React.useEffect(() => { initState(); }, [page, limit]); async function initState() { try { const res = await listTask(limit, page); const data = res.data.data.content.map((item: any, index: number) => ({ no: (page - 1) * limit + index + 1, title: item.title, uniqueCode: item.uniqueCode || "-", assignmentMainType: item.assignmentMainType?.name || "-", assignmentType: item.assignmentType?.name || "-", createdAt: item.createdAt, isDone: item.isDone, })); setTaskTable(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 TaskTable;