diff --git a/src/app/admin/home/page.tsx b/src/app/admin/home/page.tsx index 0aec267..6c2cfee 100644 --- a/src/app/admin/home/page.tsx +++ b/src/app/admin/home/page.tsx @@ -1,10 +1,129 @@ +"use client" +import Table from "#/components/table/table" +import { ColumnDef } from "@tanstack/react-table" export default function HomePage () { + type Payment = { + id: string + amount: number + status: "pending" | "processing" | "success" | "failed" + email: string + } + + + const data: Payment[] = [ + { + id: "728ed52f", + amount: 100, + status: "pending", + email: "m@example.com", + }, + { + id: "728ed521", + amount: 200, + status: "pending", + email: "j@example.com", + }, + { + id: "728ed528", + amount: 300, + status: "processing", + email: "f@example.com", + }, + { + id: "728ed52g", + amount: 600, + status: "success", + email: "h@example.com", + }, + { + id: "728ed520", + amount: 50, + status: "failed", + email: "k@example.com", + }, + { + id: "728ed529", + amount: 200, + status: "pending", + email: "l@example.com", + }, + { + id: "728ed526", + amount: 150, + status: "processing", + email: "d@example.com", + }, + { + id: "728ed523", + amount: 100, + status: "success", + email: "o@example.com", + }, + { + id: "728ed52y", + amount: 100, + status: "failed", + email: "v@example.com", + }, + // ... + ] + + + + const columns: ColumnDef[] = [ + { + id: "select", + header: ({ table }) => ( + table.toggleAllPageRowsSelected(!!value)} type="checkbox" name="" id="" /> + ), + cell: ({ row }) => ( + row.toggleSelected(!!value)} type="checkbox" name="" id="" /> + ), + }, + { + accessorKey: "status", + header: "Status", + }, + { + accessorKey: "email", + header: ({ column }) => { + return ( +

Email

+ ) + }, + }, + { + accessorKey: "amount", + header: () =>
Amount
, + cell: ({ row }) => { + const amount = parseFloat(row.getValue("amount")) + const formatted = new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + }).format(amount) + + return
{formatted}
+ }, + + + + }, + +] + return( <> - + ) } \ No newline at end of file diff --git a/src/components/table/table.tsx b/src/components/table/table.tsx index 5c078f6..cc46a5d 100644 --- a/src/components/table/table.tsx +++ b/src/components/table/table.tsx @@ -10,15 +10,18 @@ import { getFilteredRowModel, } from "@tanstack/react-table" import { useState } from "react"; +import { clsx, type ClassValue } from "clsx" interface DataTableProps { columns: ColumnDef[] - data: TData[] + data: TData[], + pageSize?: number } export default function Table({ columns, data, + pageSize = 10 }: DataTableProps) { const [rowSelection, setRowSelection] = useState({}) const [columnFilters, setColumnFilters] = useState( @@ -35,26 +38,37 @@ export default function Table({ rowSelection, columnFilters, }, + initialState: { + pagination: { + pageSize: pageSize, + } + }, getFilteredRowModel: getFilteredRowModel(), onRowSelectionChange: setRowSelection, onColumnFiltersChange: setColumnFilters, }) + const totalPages = table.getPageCount() + const currentPage = table.getState().pagination.pageIndex + 1 - function clsx(arg0: string, arg1: { 'bg-gray-300': boolean; }): string | undefined { - throw new Error("Function not implemented."); + const getPageNumbers = () => { + const pages = [] + for (let i = 1; i <= totalPages; i++) { + pages.push(i) + } + return pages } return(
-
-
- +
+
+ {table.getHeaderGroups().map((headerGroup) => ( - + {headerGroup.headers.map((header) => { return( - {table.getRowModel().rows.length ? ( table.getRowModel().rows.map((row) => ( - + {row.getVisibleCells().map((cell) => ( - ))} @@ -79,7 +93,7 @@ export default function Table({ ) : ( - @@ -90,13 +104,32 @@ export default function Table({
+ +
+ {getPageNumbers().map((pageNumber) => ( + + ))} +
+
+ {flexRender( header.column.columnDef.header, header.getContext() @@ -68,9 +82,9 @@ export default function Table({
+ {flexRender(cell.column.columnDef.cell, cell.getContext())}
+ Aucun résultats