Skip to content

Commit 8a0e613

Browse files
authored
Merge pull request #13966 from ethereum/migrateEventCard
Migrate EventCard to Shadcn
2 parents 6295ba4 + ffee150 commit 8a0e613

File tree

1 file changed

+39
-91
lines changed

1 file changed

+39
-91
lines changed

src/components/EventCard.tsx

Lines changed: 39 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@ import React from "react"
22
import { useRouter } from "next/router"
33
import { useTranslation } from "next-i18next"
44
import { BsCalendar3 } from "react-icons/bs"
5-
import { Box, Flex, Heading, Icon } from "@chakra-ui/react"
65

76
import type { EventCardProps } from "@/lib/types"
87

9-
import { ButtonLink } from "./Buttons"
8+
import { ButtonLink } from "@/components/ui/buttons/Button"
9+
import { Card, CardContent, CardFooter, CardHeader } from "@/components/ui/card"
10+
11+
import { cn } from "@/lib/utils/cn"
12+
1013
import { TwImage } from "./Image"
11-
import Text from "./OldText"
1214

1315
import EventFallback from "@/public/images/events/event-placeholder.png"
1416

15-
const clearStyles = {
16-
content: '""',
17-
display: "block",
18-
width: "100%",
19-
clear: "both",
20-
}
21-
22-
const EventCard = ({
17+
const EventCard: React.FC<EventCardProps> = ({
2318
title,
2419
href,
2520
description,
@@ -28,97 +23,50 @@ const EventCard = ({
2823
imageUrl,
2924
endDate,
3025
startDate,
31-
}: EventCardProps) => {
26+
}) => {
3227
const { locale } = useRouter()
3328
const { t } = useTranslation("page-community")
29+
3430
const formatedDate = new Intl.DateTimeFormat(locale, {
3531
day: "2-digit",
3632
month: "short",
3733
}).formatRange(
38-
// .replace(/-/g, "/") ==> Fixes Safari Invalid date
3934
new Date(startDate?.replace(/-/g, "/")),
4035
new Date(endDate?.replace(/-/g, "/"))
4136
)
4237

4338
return (
44-
<Box
45-
className={className}
46-
position="relative"
47-
mt="0"
48-
_before={clearStyles}
49-
_after={clearStyles}
50-
w="full"
51-
h="full"
52-
>
53-
<Flex
54-
border="1px solid"
55-
borderColor="lightBorder"
56-
height={"100%"}
57-
direction={"column"}
58-
justifyContent={"space-between"}
59-
rounded="base"
60-
>
61-
<Box>
62-
<Flex
63-
alignItems={"center"}
64-
justifyContent={"center"}
65-
background={"grayBackground"}
66-
padding={2}
67-
gap={2}
68-
borderBottom="1px solid"
69-
borderColor="primary.base"
70-
roundedTop={"4px"}
71-
>
72-
<Icon as={BsCalendar3} boxSize={6} color="primary.base" />
73-
74-
<Text color="primary.base" marginBottom={0} textAlign="end">
75-
{formatedDate}
76-
</Text>
77-
</Flex>
78-
79-
{/* TODO : add image hostname to next config or add event image to public dir */}
80-
<Flex
81-
alignItems="center"
82-
justifyContent="center"
83-
boxShadow="rgb(0 0 0 / 10%) 0px -1px 0px inset;"
84-
>
85-
{imageUrl ? (
86-
// eslint-disable-next-line @next/next/no-img-element
87-
<img
88-
src={imageUrl}
89-
alt={title}
90-
className="max-h-[224px] w-full object-cover xl:h-[124px]"
91-
/>
92-
) : (
93-
<TwImage src={EventFallback} alt="" />
94-
)}
95-
</Flex>
96-
<Box padding={4}>
97-
<Box textAlign={"center"}>
98-
<Heading
99-
as="h3"
100-
fontSize={{ base: "md", md: "2xl" }}
101-
marginTop={0}
102-
lineHeight={1.4}
103-
>
104-
{title}
105-
</Heading>
106-
<Text as="span" opacity={0.6}>
107-
{location}
108-
</Text>
109-
</Box>
110-
<Box>
111-
<Text fontSize="sm">{description}</Text>
112-
</Box>
113-
</Box>
114-
</Box>
115-
<Box padding={4} paddingTop={0} width={"100%"}>
116-
<ButtonLink href={href} width={"100%"} variant="outline">
117-
{t("page-community-upcoming-events-view-event")}
118-
</ButtonLink>
119-
</Box>
120-
</Flex>
121-
</Box>
39+
<Card className={cn("flex h-full flex-col rounded-md border", className)}>
40+
<CardHeader className="flex flex-row items-center justify-center rounded-t-md border-b border-primary bg-[#FCFCFC] p-2 dark:bg-[#272627]">
41+
<BsCalendar3 className="mr-2 h-6 w-6 text-primary" />
42+
<span className="!mt-0 text-right text-sm text-primary">
43+
{formatedDate}
44+
</span>
45+
</CardHeader>
46+
<div className="flex items-center justify-center">
47+
{imageUrl ? (
48+
<img
49+
src={imageUrl}
50+
alt={title}
51+
className="max-h-[224px] w-full object-cover xl:h-[124px]"
52+
/>
53+
) : (
54+
<TwImage src={EventFallback} alt="" />
55+
)}
56+
</div>
57+
<CardContent className="flex-grow p-4">
58+
<div className="text-center">
59+
<h3 className="text-xl font-bold md:text-2xl">{title}</h3>
60+
<span className="text-sm opacity-60">{location}</span>
61+
</div>
62+
<p className="md:text-sm md:leading-[1.6rem]">{description}</p>
63+
</CardContent>
64+
<CardFooter className="p-4 pt-0">
65+
<ButtonLink href={href} variant="outline" className="w-full text-sm">
66+
{t("page-community-upcoming-events-view-event")}
67+
</ButtonLink>
68+
</CardFooter>
69+
</Card>
12270
)
12371
}
12472

0 commit comments

Comments
 (0)