diff --git a/src/components/ui/DataTable.tsx b/src/components/ui/DataTable.tsx new file mode 100644 index 0000000..e18d65f --- /dev/null +++ b/src/components/ui/DataTable.tsx @@ -0,0 +1,91 @@ +'use client'; + +import { + ColumnDef, + ColumnFiltersState, + flexRender, + getCoreRowModel, + getFilteredRowModel, + useReactTable +} from '@tanstack/react-table'; + +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow +} from '@/components/ui/table'; +import { useState } from 'react'; +import { Input } from './input'; + +interface DataTableProps { + columns: ColumnDef[]; + data: TData[]; +} + +export function DataTable({ columns, data }: DataTableProps) { + const [columnFilters, setColumnFilters] = useState([]); + const table = useReactTable({ + data, + columns, + getCoreRowModel: getCoreRowModel(), + onColumnFiltersChange: setColumnFilters, + getFilteredRowModel: getFilteredRowModel(), + state: { + columnFilters + } + }); + + return ( +
+
+ table.getColumn('name')?.setFilterValue(event.target.value)} + className="max-w-sm" + /> +
+
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.header, header.getContext())} + + ); + })} + + ))} + + + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ))} + + )) + ) : ( + + + No results. + + + )} + +
+
+
+ ); +} diff --git a/src/pages/account/manage/ManageAccount.tsx b/src/pages/account/manage/ManageAccount.tsx new file mode 100644 index 0000000..522bf0a --- /dev/null +++ b/src/pages/account/manage/ManageAccount.tsx @@ -0,0 +1,81 @@ +import { apiConfig } from '@/config/api.config'; +import { Account, columns } from './account/Columns'; +import { DataTable } from '@/components/ui/DataTable'; +import axios from 'axios'; +import { useEffect, useState } from 'react'; +import { getData } from '@/utils'; +import { useCallApi } from '@/hooks'; + +const API_URL = apiConfig.service_dashboard; + +const dataAccount: Account[] = [ + { + id: 1, + name: 'eMoney Account', + description: 'Rekening Member eMoney', + systemAccount: false, + createdDate: new Date('2019-12-05'), + creditLimit: null, + currency: null + }, + { + id: 2, + name: 'Merchant Account', + description: 'Rekening Merchant', + systemAccount: false, + createdDate: new Date(), + creditLimit: null, + currency: null + } +]; + +const ManageAccount = () => { + const [accounts, setAccounts] = useState([]); + const { GetData } = useCallApi(); + // console.log(accounts); + + useEffect(() => { + const fetchAccount = async () => { + try { + const response = await fetch(`${API_URL}/user/list`); + const data: Account[] = await response.json(); + setAccounts(data); + } catch (error) { + console.error('Error fetching data', error); + } + }; + + fetchAccount(); + }, []); + + // const fetchAccount = async (page: number, limit: number, sorting: any, filter: any) => { + // try { + // const response = await GetData(`${API_URL}/user/list`, { + // limit: limit, + // page: page + 1, + // with_deleted: true, + // order_field: sorting[0].id, + // order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', + // filter: JSON.stringify(filter) + // }); + + // setAccounts(response?.data.list); + + // return { + // data: response?.data.list, + // totalCount: response?.data.total_count + // }; + // } catch (error) { + // console.log(error); + // } + // }; + + return ( +
+

Manage Account

+ +
+ ); +}; + +export default ManageAccount; diff --git a/src/pages/account/manage/account/Columns.tsx b/src/pages/account/manage/account/Columns.tsx new file mode 100644 index 0000000..64fc8fa --- /dev/null +++ b/src/pages/account/manage/account/Columns.tsx @@ -0,0 +1,71 @@ +import { Button } from '@/components/ui/button'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuSeparator, + DropdownMenuTrigger +} from '@/components/ui/dropdown-menu'; +import { ColumnDef } from '@tanstack/react-table'; +import { MoreHorizontal } from 'lucide-react'; + +export type Account = { + createdDate: Date; + creditLimit: number | null; + currency: string | null; + description: string; + id: number; + name: string; + systemAccount: boolean; +}; + +export const columns: ColumnDef[] = [ + { + accessorKey: 'id', + header: 'ID' + }, + { + accessorKey: 'name', + header: 'Name' + }, + { + accessorKey: 'description', + header: 'Description' + }, + { + accessorKey: 'systemAccount', + header: 'System Account' + }, + { + accessorKey: 'createdDate', + header: 'Created Date', + cell: ({ row }) => new Date(row.original.createdDate).toLocaleDateString() + }, + { + id: 'actions', + cell: ({ row }) => { + const dataAccount = row.original; + + return ( + + + + + + Actions + navigator.clipboard.writeText(dataAccount.id.toString())} + > + Copy account ID + + {/* */} + + + ); + } + } +]; diff --git a/src/pages/groups/Column.tsx b/src/pages/groups/Column.tsx new file mode 100644 index 0000000..bcd9476 --- /dev/null +++ b/src/pages/groups/Column.tsx @@ -0,0 +1,30 @@ +import { ColumnDef } from '@tanstack/react-table'; + +export type Group = { + id: number; + createdDate: Date; + name: string; + description: string; +}; + +export const columns: ColumnDef[] = [ + { + accessorKey: 'id', + header: 'ID' + }, + { + accessorKey: 'createdDate', + header: 'Created Date' + }, + { + accessorKey: 'name', + header: 'Name' + }, + { + accessorKey: 'description', + header: 'Description' + }, + { + id: 'actions' + } +]; diff --git a/src/pages/groups/ManageGroups.tsx b/src/pages/groups/ManageGroups.tsx new file mode 100644 index 0000000..bdbdb34 --- /dev/null +++ b/src/pages/groups/ManageGroups.tsx @@ -0,0 +1,36 @@ +import { DataTable } from '@/components/ui/DataTable'; +import { columns, Group } from './Column'; + +const dataGroup: Group[] = [ + { + id: 1, + createdDate: new Date('2018-11-23'), + name: 'ADMIN', + description: 'Admin Web' + }, + { + id: 2, + createdDate: new Date('2019-02-08'), + name: 'BANK', + description: 'Bank/Switching Group' + }, + { + id: 3, + createdDate: new Date('2018-11-27'), + name: 'REGULER', + description: 'Reguler Member' + } +]; + +const ManageGroups = () => { + return ( +
+
+

Groups

+ +
+
+ ); +}; + +export default ManageGroups;