"use client" import { ColumnDef, flexRender, getCoreRowModel, getPaginationRowModel, getSortedRowModel, SortingState, useReactTable } from '@tanstack/react-table'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../ui/table" import { Button } from '../ui/button'; import { Badge } from '../ui/badge' import { ArrowUpDown, Clock, Download, Trash } from 'lucide-react'; import { useState } from 'react'; import Link from 'next/link'; // This type is used to define the shape of our data. // You can use a Zod schema here if you want. export type IFile = { uuid: string; fileName: string; checksum: string; extension: string; groupId: string | null; fileSize: number; fileType: string; isRestricted: boolean; isDocumentation: boolean; uploadedAt: string; uploadedBy: string; } function ContextButtonForFile() { return (
) } export const filesTableColumns: ColumnDef[] = [ { accessorKey: "fileName", header: ({ column }) => { return (
Nom du fichier
) }, }, { accessorKey: "uploadedBy", header: ({ column }) => { return (
Autheur(s)
) }, }, { accessorKey: "uploadedAt", header: ({ column }) => { return ( ) }, cell: ({ row }) => { const date = new Date(row.getValue("uploadedAt")) const formatted = `${date.getDate()}/${date.getMonth() + 1}/${date.getFullYear()} à ${date.getHours()}:${date.getMinutes()}` return (

{formatted}

) }, }, { accessorKey: "extension", header: ({ column }) => { return (
Extension du fichier
) }, cell: ({ row }) => { const extension = row.getValue("extension") as string; return (
{extension}
) }, }, { id: "actions", header: ({ column }) => { return (
Actions
) }, cell: ({ row }) => { const file = row.original return (
) }, }, ] interface DataTableProps { columns: ColumnDef[] data: TData[] } export function FilesDataTable({ columns, data, }: DataTableProps) { const [sorting, setSorting] = useState([]) const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), onSortingChange: setSorting, getSortedRowModel: getSortedRowModel(), state: { sorting, }, }) return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {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())} ))} )) ) : ( Auccun résultat )}
) }