Skip to content

Commit c22b353

Browse files
authored
add button to copy emails from view ticketing page (#115)
1 parent adf04fb commit c22b353

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

src/ui/pages/tickets/ViewTickets.page.tsx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const getTicketStatus = (
4545
return { status: 'unfulfilled', color: 'orange' };
4646
};
4747

48+
enum TicketsCopyMode {
49+
ALL,
50+
FULFILLED,
51+
UNFULFILLED,
52+
}
53+
4854
const ViewTicketsPage: React.FC = () => {
4955
const { eventId } = useParams();
5056
const [allTickets, setAllTickets] = useState<TicketEntry[]>([]);
@@ -57,6 +63,38 @@ const ViewTicketsPage: React.FC = () => {
5763
const [pageSize, setPageSize] = useState<string>('10');
5864
const pageSizeOptions = ['10', '25', '50', '100'];
5965

66+
const copyEmails = (mode: TicketsCopyMode) => {
67+
try {
68+
let emailsToCopy: string[] = [];
69+
let copyModeHumanString = '';
70+
switch (mode) {
71+
case TicketsCopyMode.ALL:
72+
emailsToCopy = allTickets.map((x) => x.purchaserData.email);
73+
copyModeHumanString = 'All';
74+
break;
75+
case TicketsCopyMode.FULFILLED:
76+
emailsToCopy = allTickets.filter((x) => x.fulfilled).map((x) => x.purchaserData.email);
77+
copyModeHumanString = 'Fulfilled';
78+
break;
79+
case TicketsCopyMode.UNFULFILLED:
80+
emailsToCopy = allTickets.filter((x) => !x.fulfilled).map((x) => x.purchaserData.email);
81+
copyModeHumanString = 'Unfulfilled';
82+
break;
83+
}
84+
emailsToCopy = [...new Set(emailsToCopy)];
85+
navigator.clipboard.writeText(emailsToCopy.join(';'));
86+
notifications.show({
87+
message: `${copyModeHumanString} emails copied!`,
88+
});
89+
} catch (e) {
90+
notifications.show({
91+
title: 'Failed to copy emails',
92+
message: 'Please try again or contact support.',
93+
color: 'red',
94+
});
95+
}
96+
};
97+
6098
async function checkInUser(ticket: TicketEntry) {
6199
try {
62100
const response = await api.post(`/api/v1/tickets/checkIn`, {
@@ -119,8 +157,30 @@ const ViewTicketsPage: React.FC = () => {
119157
return (
120158
<AuthGuard resourceDef={{ service: 'core', validRoles: [AppRoles.TICKETS_MANAGER] }}>
121159
<Title order={2}>View Tickets/Merch Sales</Title>
160+
<Group mt="md" mb="md">
161+
<Button
162+
onClick={() => {
163+
copyEmails(TicketsCopyMode.ALL);
164+
}}
165+
>
166+
Copy All Emails
167+
</Button>
168+
<Button
169+
onClick={() => {
170+
copyEmails(TicketsCopyMode.FULFILLED);
171+
}}
172+
>
173+
Copy Fulfilled Emails
174+
</Button>
175+
<Button
176+
onClick={() => {
177+
copyEmails(TicketsCopyMode.UNFULFILLED);
178+
}}
179+
>
180+
Copy Unfulfilled Emails
181+
</Button>
182+
</Group>
122183
<div>
123-
<br />
124184
<Title order={4}>{pluralize('item', totalQuantitySold, true)} sold</Title>
125185
<Table>
126186
<Table.Thead>

0 commit comments

Comments
 (0)