Skip to content

Commit 7fe4272

Browse files
committed
feat(categories): integrate new table into CategoriesPageClient, replace old table component with new implementation
1 parent 4db79eb commit 7fe4272

File tree

2 files changed

+49
-113
lines changed

2 files changed

+49
-113
lines changed

src/app/(private)/dashboard/categories/client.tsx

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
"use client";
22

3-
import type { Category, CategoryForm } from "@/types";
4-
53
import { useState } from "react";
64
import { useRouter } from "next/navigation";
75
import { useDisclosure, addToast } from "@heroui/react";
86
import { useForm } from "react-hook-form";
97
import { zodResolver } from "@hookform/resolvers/zod";
8+
import { SquarePenIcon, Trash2 } from "lucide-react";
9+
1010
import {
1111
createCategory,
1212
deleteCategory,
1313
updateCategory,
1414
} from "@/actions/categories";
15-
import { CategoryDrawer, CategoryTable } from "@/components/categories";
16-
import { DeleteModal, HeadingDashboard } from "@/components/ui";
15+
import { CategoryDrawer } from "@/components/categories";
16+
import { DeleteModal, HeadingDashboard, Table } from "@/components/ui";
1717
import { categorySchema } from "@/lib/zod";
1818

19+
import type { Category, CategoryForm, TableAction, TableColumn } from "@/types";
20+
1921
type Props = {
2022
categories: Category[];
2123
};
@@ -98,20 +100,54 @@ export default function CategoriesPageClient({ categories }: Props) {
98100
}
99101
};
100102

103+
const columns: TableColumn[] = [
104+
{ name: "Name", uid: "name", sortable: true },
105+
{ name: "Slug", uid: "slug", sortable: true },
106+
{ name: "Created At", uid: "created_at", sortable: true },
107+
];
108+
109+
const actions: TableAction[] = [
110+
{
111+
key: "edit",
112+
label: "Edit Category",
113+
icon: <SquarePenIcon size={18} />,
114+
shortcut: "⌘E",
115+
onAction: (category) => openEditModal(category),
116+
},
117+
{
118+
key: "delete",
119+
label: "Delete Category",
120+
icon: <Trash2 size={18} />,
121+
color: "danger",
122+
shortcut: "⌘D",
123+
onAction: (category) => handleDelete(category.id),
124+
},
125+
];
126+
101127
return (
102128
<div className="flex flex-col gap-4">
103129
{/* Heading */}
104-
<HeadingDashboard
105-
title="Categories"
106-
count={categories.length}
107-
openAddModal={openAddModal}
108-
/>
130+
<HeadingDashboard title="Categories" count={categories.length} />
109131

110132
{/* Table */}
111-
<CategoryTable
112-
categories={categories}
113-
openEditModal={openEditModal}
114-
handleDelete={handleDelete}
133+
<Table
134+
title="Category table"
135+
data={categories}
136+
columns={columns}
137+
actions={actions}
138+
searchPlaceholder="Search by name..."
139+
searchKeys={["name"]}
140+
defaultRowsPerPage={10}
141+
rowsPerPageOptions={[10, 25, 50, 100]}
142+
addButton={{ label: "Add Category", onAdd: () => openAddModal() }}
143+
cellRenderer={({ item, columnKey, value }) => {
144+
switch (columnKey) {
145+
case "created_at":
146+
return new Date(value).toLocaleDateString();
147+
default:
148+
return value;
149+
}
150+
}}
115151
/>
116152

117153
{/* Drawer */}

src/components/categories/category-table.tsx

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)