-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathindex.tsx
More file actions
187 lines (177 loc) · 8.56 KB
/
Copy pathindex.tsx
File metadata and controls
187 lines (177 loc) · 8.56 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
import {Badge, Table, Text, Button, ActionIcon, Group, Tooltip, Stack} from "@mantine/core";
import {t} from "@lingui/macro";
import {AdminEvent} from "../../../api/admin.client";
import {IconChevronDown, IconChevronUp, IconEye, IconUserCheck} from "@tabler/icons-react";
import {IdParam} from "../../../types";
import tableStyles from "../../../styles/admin-table.module.scss";
interface AdminEventsTableProps {
events: AdminEvent[];
onSort?: (column: string) => void;
sortBy?: string;
sortDirection?: 'asc' | 'desc';
onViewEvent?: (event: AdminEvent) => void;
onImpersonate?: (userId: IdParam, accountId: IdParam) => void;
isImpersonating?: boolean;
}
const AdminEventsTable = ({events, onSort, sortBy, sortDirection, onViewEvent, onImpersonate, isImpersonating}: AdminEventsTableProps) => {
if (!events || events.length === 0) {
return (
<div className={tableStyles.emptyState}>
<Text size="lg" c="dimmed">{t`No events found`}</Text>
</div>
);
}
const formatDate = (dateString?: string | null) => {
if (!dateString) return '-';
const date = new Date(dateString);
return date.toLocaleDateString();
};
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(amount);
};
const formatNumber = (num: number) => {
return new Intl.NumberFormat('en-US').format(num);
};
const getStatusBadgeColor = (status: string) => {
switch (status.toUpperCase()) {
case 'LIVE':
return 'green';
case 'DRAFT':
return 'yellow';
case 'ARCHIVED':
return 'gray';
default:
return 'blue';
}
};
const handleSort = (column: string) => {
if (onSort) {
onSort(column);
}
};
const SortIcon = ({column}: {column: string}) => {
if (sortBy !== column) return null;
return sortDirection === 'asc' ? <IconChevronUp size={14} /> : <IconChevronDown size={14} />;
};
return (
<div className={tableStyles.tableWrapper}>
<div className={tableStyles.tableScroll}>
<Table className={tableStyles.table} highlightOnHover>
<Table.Thead>
<Table.Tr>
<Table.Th>
<Button
variant="subtle"
size="compact-sm"
onClick={() => handleSort('title')}
rightSection={<SortIcon column="title" />}
className={tableStyles.sortButton}
>
{t`Event Title`}
</Button>
</Table.Th>
<Table.Th>{t`Organizer`}</Table.Th>
<Table.Th>
<Button
variant="subtle"
size="compact-sm"
onClick={() => handleSort('start_date')}
rightSection={<SortIcon column="start_date" />}
className={tableStyles.sortButton}
>
{t`Start Date`}
</Button>
</Table.Th>
<Table.Th>
<Button
variant="subtle"
size="compact-sm"
onClick={() => handleSort('end_date')}
rightSection={<SortIcon column="end_date" />}
className={tableStyles.sortButton}
>
{t`End Date`}
</Button>
</Table.Th>
<Table.Th>{t`Statistics`}</Table.Th>
<Table.Th>{t`Status`}</Table.Th>
<Table.Th>{t`Actions`}</Table.Th>
</Table.Tr>
</Table.Thead>
<Table.Tbody>
{events.map((event) => (
<Table.Tr key={event.id}>
<Table.Td>
<Text fw={500}>{event.title}</Text>
</Table.Td>
<Table.Td>
<Text size="sm">{event.organizer_name}</Text>
</Table.Td>
<Table.Td>
<Text size="sm">{formatDate(event.start_date)}</Text>
</Table.Td>
<Table.Td>
<Text size="sm">{formatDate(event.end_date)}</Text>
</Table.Td>
<Table.Td>
{event.statistics ? (
<Stack gap={4}>
<Group gap={6}>
<Text size="xs" c="dimmed">{t`Sales:`}</Text>
<Text size="xs" fw={600}>{formatCurrency(event.statistics.total_gross_sales)}</Text>
</Group>
<Group gap={6}>
<Text size="xs" c="dimmed">{t`Attendees:`}</Text>
<Text size="xs" fw={500}>{formatNumber(event.statistics.attendees_registered)}</Text>
</Group>
<Group gap={6}>
<Text size="xs" c="dimmed">{t`Orders:`}</Text>
<Text size="xs" fw={500}>{formatNumber(event.statistics.orders_created)}</Text>
</Group>
</Stack>
) : (
<Text size="sm" c="dimmed">-</Text>
)}
</Table.Td>
<Table.Td>
<Badge color={getStatusBadgeColor(event.status)} variant="light">
{event.status}
</Badge>
</Table.Td>
<Table.Td>
<Group gap="xs">
<Tooltip label={t`View Event`}>
<ActionIcon
variant="subtle"
color="blue"
onClick={() => onViewEvent?.(event)}
>
<IconEye size={18} />
</ActionIcon>
</Tooltip>
<Tooltip label={t`Impersonate User`}>
<ActionIcon
variant="subtle"
color="grape"
onClick={() => onImpersonate?.(event.user_id, event.account_id)}
disabled={isImpersonating}
>
<IconUserCheck size={18} />
</ActionIcon>
</Tooltip>
</Group>
</Table.Td>
</Table.Tr>
))}
</Table.Tbody>
</Table>
</div>
</div>
);
};
export default AdminEventsTable;