Skip to content

Commit edfb0cd

Browse files
Add HubDisplay component to manage event participant display and update ParticipantsPage logic
1 parent e81d650 commit edfb0cd

2 files changed

Lines changed: 66 additions & 48 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import Image from "next/image";
2+
import { useRouter } from "next/router";
3+
4+
import { useEvent } from "@/hooks/events";
5+
6+
import { Avatar, AvatarFallback } from "./avatar";
7+
import { Button } from "./button";
8+
import { Card, CardContent } from "./card";
9+
10+
export default function HubDisplay() {
11+
const router = useRouter();
12+
const { id } = router.query;
13+
const eventId = Number(id);
14+
15+
const { data: event, isLoading } = useEvent(eventId);
16+
return (
17+
<div className="mx-auto max-w-3xl px-4 sm:px-6 lg:px-0">
18+
<div className="relative mb-6 h-56 w-full overflow-hidden rounded-xl bg-gray-200">
19+
{event?.images?.[0]?.image && (
20+
<Image
21+
src={event.images[0].image}
22+
alt={event.event_name}
23+
fill
24+
className="object-cover"
25+
/>
26+
)}
27+
</div>
28+
{!isLoading && event?.participants && event.participants.length > 0 && (
29+
<div className="grid grid-cols-2 gap-4">
30+
{event.participants.map((p) => (
31+
<Card key={p.id}>
32+
<CardContent className="flex items-center gap-4 p-4">
33+
<Avatar>
34+
<AvatarFallback>
35+
{p.username.slice(0, 2).toUpperCase()}
36+
</AvatarFallback>
37+
</Avatar>
38+
39+
<div className="flex-1">
40+
<p className="font-medium">{p.username}</p>
41+
<p className="text-sm text-muted-foreground">
42+
Attending this event
43+
</p>
44+
</div>
45+
46+
<Button variant="default" size="sm">
47+
meow
48+
</Button>
49+
</CardContent>
50+
</Card>
51+
))}
52+
</div>
53+
)}
54+
</div>
55+
);
56+
}

client/src/pages/events/[id]/hub.tsx

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
import Image from "next/image";
21
import Link from "next/link";
32
import { useRouter } from "next/router";
43
import Confetti from "react-confetti";
54

6-
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
75
import { Button } from "@/components/ui/button";
8-
import { Card, CardContent } from "@/components/ui/card";
6+
import HubDisplay from "@/components/ui/hub-display";
97
import { useEvent } from "@/hooks/events";
108
import ActionLayout from "@/pages/layouts/actionlayout";
119

1210
export default function ParticipantsPage() {
1311
const router = useRouter();
1412
const { id } = router.query;
1513
const eventId = Number(id);
14+
const { data: event } = useEvent(eventId);
1615

17-
const { data: event, isLoading } = useEvent(eventId);
16+
if (!event) {
17+
return <p>Event not found</p>;
18+
}
19+
20+
const eventDate = new Date(event.event_date);
21+
const now = new Date();
22+
const hasEnded = eventDate < now;
1823

1924
return (
2025
<>
@@ -35,50 +40,7 @@ export default function ParticipantsPage() {
3540
</Link>
3641
}
3742
>
38-
<div className="mx-auto max-w-3xl px-4 sm:px-6 lg:px-0">
39-
<div className="relative mb-6 h-56 w-full overflow-hidden rounded-xl bg-gray-200">
40-
{event?.images?.[0]?.image && (
41-
<Image
42-
src={event.images[0].image}
43-
alt={event.event_name}
44-
fill
45-
className="object-cover"
46-
/>
47-
)}
48-
</div>
49-
{!isLoading &&
50-
event?.participants &&
51-
event.participants.length > 0 && (
52-
<div className="grid grid-cols-2 gap-4">
53-
{event.participants.map((p) => (
54-
<Card key={p.id}>
55-
<CardContent className="flex items-center gap-4 p-4">
56-
<Avatar>
57-
<AvatarFallback>
58-
{p.username.slice(0, 2).toUpperCase()}
59-
</AvatarFallback>
60-
</Avatar>
61-
62-
<div className="flex-1">
63-
<p className="font-medium">{p.username}</p>
64-
<p className="text-sm text-muted-foreground">
65-
Attending this event
66-
</p>
67-
</div>
68-
69-
<Button variant="default" size="sm">
70-
meow
71-
</Button>
72-
</CardContent>
73-
</Card>
74-
))}
75-
</div>
76-
)}
77-
</div>
78-
79-
{!isLoading && event?.participants?.length === 0 && (
80-
<p>No participants yet.</p>
81-
)}
43+
{hasEnded ? <HubDisplay /> : <Button>Event has ended!</Button>}
8244
</ActionLayout>
8345
</>
8446
);

0 commit comments

Comments
 (0)