2025-03-27 15:17:04 +07:00
|
|
|
import { FC, ReactElement, useState } from 'react';
|
2025-03-27 17:22:04 +07:00
|
|
|
import {
|
|
|
|
|
FilterOutlined,
|
|
|
|
|
SearchOutlined,
|
|
|
|
|
EditOutlined,
|
|
|
|
|
} from '@ant-design/icons';
|
2025-03-27 15:17:04 +07:00
|
|
|
import { Button, Input } from '@imphnen-frontend-service/ui/atoms';
|
2025-03-27 15:59:02 +07:00
|
|
|
import { Pagination } from '@imphnen-frontend-service/ui/molecules';
|
|
|
|
|
import { DataTable } from '@imphnen-frontend-service/ui/organisms';
|
2025-03-27 15:17:04 +07:00
|
|
|
|
2025-03-27 17:22:04 +07:00
|
|
|
// 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-27 17:22:04 +07:00
|
|
|
const mockData: Account[] = Array.from({ length: 20 }, (_, i) => ({
|
2025-03-27 15:17:04 +07:00
|
|
|
id: i + 1,
|
|
|
|
|
name: i === 0 ? 'Ahmad Wijuana' : 'Nama Lengkap',
|
|
|
|
|
email: 'Fullname23@gmail.com',
|
|
|
|
|
phone: '081904423804',
|
|
|
|
|
address: 'Jl. Pantai Cibaduyut Indonesia',
|
|
|
|
|
}));
|
2025-03-27 15:06:30 +07:00
|
|
|
|
|
|
|
|
export const Components: FC = (): ReactElement => {
|
2025-03-27 15:17:04 +07:00
|
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
|
|
const itemsPerPage = 9;
|
|
|
|
|
|
|
|
|
|
// Filter data based on search query
|
|
|
|
|
const filteredData = mockData.filter(
|
|
|
|
|
(item) =>
|
|
|
|
|
item.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
|
|
|
|
item.email.toLowerCase().includes(searchQuery.toLowerCase())
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Paginate data
|
|
|
|
|
const indexOfLastItem = currentPage * itemsPerPage;
|
|
|
|
|
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 handlePageChange = (pageNumber: number) => {
|
|
|
|
|
setCurrentPage(pageNumber);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSearch = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setSearchQuery(e.target.value);
|
|
|
|
|
setCurrentPage(1); // Reset to first page when searching
|
|
|
|
|
};
|
|
|
|
|
|
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"
|
|
|
|
|
value={searchQuery}
|
|
|
|
|
onChange={handleSearch}
|
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-27 17:22:04 +07:00
|
|
|
<DataTable
|
|
|
|
|
data={currentItems}
|
|
|
|
|
headers={[
|
|
|
|
|
{
|
|
|
|
|
label: 'No.',
|
|
|
|
|
render: (_, index) => 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) => (
|
|
|
|
|
<Button
|
|
|
|
|
variant="primary"
|
|
|
|
|
size="sm"
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
handleEdit(item.id);
|
|
|
|
|
}}
|
|
|
|
|
className="flex items-center gap-2"
|
|
|
|
|
>
|
|
|
|
|
<EditOutlined /> Edit
|
|
|
|
|
</Button>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
/>
|
2025-03-27 15:17:04 +07:00
|
|
|
|
|
|
|
|
{/* Pagination */}
|
|
|
|
|
<Pagination
|
|
|
|
|
currentPage={currentPage}
|
|
|
|
|
totalPages={Math.ceil(filteredData.length / itemsPerPage)}
|
|
|
|
|
onPageChange={handlePageChange}
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
2025-03-27 15:06:30 +07:00
|
|
|
</main>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Components;
|