diff --git a/apps/backoffice/src/app/accounts/page.tsx b/apps/backoffice/src/app/accounts/page.tsx index c68bbc0..7dc263b 100644 --- a/apps/backoffice/src/app/accounts/page.tsx +++ b/apps/backoffice/src/app/accounts/page.tsx @@ -1,3 +1,5 @@ +import * as React from 'react'; + import { FC, ReactElement, useState } from 'react'; import { FilterOutlined, @@ -8,6 +10,13 @@ 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 { + ColumnDef, + flexRender, + getCoreRowModel, + useReactTable, +} from '@tanstack/react-table'; + // Define account interface interface Account { id: number; @@ -18,14 +27,74 @@ interface Account { } // Mock data for demonstration -const mockData: Account[] = Array.from({ length: 20 }, (_, i) => ({ +const mockData: Account[] = Array.from({ length: 90 }, (_, i) => ({ id: i + 1, name: i === 0 ? 'Ahmad Wijuana' : 'Nama Lengkap', - email: 'Fullname23@gmail.com', + email: 'fullname23@gmail.com', phone: '081904423804', address: 'Jl. Pantai Cibaduyut Indonesia', })); +const columns: ColumnDef[] = [ + { + header: 'No', + accessorKey: 'id', + }, + { + header: 'Nama Lengkap', + accessorKey: 'name', + }, + { + header: 'Email', + accessorKey: 'email', + }, + { + header: 'Nomor Telp', + accessorKey: 'phone', + }, + { + header: 'Alamat Pengiriman', + accessorKey: 'address', + }, + { + header: 'Action', + cell: ({ row }) => { + return ( + + ); + }, + }, +]; + +// const columnHelper = createColumnHelper(); +// const columns = [ +// columnHelper.accessor('id', { +// cell: (info) => info.column.id, +// }), +// columnHelper.accessor('name', { +// header: 'Nama Lengkap', +// cell: (info) => info.getValue(), +// }), +// columnHelper.accessor('name', { +// header: 'Nama Lengkap', +// cell: (info) => info.getValue(), +// }), +// columnHelper.accessor('name', { +// header: 'Nama Lengkap', +// cell: (info) => info.getValue(), +// }), +// ]; + export const Components: FC = (): ReactElement => { const [searchQuery, setSearchQuery] = useState(''); const [currentPage, setCurrentPage] = useState(1); @@ -43,10 +112,10 @@ export const Components: FC = (): ReactElement => { const indexOfFirstItem = indexOfLastItem - itemsPerPage; const currentItems = filteredData.slice(indexOfFirstItem, indexOfLastItem); - const handleEdit = (id: number) => { - console.log(`Edit item with id: ${id}`); - // Implement edit functionality - }; + // const handleEdit = (id: number) => { + // console.log(`Edit item with id: ${id}`); + // // Implement edit functionality + // }; const handlePageChange = (pageNumber: number) => { setCurrentPage(pageNumber); @@ -57,6 +126,14 @@ export const Components: FC = (): ReactElement => { setCurrentPage(1); // Reset to first page when searching }; + // const [data, _setData] = React.useState(() => [...mockData]); + + const table = useReactTable({ + data: mockData, + columns, + getCoreRowModel: getCoreRowModel(), + }); + return (
{/* Header */} @@ -92,7 +169,47 @@ 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() + )} +
+ + {/* { ), }, ]} - /> + /> */} {/* Pagination */}