Skip to content

Commit 9515ee6

Browse files
committed
the data is entring
1 parent 7869a24 commit 9515ee6

File tree

4 files changed

+78
-22
lines changed

4 files changed

+78
-22
lines changed

src/app/api/events/[id]/route.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { db } from "@/lib/db";
33
import { events } from "@/lib/db/schema";
44
import { eq } from "drizzle-orm";
55

6+
7+
// GET one event
8+
export async function GET(_: Request, { params }: { params: { id: string } }) {
9+
const result = await db.select().from(events).where(eq(events.id, params.id));
10+
if (!result[0]) {
11+
return NextResponse.json({ error: "Not found" }, { status: 404 });
12+
}
13+
return NextResponse.json(result[0]);
14+
}
15+
616
// Update event
717
export async function PUT(req: Request, { params }: { params: { id: string } }) {
818
const data = await req.json();

src/app/events/[id]/edit/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// New Event Page - src/app/events/[id]/edit/page.tsx
12
"use client";
23

34
import { useState } from "react";

src/app/events/[id]/page.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { notFound } from "next/navigation";
2+
3+
export default async function EventDetailPage({
4+
params,
5+
}: {
6+
params: { id: string };
7+
}) {
8+
const { id } = params;
9+
10+
const baseUrl =
11+
process.env.NEXT_PUBLIC_BASE_URL || "http://localhost:3000";
12+
13+
const res = await fetch(`${baseUrl}/api/events/${id}`, {
14+
cache: "no-store",
15+
});
16+
17+
if (!res.ok) return notFound();
18+
19+
const event = await res.json();
20+
21+
return (
22+
<div className="max-w-2xl mx-auto p-6 space-y-4">
23+
<h1 className="text-3xl font-bold">{event.title}</h1>
24+
<p className="text-gray-600">{event.venue}</p>
25+
<p className="text-gray-500">
26+
{new Date(event.date).toLocaleDateString()} at {event.time}
27+
</p>
28+
{event.image && (
29+
<img
30+
src={event.image}
31+
alt={event.title}
32+
className="w-full rounded-lg shadow"
33+
/>
34+
)}
35+
<p className="mt-4 whitespace-pre-line">{event.description}</p>
36+
</div>
37+
);
38+
}
39+

src/app/events/page.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Admin Events Page - src/app/events/page.tsx
12
"use client";
23

34
import { useState, useEffect } from "react";
@@ -46,28 +47,33 @@ export default function AdminEventsPage() {
4647
</tr>
4748
</thead>
4849
<tbody>
49-
{events.map((e: Event) => (
50-
<tr key={e.id} className="border-t">
51-
<td className="p-2">{e.title}</td>
52-
<td className="p-2">{e.venue}</td>
53-
<td className="p-2">{new Date(e.date).toLocaleDateString()}</td>
54-
<td className="p-2 flex gap-2">
55-
<button
56-
onClick={() => router.push(`/events/${e.id}/edit`)}
57-
className="p-1 bg-yellow-300 rounded"
58-
>
59-
<Pencil className="w-4 h-4" />
60-
</button>
61-
<button
62-
onClick={() => deleteEvent(e.id)}
63-
className="p-1 bg-red-500 text-white rounded"
64-
>
65-
<Trash className="w-4 h-4" />
66-
</button>
67-
</td>
68-
</tr>
69-
))}
70-
</tbody>
50+
{events.map((e: Event) => (
51+
<tr
52+
key={e.id}
53+
className="border-t cursor-pointer hover:bg-gray-50"
54+
onClick={() => router.push(`/events/${e.id}`)}
55+
>
56+
<td className="p-2">{e.title}</td>
57+
<td className="p-2">{e.venue}</td>
58+
<td className="p-2">{new Date(e.date).toLocaleDateString()}</td>
59+
<td className="p-2 flex gap-2" onClick={(ev) => ev.stopPropagation()}>
60+
<button
61+
onClick={() => router.push(`/events/${e.id}/edit`)}
62+
className="p-1 bg-yellow-300 rounded"
63+
>
64+
<Pencil className="w-4 h-4" />
65+
</button>
66+
<button
67+
onClick={() => deleteEvent(e.id)}
68+
className="p-1 bg-red-500 text-white rounded"
69+
>
70+
<Trash className="w-4 h-4" />
71+
</button>
72+
</td>
73+
</tr>
74+
))}
75+
</tbody>
76+
7177
</table>
7278
</div>
7379
);

0 commit comments

Comments
 (0)