1
1
import React from "react"
2
- import { Box , Heading } from "@chakra-ui/react"
2
+ import { useRouter } from "next/router"
3
+ import { useTranslation } from "react-i18next"
4
+ import { BsCalendar3 } from "react-icons/bs"
5
+ import { Box , Flex , Heading , Icon } from "@chakra-ui/react"
6
+ import { Image } from "@chakra-ui/react"
3
7
4
8
import { ButtonLink } from "./Buttons"
5
- import Emoji from "./Emoji"
6
9
import Text from "./OldText"
7
10
8
11
const clearStyles = {
@@ -16,87 +19,113 @@ export type EventCardProps = {
16
19
title : string
17
20
href : string
18
21
date : string
22
+ startDate : string
23
+ endDate : string
19
24
description : string
20
25
className ?: string
21
26
location : string
22
- isEven : boolean
27
+ imageUrl ?: string
23
28
}
24
29
25
30
const EventCard = ( {
26
31
title,
27
32
href,
28
- date,
29
33
description,
30
34
className,
31
35
location,
32
- isEven,
33
- } : EventCardProps ) => (
34
- < Box
35
- className = { className }
36
- position = "relative"
37
- marginTop = { { base : "30px" , md : 0 } }
38
- _before = { clearStyles }
39
- _after = { clearStyles }
40
- >
41
- < Box
42
- w = "24px"
43
- h = "24px"
44
- position = "absolute"
45
- top = "0"
46
- insetInlineStart = "50%"
47
- overflow = "hidden"
48
- ms = "-12px"
49
- backgroundColor = "primary.base"
50
- display = { { base : "none" , md : "block" } }
51
- />
36
+ imageUrl,
37
+ endDate,
38
+ startDate,
39
+ } : EventCardProps ) => {
40
+ const { locale } = useRouter ( )
41
+ const { t } = useTranslation ( "page-community" )
42
+ const formatedDate = new Intl . DateTimeFormat ( locale , {
43
+ day : "2-digit" ,
44
+ month : "short" ,
45
+ } ) . formatRange (
46
+ // .replace(/-/g, "/") ==> Fixes Safari Invalid date
47
+ new Date ( startDate ?. replace ( / - / g, "/" ) ) ,
48
+ new Date ( endDate ?. replace ( / - / g, "/" ) )
49
+ )
50
+
51
+ return (
52
52
< Box
53
- width = { { base : "100%" , md : "45%" } }
54
- padding = { 6 }
55
- backgroundColor = "ednBackground"
56
- borderRadius = "sm"
57
- border = "1px solid"
58
- borderColor = "lightBorder"
59
- float = { isEven ? "inline-end" : { base : "inline-end" , md : "none" } }
60
- marginTop = { isEven ? { base : 0 , md : "-25%" } : 0 }
61
- _before = { {
62
- content : '""' ,
63
- position : "absolute" ,
64
- top : "10px" ,
65
- width : 0 ,
66
- height : "3px" ,
67
- display : { base : "none" , md : "inline" } ,
68
- ...( isEven
69
- ? {
70
- insetInlineStart : "inherit" ,
71
- insetInlineEnd : "45%" ,
72
- borderInlineStart : 0 ,
73
- borderInlineEnd : "25px solid" ,
74
- }
75
- : {
76
- insetInlineStart : "45%" ,
77
- borderInlineStart : "25px solid" ,
78
- borderInlineEnd : 0 ,
79
- } ) ,
80
- borderColor : "primary.base" ,
81
- } }
53
+ className = { className }
54
+ position = "relative"
55
+ mt = "0"
56
+ _before = { clearStyles }
57
+ _after = { clearStyles }
58
+ w = "full"
59
+ h = "full"
82
60
>
83
- < Text color = "primary.base" marginBottom = { 0 } textAlign = "end" >
84
- { date }
85
- < Emoji text = ":spiral_calendar:" fontSize = "md" ms = { 2 } />
86
- </ Text >
87
- < Text marginBottom = { 0 } textAlign = "end" >
88
- < Text as = "span" opacity = { 0.6 } >
89
- { location }
90
- </ Text >
91
- < Emoji text = ":round_pushpin:" fontSize = "md" ms = { 2 } />
92
- </ Text >
93
- < Heading as = "h3" marginTop = { 0 } fontWeight = "semibold" lineHeight = { 1.4 } >
94
- { title }
95
- </ Heading >
96
- < Text > { description } </ Text >
97
- < ButtonLink href = { href } > View Event</ ButtonLink >
61
+ < Flex
62
+ border = "1px solid"
63
+ borderColor = "lightBorder"
64
+ height = { "100%" }
65
+ direction = { "column" }
66
+ justifyContent = { "space-between" }
67
+ rounded = "base"
68
+ >
69
+ < Box >
70
+ < Flex
71
+ alignItems = { "center" }
72
+ justifyContent = { "center" }
73
+ background = { "grayBackground" }
74
+ padding = { 2 }
75
+ gap = { 2 }
76
+ borderBottom = "1px solid"
77
+ borderColor = "primary.base"
78
+ roundedTop = { "4px" }
79
+ >
80
+ < Icon as = { BsCalendar3 } boxSize = { 6 } color = "primary.base" />
81
+
82
+ < Text color = "primary.base" marginBottom = { 0 } textAlign = "end" >
83
+ { formatedDate }
84
+ </ Text >
85
+ </ Flex >
86
+
87
+ { /* TODO : add image hostname to next config or add event image to public dir */ }
88
+ < Flex
89
+ alignItems = "center"
90
+ justifyContent = "center"
91
+ boxShadow = "rgb(0 0 0 / 10%) 0px -1px 0px inset;"
92
+ >
93
+ < Image
94
+ src = { imageUrl || "/images/events/event-placeholder.png" }
95
+ alt = { title }
96
+ w = "full"
97
+ height = { { base : "224px" , xl : "124px" } }
98
+ objectFit = { "cover" }
99
+ fallbackSrc = "/images/events/event-placeholder.png"
100
+ />
101
+ </ Flex >
102
+ < Box padding = { 4 } >
103
+ < Box textAlign = { "center" } >
104
+ < Heading
105
+ as = "h3"
106
+ fontSize = { { base : "md" , md : "2xl" } }
107
+ marginTop = { 0 }
108
+ lineHeight = { 1.4 }
109
+ >
110
+ { title }
111
+ </ Heading >
112
+ < Text as = "span" opacity = { 0.6 } >
113
+ { location }
114
+ </ Text >
115
+ </ Box >
116
+ < Box >
117
+ < Text fontSize = "sm" > { description } </ Text >
118
+ </ Box >
119
+ </ Box >
120
+ </ Box >
121
+ < Box padding = { 4 } paddingTop = { 0 } width = { "100%" } >
122
+ < ButtonLink href = { href } width = { "100%" } variant = "outline" >
123
+ { t ( "page-community-upcoming-events-view-event" ) }
124
+ </ ButtonLink >
125
+ </ Box >
126
+ </ Flex >
98
127
</ Box >
99
- </ Box >
100
- )
128
+ )
129
+ }
101
130
102
131
export default EventCard
0 commit comments