Files
imphnen-frontend-service/apps/backoffice/src/app/accounts/page.tsx
T

229 lines
6.9 KiB
TypeScript
Raw Normal View History

2025-03-28 16:21:27 +07:00
import * as React from 'react';
2025-03-28 18:17:13 +07:00
import { FC, ReactElement } from 'react';
import {
FilterOutlined,
SearchOutlined,
EditOutlined,
2025-03-28 16:50:58 +07:00
ArrowRightOutlined,
ArrowLeftOutlined,
} from '@ant-design/icons';
2025-03-27 15:17:04 +07:00
import { Button, Input } from '@imphnen-frontend-service/ui/atoms';
import { DataTable } from '@imphnen-frontend-service/ui/organisms';
2025-03-27 15:17:04 +07:00
2025-03-28 16:21:27 +07:00
import {
ColumnDef,
flexRender,
getCoreRowModel,
2025-03-28 16:50:58 +07:00
getPaginationRowModel,
PaginationState,
2025-03-28 16:21:27 +07:00
useReactTable,
} from '@tanstack/react-table';
// Define account interface
interface Account {
id: number;
name: string;
email: string;
phone: string;
address: string;
}
2025-03-27 15:17:04 +07:00
// Mock data for demonstration
2025-03-28 16:21:27 +07:00
const mockData: Account[] = Array.from({ length: 90 }, (_, i) => ({
2025-03-27 15:17:04 +07:00
id: i + 1,
name: i === 0 ? 'Ahmad Wijuana' : 'Nama Lengkap',
2025-03-28 16:21:27 +07:00
email: 'fullname23@gmail.com',
2025-03-27 15:17:04 +07:00
phone: '081904423804',
address: 'Jl. Pantai Cibaduyut Indonesia',
}));
2025-03-27 15:06:30 +07:00
2025-03-28 16:21:27 +07:00
const columns: ColumnDef<any>[] = [
{
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 (
<Button
variant="primary"
size="sm"
onClick={(e) => {
e.stopPropagation();
// handleEdit(row.id);
}}
className="flex items-center gap-2"
>
<EditOutlined /> Edit
</Button>
);
},
},
];
2025-03-27 15:06:30 +07:00
export const Components: FC = (): ReactElement => {
2025-03-28 16:50:58 +07:00
const [pagination, setPagination] = React.useState<PaginationState>({
pageIndex: 0,
pageSize: 9,
});
2025-03-28 16:21:27 +07:00
const table = useReactTable({
data: mockData,
columns,
2025-03-28 16:50:58 +07:00
state: {
pagination,
},
2025-03-28 16:21:27 +07:00
getCoreRowModel: getCoreRowModel(),
2025-03-28 16:50:58 +07:00
getPaginationRowModel: getPaginationRowModel(),
onPaginationChange: setPagination,
2025-03-28 16:21:27 +07:00
});
2025-03-27 15:06:30 +07:00
return (
<main className="w-full px-[48px] py-[40px] flex flex-col gap-8">
2025-03-27 16:58:24 +07:00
{/* Header */}
2025-03-27 15:06:30 +07:00
<header className="bg-white py-4 px-8 rounded-md shadow p-4">
<h1 className="text-p2 font-semibold">Data Akun</h1>
</header>
2025-03-27 15:17:04 +07:00
{/* Account Table Section */}
<section className="flex flex-col gap-6 p-8 bg-white rounded-md">
{/* Search and Filter */}
2025-03-27 16:55:54 +07:00
<div className="flex justify-between items-center gap-8 mb-2">
<div className="relative w-full">
2025-03-27 15:17:04 +07:00
<Input
placeholder="Cari berdasarkan nama lengkap, email"
2025-03-27 16:55:54 +07:00
className="pl-12 w-full max-h-full"
2025-03-27 15:17:04 +07:00
/>
2025-03-27 16:55:54 +07:00
<div className="absolute left-3 top-1/2 transform -translate-y-1/2 text-[16px]">
2025-03-27 15:17:04 +07:00
<SearchOutlined />
</div>
</div>
2025-03-27 16:55:54 +07:00
<Button
variant="primary"
disabled
size="md"
className="flex items-center gap-3"
>
2025-03-27 15:17:04 +07:00
<FilterOutlined />
Filters
</Button>
</div>
{/* Table */}
2025-03-28 18:17:13 +07:00
<DataTable data={mockData} columns={columns} />
2025-03-27 15:17:04 +07:00
{/* Pagination */}
2025-03-28 16:50:58 +07:00
{/* <Pagination
2025-03-27 15:17:04 +07:00
currentPage={currentPage}
totalPages={Math.ceil(filteredData.length / itemsPerPage)}
onPageChange={handlePageChange}
2025-03-28 16:50:58 +07:00
/> */}
<div className="flex items-center justify-center gap-[40px]">
<button
className="disabled:opacity-50 cursor-pointer"
onClick={() => table.previousPage()}
disabled={!table.getCanPreviousPage()}
aria-label="Previous page"
>
<ArrowLeftOutlined className="text-[16px] text-neutral-800" />
</button>
2025-03-28 17:29:06 +07:00
<div className="flex gap-4 items-baseline">
{table.getPageCount() <= 8 ? (
Array.from({ length: table.getPageCount() }, (_, index) => (
2025-03-28 16:50:58 +07:00
<button
2025-03-28 17:29:06 +07:00
className={`size-[30px] py-[8px] flex items-center justify-center rounded-md cursor-pointer ${
table.getState().pagination.pageIndex === index
? 'bg-primary-500 text-white'
: 'bg-primary-100 hover:bg-primary-200'
}`}
onClick={() => table.setPageIndex(index)}
>
{index + 1}
</button>
))
) : (
// Render ellipsis jika total halaman lebih dari 8
<>
<button
onClick={() => table.setPageIndex(0)}
2025-03-28 16:50:58 +07:00
className={`size-[30px] py-[8px] flex items-center justify-center rounded-md cursor-pointer ${
2025-03-28 17:29:06 +07:00
table.getState().pagination.pageIndex === 0
2025-03-28 16:50:58 +07:00
? 'bg-primary-500 text-white'
: 'bg-primary-100 hover:bg-primary-200'
}`}
>
2025-03-28 17:29:06 +07:00
1
2025-03-28 16:50:58 +07:00
</button>
2025-03-28 17:29:06 +07:00
{table.getState().pagination.pageIndex > 3 && <span>...</span>}
{Array.from(
{ length: 5 },
(_, index) =>
table.getState().pagination.pageIndex - 2 + index
)
.filter((page) => page > 0 && page < table.getPageCount() - 1)
.map((page) => (
<button
key={page}
onClick={() => table.setPageIndex(page)}
className={`size-[30px] py-[8px] flex items-center justify-center rounded-md cursor-pointer ${
table.getState().pagination.pageIndex === page
? 'bg-primary-500 text-white'
: 'bg-primary-100 hover:bg-primary-200'
}`}
>
{page + 1}
</button>
))}
{table.getState().pagination.pageIndex <
table.getPageCount() - 4 && <span>...</span>}
<button
onClick={() => table.setPageIndex(table.getPageCount() - 1)}
className={`size-[30px] py-[8px] flex items-center justify-center rounded-md cursor-pointer ${
table.getState().pagination.pageIndex ===
table.getPageCount() - 1
? 'bg-primary-500 text-white'
: 'bg-primary-100 hover:bg-primary-200'
}`}
>
{table.getPageCount()}
</button>
</>
2025-03-28 16:50:58 +07:00
)}
2025-03-28 17:29:06 +07:00
</div>
2025-03-28 16:50:58 +07:00
<button
className="disabled:opacity-50 cursor-pointer"
onClick={() => table.nextPage()}
disabled={!table.getCanNextPage()}
aria-label="Next page"
>
<ArrowRightOutlined className="text-[16px] text-neutral-800" />
</button>
</div>
2025-03-27 15:17:04 +07:00
</section>
2025-03-27 15:06:30 +07:00
</main>
);
};
export default Components;