Skip to content

Commit

Permalink
csv export + componentize
Browse files Browse the repository at this point in the history
Co-Authored-By: Bloxs <[email protected]>
  • Loading branch information
quick007 and Blocksnmore committed Feb 17, 2024
1 parent 7ef69c1 commit 9bc5f7d
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 177 deletions.
10 changes: 8 additions & 2 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ import * as $events_teams_filters from "./islands/events/teams/filters.tsx";
import * as $events_teams_invite from "./islands/events/teams/invite.tsx";
import * as $events_teams_manage from "./islands/events/teams/manage.tsx";
import * as $events_viewing_availability from "./islands/events/viewing/availability.tsx";
import * as $events_viewing_contact from "./islands/events/viewing/contact.tsx";
import * as $events_viewing_dates from "./islands/events/viewing/dates.tsx";
import * as $events_viewing_delete from "./islands/events/viewing/delete.tsx";
import * as $events_viewing_register from "./islands/events/viewing/register.tsx";
import * as $events_viewing_register_index from "./islands/events/viewing/register/index.tsx";
import * as $events_viewing_register_submit from "./islands/events/viewing/register/submit.tsx";
import * as $events_viewing_selectShowTime from "./islands/events/viewing/selectShowTime.tsx";
import * as $events_viewing_showtimes from "./islands/events/viewing/showtimes.tsx";
import * as $events_viewing_ticketActions from "./islands/events/viewing/ticketActions.tsx";
Expand Down Expand Up @@ -196,9 +198,13 @@ const manifest = {
"./islands/events/teams/invite.tsx": $events_teams_invite,
"./islands/events/teams/manage.tsx": $events_teams_manage,
"./islands/events/viewing/availability.tsx": $events_viewing_availability,
"./islands/events/viewing/contact.tsx": $events_viewing_contact,
"./islands/events/viewing/dates.tsx": $events_viewing_dates,
"./islands/events/viewing/delete.tsx": $events_viewing_delete,
"./islands/events/viewing/register.tsx": $events_viewing_register,
"./islands/events/viewing/register/index.tsx":
$events_viewing_register_index,
"./islands/events/viewing/register/submit.tsx":
$events_viewing_register_submit,
"./islands/events/viewing/selectShowTime.tsx":
$events_viewing_selectShowTime,
"./islands/events/viewing/showtimes.tsx": $events_viewing_showtimes,
Expand Down
16 changes: 14 additions & 2 deletions islands/components/pieces/navDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,20 @@ const NavbarDropDown = ({
>
{user.email.split("@")[0]}
</p>
<Selector class={`size-5 ml-1 hidden md:block ${(translucent && !open.value) ? "text-gray-300 group-hover:text-gray-600 " : "text-gray-600 "}`} />
<UserCircle class={`size-6 block md:hidden ${(translucent && !open.value) ? "text-gray-300 group-hover:text-gray-900 " : "text-gray-900 "}`} />
<Selector
class={`size-5 ml-1 hidden md:block transition ${
translucent && !open.value
? "text-gray-300 group-hover:text-gray-600 "
: "text-gray-600 "
}`}
/>
<UserCircle
class={`size-6 block md:hidden transition ${
translucent && !open.value
? "text-gray-300 group-hover:text-gray-900 "
: "text-gray-900 "
}`}
/>
</button>
</Dropdown>
);
Expand Down
4 changes: 2 additions & 2 deletions islands/events/editing/showtimeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const ShowtimeSelector = ({
};

return (
<div class="mt-8 mb-2 ml-auto">

<SelectShowTime
all={true}
changeOpen={changeOpen}
showTime={defaultShowTime}
showTimes={showTimes}
setShowTime={setShowTime}
/>
</div>

);
};

Expand Down
73 changes: 62 additions & 11 deletions islands/events/list/exportTicketData.tsx
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>
</>
);
}
8 changes: 4 additions & 4 deletions islands/events/list/ticketDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Dropdown from "@/islands/components/pickers/dropdown.tsx";
import DotsVertical from "$tabler/dots-vertical.tsx";
import { Ticket, Field } from "@/utils/db/kv.types.ts";
import { Field, Ticket } from "@/utils/db/kv.types.ts";

export default function TicketDropdown({
ticketID,
key,
showtime,
value,
fields,
}: {
ticketID: string;
key: string;
showtime: string;
value: Ticket;
fields: Field[];
}) {
Expand All @@ -18,7 +18,7 @@ export default function TicketDropdown({
options={[
{
content: "See Ticket",
link: `./tickets/${ticketID}?s=${key}`,
link: `./tickets/${ticketID}?s=${showtime}`,
},
{
content: "Delete Ticket",
Expand Down
55 changes: 55 additions & 0 deletions islands/events/viewing/contact.tsx
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,
)}
</>
);
};
Loading

0 comments on commit 9bc5f7d

Please sign in to comment.