From c51889d4401623edb86b9aa05877eb18b1a0ea29 Mon Sep 17 00:00:00 2001 From: Wikzyy Date: Tue, 15 Apr 2025 21:11:09 +0700 Subject: [PATCH] update table on manage group --- src/pages/groups/Column.tsx | 22 +++- src/pages/groups/ListToolbar.tsx | 49 +++++++ src/pages/groups/ManageGroups.tsx | 205 ++++++++++++++++-------------- 3 files changed, 178 insertions(+), 98 deletions(-) create mode 100644 src/pages/groups/ListToolbar.tsx diff --git a/src/pages/groups/Column.tsx b/src/pages/groups/Column.tsx index d796078..2f6fe7f 100644 --- a/src/pages/groups/Column.tsx +++ b/src/pages/groups/Column.tsx @@ -1,3 +1,4 @@ +import { KeenIcon } from '@/components'; import { ColumnDef } from '@tanstack/react-table'; export type Group = { @@ -8,7 +9,7 @@ export type Group = { description: string; }; -export const columns: ColumnDef[] = [ +export const getColumns = (handleUpdate: (data: any) => void): ColumnDef[] => [ { accessorKey: 'no', header: 'ID' @@ -30,8 +31,19 @@ export const columns: ColumnDef[] = [ accessorKey: 'description', header: 'Description' }, - // { - // id: 'actions', - // header: 'Actions' - // } + { + id: 'actions', + cell: ({ row }) => { + const dataMembers = row.original; + + return ( + + ); + } + } ]; diff --git a/src/pages/groups/ListToolbar.tsx b/src/pages/groups/ListToolbar.tsx new file mode 100644 index 0000000..7ab5fa4 --- /dev/null +++ b/src/pages/groups/ListToolbar.tsx @@ -0,0 +1,49 @@ +import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; +import { Button } from '@/components/ui/button'; + +const ListToolBar = ({ createGroup }: { createGroup: () => void }) => { + const { table, reload } = useDataGrid(); + + return ( +
+
+
+
+ + + + +
+
+ + + + +
+
+
+
+ ); +}; + +export { ListToolBar }; diff --git a/src/pages/groups/ManageGroups.tsx b/src/pages/groups/ManageGroups.tsx index 55ae1eb..3ba347d 100644 --- a/src/pages/groups/ManageGroups.tsx +++ b/src/pages/groups/ManageGroups.tsx @@ -1,5 +1,5 @@ import { DataTable } from '@/components/ui/DataTable'; -import { columns, Group } from './Column'; +import { getColumns, Group } from './Column'; import { apiConfig } from '@/config/api.config'; import axios, { AxiosResponse } from 'axios'; import { Helmet } from 'react-helmet'; @@ -24,6 +24,8 @@ import CloseIcon from '@mui/icons-material/Close'; import Divider from '@mui/material/Divider'; import ConfirmDialog from '@/components/confirm'; import { toast } from 'sonner'; +import { Container, DataGridProvider } from '@/components'; +import { ListToolBar } from './ListToolbar'; // import { DialogHeader } from '@/components/ui/dialog'; // import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; const BASE_URL = apiConfig.service_customer; @@ -89,9 +91,9 @@ const ManageGroups = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - if (!formData.groupName) return toast.warning(`Group name can not be empty!`) - if (!formData.status) return toast.warning(`Status can not be empty!`) - if (!formData.description) return toast.warning(`Description can not be empty!`) + if (!formData.groupName) return toast.warning(`Group name can not be empty!`); + if (!formData.status) return toast.warning(`Status can not be empty!`); + if (!formData.description) return toast.warning(`Description can not be empty!`); setIsDialogOpen(false); setDialogOpen(true); }; @@ -134,7 +136,7 @@ const ManageGroups = () => { description: formData.description, created_at: new Date() }); - toast.success(`Success create group`) + toast.success(`Success create group`); } else if (dialogType === 'update') { await axios.put(`${BASE_URL}/groups/update/${formData.id}`, { name: formData.groupName, @@ -142,14 +144,14 @@ const ManageGroups = () => { description: formData.description, updated_at: new Date() }); - toast.success(`Success update group`) + toast.success(`Success update group`); } else if (dialogType === 'delete') { await axios.delete(`${BASE_URL}/groups/delete/${formData.id}/true`); - toast.success(`Success delete group`) + toast.success(`Success delete group`); } } catch (error: any) { console.log(error); - toast.error(error.message) + toast.error(error.message); } finally { await fetchGroups(); setDialogOpen(false); @@ -162,19 +164,19 @@ const ManageGroups = () => { TPAY | Manage Group - setDialogOpen(false)} - title="Confirm Action" - content={ - `Are you sure you want to ` + - (dialogType === 'create' ? 'create?' : dialogType === 'update' ? 'update?' : 'delete?') - } - onYes={handleYes} - onNo={() => setDialogOpen(false)} - /> -

Groups

-
+ + setDialogOpen(false)} + title="Confirm Action" + content={ + `Are you sure you want to ` + + (dialogType === 'create' ? 'create?' : dialogType === 'update' ? 'update?' : 'delete?') + } + onYes={handleYes} + onNo={() => setDialogOpen(false)} + /> +

Groups

Dashboard @@ -188,84 +190,101 @@ const ManageGroups = () => { Manage Groups -
-
- */} +
+ {/* -
+ /> */} + } + layout={{ card: true }} + sorting={[{ id: 'created_at', desc: true }]} + serverSide={false} + onRowSelectionChange={(selected, table: any) => { + const selectedRow = table.getSelectedRowModel().rows[0]; + if (selectedRow) handleUpdate(selectedRow.original); + }} + /> +
+ {/* */} - - -
- {dialogType==='create'?"Create New Group":"Update Group"} - - - -
- -
-
-
- - -
-
- - - - } - label="Yes" - /> - } - label="No" - /> - - -
-
- - -
- -
-
-
-
+ + +
+ + {dialogType === 'create' ? 'Create New Group' : 'Update Group'} + + + + +
+ +
+
+
+ + +
+
+ + + + } + label="Yes" + /> + } + label="No" + /> + + +
+
+ + +
+ +
+
+
+
+ ); };