-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventCardView.tsx
More file actions
101 lines (93 loc) ยท 2.83 KB
/
EventCardView.tsx
File metadata and controls
101 lines (93 loc) ยท 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemGroup,
ItemMedia,
ItemTitle,
} from '@/components/ui/item';
import type { Events } from '@/types/schema';
import { getShortenedDate } from '@/utils/date';
import { ChevronRightIcon, Plus } from 'lucide-react';
import { Link } from 'react-router';
import { Button } from './ui/button';
type Event = Events & { guests: number; registration_start: string | null };
function getDateLabel(
startDateString: string | null,
endDateString: string | null
) {
if (!endDateString) {
return '์์ ๋ชจ์ง ์ค';
}
const now = new Date();
const endDate = new Date(endDateString!);
if (startDateString && now < new Date(startDateString)) {
return `${getShortenedDate(startDateString)}๋ถํฐ ๋ชจ์ง`;
}
if (now <= endDate) {
return `${getShortenedDate(endDateString)}๊น์ง ๋ชจ์ง`;
}
return '๋ชจ์ง ๋ง๊ฐ';
}
export default function EventCardView({ events }: { events: Event[] }) {
if (events.length === 0) {
return (
<div className="flex-1 flex items-center justify-center">
<div className="flex w-full max-w-md flex-col gap-8 items-center">
<div className="flex flex-col gap-4 text-center">
<h1 className="text-2xl font-bold">๊ฐ์คํ ์ผ์ ์ด ์๋ค์!</h1>
<h2 className="text-base font-base">
์ฌ๋๋ค๊ณผ ์๋ก์ด ์ผ์ ์ ์ก์ ๋ณผ๊น์?
</h2>
</div>
<Link to="/new-event">
<Button className="text-lg font-bold px-20 py-5">
์๋ก์ด ์ผ์ ๋ง๋ค๊ธฐ
</Button>
</Link>
</div>
</div>
);
}
return (
<ItemGroup className="gap-4">
<Item variant="default" asChild role="listitem">
<Link to="/new-event">
<ItemMedia variant="icon">
<Plus />
</ItemMedia>
<ItemContent>
<ItemTitle>
<h2 className="text-lg font-semibold line-clamp-1">
์๋ก์ด ์ผ์ ๋ง๋ค๊ธฐ
</h2>
</ItemTitle>
</ItemContent>
</Link>
</Item>
{events.map((event) => (
<Item key={event.id} variant="outline" asChild role="listitem">
<Link to={`/event/${event.id}`}>
<ItemContent>
<ItemTitle>
<h2 className="text-lg font-semibold line-clamp-1">
{event.title}
</h2>
</ItemTitle>
<ItemDescription>
{getDateLabel(
event.registration_start,
event.registration_deadline
)}
</ItemDescription>
</ItemContent>
<ItemActions>
<ChevronRightIcon className="size-4" />
</ItemActions>
</Link>
</Item>
))}
</ItemGroup>
);
}