-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventCalendarTemplate.tsx
More file actions
124 lines (114 loc) · 3.15 KB
/
Copy pathEventCalendarTemplate.tsx
File metadata and controls
124 lines (114 loc) · 3.15 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { useSelector } from 'react-redux';
import Card from '@kitconcept/volto-light-theme/primitives/Card/Card';
import DefaultSummary from '@kitconcept/volto-light-theme/components/Summary/DefaultSummary';
import cx from 'classnames';
type IntlType = {
intl: {
locale: string;
};
};
const EventItem = ({
item,
lang,
isEditMode,
}: {
item: any;
lang: string;
isEditMode: boolean;
}) => {
const formatter = new Intl.DateTimeFormat(lang, {
year: 'numeric',
month: 'short',
});
const headFormatter = new Intl.DateTimeFormat(lang, {
day: 'numeric',
year: 'numeric',
month: 'long',
});
const itemDates = (item: any) => {
const start =
item['@type'] === 'Event'
? item.start
? new Date(item.start)
: null
: item.Effective
? new Date(item.Effective)
: new Date(item.CreationDate);
const end =
item['@type'] === 'Event' && (item.end ? new Date(item.end) : null);
const notSameDay = end && start?.getDate() !== end?.getDate();
const formattedStartDate = start ? formatter.format(start) : '';
const formattedEndDate = end ? formatter.format(end) : '';
const formattedHeaderDate = !end
? start
? headFormatter.format(start)
: ''
: start && end
? headFormatter.formatRange(start, end)
: '';
return {
start,
end,
formattedStartDate,
formattedEndDate,
formattedHeaderDate,
notSameDay,
};
};
const {
start,
end,
formattedHeaderDate,
notSameDay,
formattedStartDate,
formattedEndDate,
} = itemDates(item);
return (
<div className="card-listing">
<Card href={isEditMode ? '' : item['@id']} className="event-card">
<Card.Image>
<div className={cx('date-inset', { 'has-end-date': notSameDay })}>
<div className="day">
{start && String(start?.getDate()).padStart(2, '0')}
</div>
<div className="month">{formattedStartDate}</div>
{notSameDay && (
<>
<div className="separator"></div>
<div className="day">
{end && String(end?.getDate()).padStart(2, '0')}
</div>
<div className="month">{formattedEndDate}</div>
</>
)}
</div>
</Card.Image>
<Card.Summary>
<div className="headline calendar">
<span className="day">{formattedHeaderDate}</span>
{item.head_title && (
<span className="event-title">{item.head_title}</span>
)}
</div>
<DefaultSummary item={item} HeadingTag="h2" />
</Card.Summary>
</Card>
</div>
);
};
const EventCalendarTemplate = (props: any) => {
const lang = useSelector((state: IntlType) => state.intl.locale);
return (
<div className="event-calendar items">
{props.items.map((item: any, index: number) => (
<EventItem
key={index}
item={item}
lang={lang}
isEditMode={props.isEditMode}
/>
))}
</div>
);
};
export default EventCalendarTemplate;