Skip to content

Commit 2ceaa1a

Browse files
committed
feat: styling tablecolumn list event admin
1 parent 56af553 commit 2ceaa1a

File tree

4 files changed

+61
-40
lines changed

4 files changed

+61
-40
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"use client";
2+
import Badge from "@/components/ui/Badge";
3+
import { Button } from "@/components/ui/Button";
4+
import { EventType } from "@/domains/Events";
5+
import { formatDateEvent } from "@/lib/format";
6+
import { ColumnDef } from "@tanstack/react-table";
7+
import { Edit2, SquareChartGantt } from "lucide-react";
8+
9+
export const columnsEventListAdmin: ColumnDef<EventType>[] = [
10+
{
11+
accessorKey: "title",
12+
header: "Event Title",
13+
},
14+
{
15+
accessorKey: "date_event",
16+
header: "Date",
17+
cell: ({ row }) => <p>{formatDateEvent(row.original.date_event)}</p>,
18+
},
19+
{
20+
accessorKey: "location",
21+
header: "Location",
22+
},
23+
{
24+
accessorKey: "status",
25+
header: "Status",
26+
cell: ({ row }) => (
27+
<div>
28+
<Badge variant={row.original.status}>{row.original.status}</Badge>
29+
</div>
30+
),
31+
},
32+
{
33+
id: "actions",
34+
header: "Actions",
35+
cell: ({ row }) => (
36+
<div className="flex gap-2">
37+
<Button
38+
size="icon"
39+
variant="outline"
40+
className="cursor-poiner h-8 w-8 cursor-pointer border-blue-500 bg-blue-500 text-white hover:bg-blue-600 hover:text-white"
41+
onClick={() => console.log("Edit event:", row.original.id)}
42+
>
43+
<Edit2 className="h-4 w-4" />
44+
</Button>
45+
<Button
46+
size="icon"
47+
variant="outline"
48+
className="h-8 w-8 cursor-pointer border-emerald-500 bg-emerald-500 text-white hover:bg-emerald-600 hover:text-white"
49+
onClick={() => console.log("View event:", row.original.id)}
50+
>
51+
<SquareChartGantt className="h-4 w-4" />
52+
</Button>
53+
</div>
54+
),
55+
},
56+
];

src/features/events/components/MyEventCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Clock, Pin } from "lucide-react";
33
import Badge from "@/components/ui/Badge";
44
import { Card, CardContent, CardFooter } from "@/components/ui/Card";
55
import { UserEventType } from "@/domains/Events";
6-
import { useFormatDateEvent } from "@/lib/format";
6+
import { formatDateEvent } from "@/lib/format";
77

88
const MyEventCard = ({ data }: { data: UserEventType }) => {
99
const { order_no, status } = data;
@@ -38,7 +38,7 @@ const MyEventCard = ({ data }: { data: UserEventType }) => {
3838
<CardFooter className="mt-auto flex flex-col items-start gap-2 px-4 pt-3 pb-4">
3939
<div className="flex items-center gap-2">
4040
<Clock size={15} className="text-gray-500" />
41-
<p className="text-sm">{useFormatDateEvent(data.event_detail.date as string) || "-"}</p>
41+
<p className="text-sm">{formatDateEvent(data.event_detail.date as string) || "-"}</p>
4242
</div>
4343
<div className="flex items-center gap-2">
4444
<Pin size={15} className="text-gray-500" />

src/features/events/pages/AdminEventsListPage.tsx

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import TableData from "@/components/common/TableData";
44
import { Button } from "@/components/ui/Button";
55
import { useRouter } from "@/lib/navigation";
6-
import { ColumnDef } from "@tanstack/react-table";
76
import { Plus } from "lucide-react";
87
import { useEventsAdmin } from "../hooks/useEvent";
9-
import { EventType } from "@/domains/Events";
108
import { useQueryParams } from "@/hooks";
119
import Loader from "@/components/common/Loader";
10+
import { columnsEventListAdmin } from "../components/ColumnsEventListAdmin";
1211

1312
const AdminEventsListPage = () => {
1413
const router = useRouter();
@@ -18,42 +17,8 @@ const AdminEventsListPage = () => {
1817
const searchQuery = getParam("search", "");
1918

2019
const { data: eventsResponse, isLoading } = useEventsAdmin(currentPage, itemsPerPage, searchQuery);
21-
console.log(eventsResponse);
2220
const totalPages = eventsResponse?.pagination?.total_pages || 1;
2321

24-
const columns: ColumnDef<EventType>[] = [
25-
{
26-
accessorKey: "title",
27-
header: "Event Title",
28-
},
29-
{
30-
accessorKey: "date_event",
31-
header: "Date",
32-
},
33-
{
34-
accessorKey: "location",
35-
header: "Location",
36-
},
37-
{
38-
accessorKey: "status",
39-
header: "Status",
40-
},
41-
{
42-
id: "actions",
43-
header: "Actions",
44-
cell: ({ row }) => (
45-
<div className="flex gap-2">
46-
<Button size="sm" variant="outline" onClick={() => console.log("Edit event:", row.original.id)}>
47-
Edit
48-
</Button>
49-
<Button size="sm" variant="outline" onClick={() => console.log("View event:", row.original.id)}>
50-
View
51-
</Button>
52-
</div>
53-
),
54-
},
55-
];
56-
5722
const createEventButton = (
5823
<Button
5924
className="bg-hmc-base-blue hover:bg-hmc-base-blue/90 cursor-pointer"
@@ -76,7 +41,7 @@ const AdminEventsListPage = () => {
7641
) : (
7742
<TableData
7843
data={eventsResponse?.data || []}
79-
columns={columns}
44+
columns={columnsEventListAdmin}
8045
searchable
8146
searchPlaceholder="Search events"
8247
rightAction={createEventButton}

src/lib/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function useFormatPrice(price?: number) {
2222
}).format(price as number);
2323
}
2424

25-
export const useFormatDateEvent = (dateString: string): string => {
25+
export const formatDateEvent = (dateString: string): string => {
2626
const date = new Date(dateString);
2727
return new Intl.DateTimeFormat("id-ID", {
2828
weekday: "long",

0 commit comments

Comments
 (0)