diff --git a/apps/backoffice/src/app/accounts/page.tsx b/apps/backoffice/src/app/accounts/page.tsx index db00456..950d2c2 100644 --- a/apps/backoffice/src/app/accounts/page.tsx +++ b/apps/backoffice/src/app/accounts/page.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; -import { FC, ReactElement, useState } from 'react'; +import { FC, ReactElement } from 'react'; import { FilterOutlined, SearchOutlined, @@ -9,7 +9,6 @@ import { ArrowLeftOutlined, } from '@ant-design/icons'; import { Button, Input } from '@imphnen-frontend-service/ui/atoms'; -import { Pagination } from '@imphnen-frontend-service/ui/molecules'; import { DataTable } from '@imphnen-frontend-service/ui/organisms'; import { @@ -130,75 +129,7 @@ export const Components: FC = (): ReactElement => { {/* Table */} -
- - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => ( - - ))} - - ))} - - - {table.getRowModel().rows.map((row) => ( - - {row.getVisibleCells().map((cell, index) => ( - - ))} - - ))} - -
- {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext() - )} -
- {flexRender( - cell.column.columnDef.cell, - cell.getContext() - )} -
-
- {/* index + 1 + indexOfFirstItem, - }, - { label: 'Nama Lengkap', key: 'name' }, - { label: 'Email', key: 'email' }, - { label: 'Nomor Telp', key: 'phone' }, - { label: 'Alamat Pengiriman', key: 'address' }, - { - label: 'Action', - render: (item: Account) => ( - - ), - }, - ]} - /> */} + {/* Pagination */} {/* = ({ totalPages, onPageChange, }): ReactElement => { - // Generate page numbers to display const getPageNumbers = () => { const pages = []; - // const maxPagesToShow = 5; - - // Always show first page if (currentPage > 3) { pages.push(1); if (currentPage > 4) { @@ -25,7 +21,6 @@ export const Pagination: FC = ({ } } - // Calculate range of pages to show around current page const startPage = Math.max(1, currentPage - 1); const endPage = Math.min(totalPages, currentPage + 1); @@ -33,7 +28,6 @@ export const Pagination: FC = ({ pages.push(i); } - // Always show last page if (currentPage < totalPages - 2) { if (currentPage < totalPages - 3) { pages.push('...'); diff --git a/libs/ui/src/organisms/datatable/datatable.tsx b/libs/ui/src/organisms/datatable/datatable.tsx index 61dba12..545bea7 100644 --- a/libs/ui/src/organisms/datatable/datatable.tsx +++ b/libs/ui/src/organisms/datatable/datatable.tsx @@ -1,52 +1,57 @@ -import { ReactElement, ReactNode } from 'react'; import { + PaginationState, useReactTable, getCoreRowModel, getPaginationRowModel, - getFilteredRowModel, + flexRender, + ColumnDef, } from '@tanstack/react-table'; +import React from 'react'; interface DataTableProps { data: T[]; - headers: { - accessorKey?: keyof T; - header: string; - cell?: (info: any) => ReactNode; - }[]; - onRowClick?: (item: T) => void; + columns: ColumnDef[]; + pageSize?: number; } -export const DataTable = >({ +export const DataTable = ({ data, - headers, - onRowClick, -}: DataTableProps): ReactElement => { + columns, + pageSize = 9, +}: DataTableProps) => { + const [pagination, setPagination] = React.useState({ + pageIndex: 0, + pageSize, + }); + const table = useReactTable({ data, - columns: headers.map((header) => ({ - accessorKey: header.accessorKey, - header: header.header, - cell: header.cell, - })), + columns, + state: { + pagination, + }, getCoreRowModel: getCoreRowModel(), getPaginationRowModel: getPaginationRowModel(), - getFilteredRowModel: getFilteredRowModel(), + onPaginationChange: setPagination, }); + return (
- + {table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( - ))} @@ -54,43 +59,19 @@ export const DataTable = >({ {table.getRowModel().rows.map((row) => ( - onRowClick && onRowClick(row.original)} - > - {row.getVisibleCells().map((cell) => ( - + + {row.getVisibleCells().map((cell, index) => ( + ))} ))}
- {header.isPlaceholder ? null : ( -
- {typeof header.column.columnDef.header === 'function' - ? header.column.columnDef.header(header.getContext()) - : header.column.columnDef.header} -
- )} +
+ {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )}
{cell.getValue() as ReactNode}
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
-
- - - - -
); };