-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Bloxs <[email protected]>
- Loading branch information
1 parent
7ef69c1
commit 9bc5f7d
Showing
13 changed files
with
290 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,82 @@ | ||
import { Field, Ticket } from "@/utils/db/kv.types.ts"; | ||
import { Field, ShowTime, Ticket } from "@/utils/db/kv.types.ts"; | ||
import { fmtDate, fmtHour } from "@/utils/dates.ts"; | ||
|
||
export default function ExportTicketData({ | ||
tickets, | ||
fields, | ||
showTimes, | ||
selectedShowTime | ||
}: { | ||
tickets: [string, Ticket][]; | ||
// showtimeID, ticketID, ticket | ||
tickets: [string, string, Ticket][]; | ||
fields: Field[]; | ||
showTimes: ShowTime[]; | ||
selectedShowTime: string | ||
}) { | ||
const exportTickets = (showtime?: string) => { | ||
const filteredTickets = tickets.filter(([showtimeID]) => | ||
showtime == undefined || showtimeID === showtime | ||
const filteredTickets = tickets.filter( | ||
([showtimeID]) => showtime == undefined || showtimeID === showtime, | ||
); | ||
|
||
// Use “ in replacement for " to avoid breaking csv | ||
|
||
const data = [ | ||
`"Showtime ID","Ticket ID","Email","Last Name","First Name","Acquired Tickets","Ticket Uses"${ | ||
fields.length > 0 | ||
? `,"${fields.map((f) => `"${f.name.replace(/"/g, "“")}"`).join(",")}` | ||
: "" | ||
}`, | ||
]; | ||
[ | ||
"Showtime", | ||
"Ticket ID", | ||
"Email", | ||
"Last Name", | ||
"First Name", | ||
"Acquired Tickets", | ||
"Ticket Uses", | ||
...fields.map((f) => `${f.name} (${f.id})`), | ||
] | ||
.map((v) => `"${v.replace(/"/g, "“")}"`) | ||
.join(","), | ||
...filteredTickets.map(([showtimeID, ticketID, ticket]) => { | ||
const showtime = showTimes.find((st) => st.id === showtimeID)!; | ||
|
||
const showtimeDateFormatted = `${fmtDate( | ||
new Date(showtime.startDate), | ||
)} ${ | ||
showtime.startTime | ||
? `at ${fmtHour(new Date(showtime.startTime)).toLowerCase()}` | ||
: "" | ||
}`.trim(); | ||
|
||
return [ | ||
`${showtimeDateFormatted} (${showtimeID})`, | ||
ticketID, | ||
ticket.userEmail, | ||
ticket.lastName, | ||
ticket.firstName, | ||
ticket.tickets, | ||
ticket.uses, | ||
...fields.map((f) => { | ||
const data = ticket.fieldData.find((fd) => fd.id === f.id)?.value; | ||
|
||
return data ?? "null"; | ||
}), | ||
] | ||
.map((v) => `"${v.toString().replace(/"/g, "“")}"`) | ||
.join(","); | ||
}), | ||
].join("\n"); | ||
|
||
return data; | ||
}; | ||
|
||
return ( | ||
<> | ||
<button type="button">Exeporte zee tix</button> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
console.log(exportTickets(selectedShowTime == "0" ? undefined : selectedShowTime)); | ||
}} | ||
class="rounded-md bg-gray-200 h-8 grid place-content-center px-2 font-medium hover:brightness-95 transition" | ||
> | ||
.csv Export | ||
</button> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useSignal } from "@preact/signals"; | ||
import { createPortal } from "preact/compat"; | ||
import { useState } from "preact/hooks"; | ||
import Popup from "@/components/popup.tsx"; | ||
|
||
export const Contact = ({ email }: { email: string }) => { | ||
const [open, setOpen] = useState(false); | ||
const checked = useSignal(false); | ||
return ( | ||
<> | ||
<button | ||
className="flex items-center select-none font-medium hover:bg-gray-200/75 hover:text-gray-900 transition text-sm mt-4 rounded-md bg-white/25 backdrop-blur-xl border px-1.5 py-0.5" | ||
onClick={() => setOpen(true)} | ||
> | ||
Contact Organizer | ||
</button> | ||
{globalThis.document != undefined && | ||
createPortal( | ||
<Popup | ||
isOpen={open} | ||
close={() => { | ||
setOpen(false); | ||
checked.value = false; | ||
}} | ||
> | ||
<h2 class="font-bold text-lg">Contact Organizer</h2> | ||
<label class="flex mt-4 items-start cursor-pointer"> | ||
<input | ||
type="checkbox" | ||
name="agreed" | ||
class="mr-4 mt-1.5" | ||
onClick={(e) => (checked.value = e.currentTarget.checked)} | ||
/> | ||
<p> | ||
I agree to interacting with this email in a professional way and | ||
following our guidelines as outlined in our{" "} | ||
<a href="/terms-of-service" class="font-medium underline"> | ||
terms and conditions | ||
</a> | ||
</p> | ||
</label> | ||
{checked.value && ( | ||
<p class="mt-6"> | ||
Organizer contact email:{" "} | ||
<a href={`mailto:${email}`} class="font-medium underline"> | ||
{email} | ||
</a> | ||
</p> | ||
)} | ||
</Popup>, | ||
document.body, | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.