-
-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathindex.tsx
More file actions
411 lines (378 loc) · 19.9 KB
/
Copy pathindex.tsx
File metadata and controls
411 lines (378 loc) · 19.9 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import {ActionIcon, Tooltip} from '@mantine/core';
import {Event, EventType, IdParam, LocationType, Product} from "../../../types.ts";
import classes from "./EventCard.module.scss";
import {NavLink, useNavigate} from "react-router";
import {
IconArchive,
IconCopy,
IconDotsVertical,
IconEye,
IconRepeat,
IconSettings,
} from "@tabler/icons-react";
import {t} from "@lingui/macro"
import {eventHomepagePath} from "../../../utilites/urlHelper.ts";
import {useDisclosure} from "@mantine/hooks";
import {DuplicateEventModal} from "../../modals/DuplicateEventModal";
import {useState} from "react";
import {ActionMenu, ActionMenuItemsGroup} from '../ActionMenu';
import {confirmationDialog} from "../../../utilites/confirmationDialog.tsx";
import {showError, showSuccess} from "../../../utilites/notifications.tsx";
import {useUpdateEventStatus} from "../../../mutations/useUpdateEventStatus.ts";
import {formatCurrency} from "../../../utilites/currency.ts";
import {formatNumber} from "../../../utilites/helpers.ts";
import {formatDateWithLocale, isValidDate, relativeDate} from "../../../utilites/dates.ts";
import {Card} from "../Card";
import {resolveEventLocation} from "../../../utilites/effectiveLocation.ts";
import {formatAddress} from "../../../utilites/addressUtilities.ts";
const placeholderGradients = [
'linear-gradient(135deg, var(--mantine-color-violet-5) 0%, var(--mantine-color-indigo-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-pink-5) 0%, var(--mantine-color-grape-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-blue-5) 0%, var(--mantine-color-cyan-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-teal-5) 0%, var(--mantine-color-green-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-orange-5) 0%, var(--mantine-color-yellow-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-indigo-5) 0%, var(--mantine-color-blue-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-grape-5) 0%, var(--mantine-color-violet-5) 100%)',
'linear-gradient(135deg, var(--mantine-color-cyan-5) 0%, var(--mantine-color-teal-5) 100%)',
];
interface EventCardProps {
event: Event;
compact?: boolean;
}
export function EventCard({event, compact = false}: EventCardProps) {
const navigate = useNavigate();
const [isDuplicateModalOpen, duplicateModal] = useDisclosure(false);
const [eventId, setEventId] = useState<IdParam>();
const statusToggleMutation = useUpdateEventStatus();
const coverImage = event.images?.find(img => img.type === 'EVENT_COVER');
const gradientIndex = event.id ? Number(event.id) % placeholderGradients.length : 0;
const placeholderGradient = placeholderGradients[gradientIndex];
const handleDuplicate = () => {
setEventId(event.id);
duplicateModal.open();
}
const handleStatusToggle = () => {
const message = event?.status !== 'ARCHIVED'
? t`Are you sure you want to archive this event?`
: t`Are you sure you want to restore this event? It will be restored as a draft event.`;
confirmationDialog(message, () => {
statusToggleMutation.mutate({
eventId: event.id,
status: event?.status === 'ARCHIVED' ? 'DRAFT' : 'ARCHIVED'
}, {
onSuccess: () => {
showSuccess(t`Event status updated`);
},
onError: (error: any) => {
showError(error?.response?.data?.message || t`Event status update failed. Please try again later`);
}
});
})
}
const getStatusConfig = () => {
if (event.status === 'ARCHIVED') {
return {label: t`Archived`, status: 'archived', tone: 'muted'};
}
if (event.lifecycle_status === 'ENDED') {
return {label: t`Ended`, status: 'ended', tone: 'muted'};
}
if (event.status === 'DRAFT') {
return {label: t`Draft`, status: 'draft', tone: 'warning'};
}
if (event.lifecycle_status === 'ONGOING') {
return {label: t`Live`, status: 'live', tone: 'success', pulse: true};
}
return {label: t`On Sale`, status: 'onsale', tone: 'success'};
};
const getLocationText = () => {
const occurrences = event.occurrences ?? [];
const resolvedList = occurrences.length > 0
? occurrences.map(o => resolveEventLocation(event, o))
: [resolveEventLocation(event, null)];
const types = new Set<string>();
const locationIds = new Set<string>();
for (const r of resolvedList) {
if (r) {
types.add(r.type);
if (r.location_id != null) locationIds.add(String(r.location_id));
}
}
const first = resolvedList[0];
if (!first) return null;
if (types.size > 1) return t`Online & in-person`;
if (first.type === LocationType.Online) return t`Online`;
if (locationIds.size > 1) return t`Multiple locations`;
if (first.type !== LocationType.InPerson) return null;
const city = first.location?.structured_address?.city;
const venueName = first.location?.name || first.location?.structured_address?.venue_name;
const formatted = first.location?.structured_address ? formatAddress(first.location.structured_address) : '';
return venueName ?? city ?? (formatted ? formatted : null);
};
const getTicketAvailability = () => {
const products = event.products;
if (!products || products.length === 0) return null;
const ticketProducts = products.filter((p: Product) => p.product_type === 'TICKET');
if (ticketProducts.length === 0) return null;
const availableCount = ticketProducts.filter((p: Product) => {
if (p.status === 'INACTIVE') return false;
return p.is_available !== false && p.is_sold_out !== true;
}).length;
const totalCount = ticketProducts.length;
if (availableCount === 0) {
return {text: t`Sold out`, status: 'sold-out'};
}
if (availableCount === totalCount) {
return {
text: totalCount === 1 ? t`1 ticket type` : t`${totalCount} ticket types`,
status: 'available'
};
}
return {text: t`${availableCount} of ${totalCount} available`, status: 'partial'};
};
const menuItems: ActionMenuItemsGroup[] = [
{
label: '',
items: [
{
label: t`View event page`,
icon: <IconEye size={14}/>,
onClick: () => window.location.href = eventHomepagePath(event),
},
{
label: t`Manage event`,
icon: <IconSettings size={14}/>,
onClick: () => navigate(`/manage/event/${event.id}`),
},
{
label: t`Duplicate event`,
icon: <IconCopy size={14}/>,
onClick: handleDuplicate,
},
{
label: event?.status === 'ARCHIVED' ? t`Restore event` : t`Archive event`,
icon: <IconArchive size={14}/>,
onClick: handleStatusToggle,
},
],
},
];
const locationText = getLocationText();
const revenue = event?.statistics?.sales_total_gross || 0;
const attendees = event?.statistics?.attendees_registered || 0;
const statusConfig = getStatusConfig();
const ticketAvailability = getTicketAvailability();
const isEnded = event.lifecycle_status === 'ENDED';
const isDraft = event.status === 'DRAFT';
const isRecurring = event.type === EventType.RECURRING;
const displayDate = (isRecurring && event.next_occurrence_start_date) || event.start_date;
const hasDate = isValidDate(displayDate);
const monthShort = formatDateWithLocale(displayDate, 'monthShort', event.timezone);
const dayOfMonth = formatDateWithLocale(displayDate, 'dayOfMonth', event.timezone);
const shortDateTime = formatDateWithLocale(displayDate, 'shortDateTime', event.timezone);
const relativeDateStr = relativeDate(displayDate);
if (compact) {
return (
<>
<div className={`${classes.eventCardCompact} ${isEnded ? classes.isEnded : ''} ${isDraft ? classes.isDraft : ''}`}>
<NavLink to={`/manage/event/${event.id}/dashboard`} className={classes.cardLinkCompact}>
<div className={classes.compactThumb}>
<div
className={`${classes.compactImage} ${!coverImage ? classes.placeholderImage : ''}`}
style={coverImage
? {backgroundImage: `url(${coverImage.url})`}
: {background: placeholderGradient}
}
/>
{hasDate && (
<div className={`${classes.compactDateBadge}`}>
<span className={classes.compactDateDay}>{dayOfMonth}</span>
<span className={classes.compactDateMonth}>{monthShort}</span>
</div>
)}
</div>
<div className={classes.compactContent}>
<div className={classes.compactPrimary}>
<span className={classes.compactTitle}>{event.title}</span>
{isRecurring && (
<span className={classes.compactRecurringIcon} aria-label={t`Recurring`}>
<IconRepeat size={12}/>
</span>
)}
</div>
<div className={classes.compactMeta}>
<span className={`${classes.compactStatus} ${classes[`compactStatus-${statusConfig.tone}`]}`}>
{statusConfig.pulse && <span className={classes.compactStatusDot}/>}
{statusConfig.label}
</span>
<span className={classes.compactDot}>·</span>
<span className={classes.compactMetaItem}>
{hasDate ? shortDateTime : t`No date added`}
</span>
{hasDate && (
<>
<span className={classes.compactDot}>·</span>
<span className={classes.compactMetaItem}>{relativeDateStr}</span>
</>
)}
{locationText && (
<>
<span className={classes.compactDot}>·</span>
<span className={`${classes.compactMetaItem} ${classes.compactLocation}`}>
{locationText}
</span>
</>
)}
{ticketAvailability && (
<>
<span className={classes.compactDot}>·</span>
<span className={`${classes.compactTickets} ${classes[`compactTickets-${ticketAvailability.status}`]}`}>
{ticketAvailability.text}
</span>
</>
)}
</div>
</div>
<div className={classes.compactStats}>
<div className={classes.compactStat}>
<span className={classes.compactStatValue}>{formatNumber(attendees)}</span>
<span className={classes.compactStatLabel}>{t`Attendees`}</span>
</div>
<div className={classes.compactStat}>
<span className={classes.compactStatValue}>{formatCurrency(revenue, event?.currency)}</span>
<span className={classes.compactStatLabel}>{t`Revenue`}</span>
</div>
</div>
<div className={classes.compactMenuButton} onClick={(e) => e.preventDefault()}>
<ActionMenu
itemsGroups={menuItems}
target={
<ActionIcon
className={classes.actionButton}
size="sm"
variant="subtle"
>
<IconDotsVertical size={16}/>
</ActionIcon>
}
/>
</div>
</NavLink>
</div>
{isDuplicateModalOpen && <DuplicateEventModal eventId={eventId} onClose={duplicateModal.close}/>}
</>
);
}
return (
<>
<Card className={`${classes.eventCard} ${isEnded ? classes.isEnded : ''} ${isDraft ? classes.isDraft : ''}`}>
<NavLink to={`/manage/event/${event.id}/dashboard`} className={classes.cardLink}>
<div className={classes.imageContainer}>
<div
className={`${classes.image} ${!coverImage ? classes.placeholderImage : ''}`}
style={coverImage
? {backgroundImage: `url(${coverImage.url})`}
: {background: placeholderGradient}
}
/>
<div className={`${classes.imageOverlay} ${!coverImage ? classes.placeholderOverlay : ''}`}/>
<div className={`${classes.statusBadge} ${classes[`status-${statusConfig.status}`]}`}>
{statusConfig.pulse && <span className={classes.pulseDot}/>}
{statusConfig.label}
</div>
{hasDate && (
<div className={classes.dateBadge}>
<span className={classes.dateDay}>{dayOfMonth}</span>
<span className={classes.dateMonth}>{monthShort}</span>
</div>
)}
{isRecurring && (
<div className={classes.recurringBadge}>
<IconRepeat size={12}/>
</div>
)}
</div>
<div className={classes.content}>
<div className={classes.contentMain}>
<h3 className={classes.title}>{event.title}</h3>
<div className={classes.meta}>
<span className={classes.eventDate}>
{hasDate ? shortDateTime : t`No date added`}
{isRecurring && (
<span className={classes.recurringLabel}>
<IconRepeat size={11}/>
{t`Recurring`}
</span>
)}
</span>
{hasDate && <span className={classes.relativeDate}>({relativeDateStr})</span>}
{locationText && (
<>
<span className={classes.separator}>·</span>
<span className={classes.location}>{locationText}</span>
</>
)}
</div>
<div className={classes.footer}>
<span
role="link"
tabIndex={0}
className={classes.organizer}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
navigate(`/manage/organizer/${event?.organizer?.id}`);
}}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
e.stopPropagation();
navigate(`/manage/organizer/${event?.organizer?.id}`);
}
}}
>
{event?.organizer?.name}
</span>
{ticketAvailability && (
<span className={`${classes.ticketStatus} ${classes[`ticket-${ticketAvailability.status}`]}`}>
{ticketAvailability.text}
</span>
)}
</div>
</div>
<div className={classes.statsPanel}>
<Tooltip label={t`Attendees registered`} withArrow position="top">
<div className={classes.stat}>
<span className={classes.statValue}>{formatNumber(attendees)}</span>
<span className={classes.statLabel}>{t`Attendees`}</span>
</div>
</Tooltip>
<Tooltip label={t`Gross revenue`} withArrow position="top">
<div className={classes.stat}>
<span className={classes.statValueRevenue}>
{formatCurrency(revenue, event?.currency)}
</span>
<span className={classes.statLabel}>{t`Revenue`}</span>
</div>
</Tooltip>
</div>
<div className={classes.menuButton} onClick={(e) => e.preventDefault()}>
<ActionMenu
itemsGroups={menuItems}
target={
<ActionIcon
className={classes.actionButton}
size="md"
variant="subtle"
>
<IconDotsVertical size={18}/>
</ActionIcon>
}
/>
</div>
</div>
</NavLink>
</Card>
{isDuplicateModalOpen && <DuplicateEventModal eventId={eventId} onClose={duplicateModal.close}/>}
</>
);
}