Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
SheetTitle,
} from "@/components/ui/sheet";
import Image from "next/image";
import { PaymentMethodIcon } from "@/components/custom/PaymentMethodIcon";
import { ReferrersModal } from "./ReferrersModal";
import {
formatCapacityIssueMessage,
Expand All @@ -72,46 +73,6 @@ const paymentMethodLabels: Record<PaymentMethod, string> = {
OTHER: "Cash In-Person",
};

function PaymentMethodIcon({ method }: { method: PaymentMethod }) {
if (method === "VENMO") {
return (
<svg
className="h-7 w-7"
xmlns="http://www.w3.org/2000/svg"
aria-label="Venmo"
role="img"
viewBox="0 0 512 512"
>
<rect width="512" height="512" rx="15%" fill="#008CFF" />
<path
d="m381.4 105.3c11 18.1 15.9 36.7 15.9 60.3 0 75.1-64.1 172.7-116.2 241.2h-118.8l-47.6-285 104.1-9.9 25.3 202.8c23.5-38.4 52.6-98.7 52.6-139.7 0-22.5-3.9-37.8-9.9-50.4z"
fill="#ffffff"
/>
</svg>
);
}

if (method === "ZELLE") {
return (
<div
className="h-7 w-7 bg-[#6d1ed4] rounded flex items-center justify-center text-white font-bold text-[15px]"
aria-label="Zelle"
>
Z
</div>
);
}

return (
<div
className="h-7 w-7 bg-green-600 rounded flex items-center justify-center text-white font-bold text-[15px]"
aria-label="Cash"
>
$
</div>
);
}

function PaymentMethodOption({ method }: { method: PaymentMethod }) {
return (
<div className="flex items-center gap-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,26 @@ import { Download } from "lucide-react";
import { useState } from "react";
import { CompleteOrderSchema } from "common/schemas/order";
import { z } from "zod";
import { getOrderBuyer } from "@/lib/order-buyer";
import { buildOrdersCsv } from "./ordersCsv";

type Order = z.infer<typeof CompleteOrderSchema>;

const paymentStatusLabel = (status: string | undefined) => {
if (status === "CONFIRMED") return "Received";
if (status === "UNVERIFIABLE") return "Unverified";
if (status === "PENDING") return "Not Received";
return "Unknown";
};

export function ExportButton({
orders,
fundraiserName,
label = "Export",
}: {
orders: Order[];
fundraiserName: string;
label?: string;
}) {
const [isExporting, setIsExporting] = useState(false);

const handleExport = () => {
setIsExporting(true);

try {
const headers = [
"Name",
"Email",
"NetID",
"Order Details",
"Payment Method",
"Payment Status",
"Pickup Status",
"Order Total",
];

const rows = orders.map((order) => {
const orderTotal = order.items.reduce(
(total, item) => total + item.quantity * Number(item.item.price),
0
);

const orderDetails = order.items
.map((item) => `${item.quantity} ${item.item.name}`)
.join(", ");

const buyer = getOrderBuyer(order);

return [
buyer.name || "Unknown",
buyer.email || "Unknown",
buyer.netId || "Unknown",
orderDetails,
order.paymentMethod || "Unknown",
paymentStatusLabel(order.paymentStatus),
order.pickedUp ? "Picked Up" : "Not Picked Up",
`$${orderTotal.toFixed(2)}`,
];
});

const csvContent = [
headers.join(","),
...rows.map((row) =>
row.map((cell) => `"${cell.replace(/"/g, '""')}"`).join(",")
),
].join("\n");
const csvContent = buildOrdersCsv(orders);

// Create blob and download link
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
Expand Down Expand Up @@ -101,8 +56,8 @@ export function ExportButton({
variant="outline"
className="font-[400] px-3 shadow-none rounded-lg border border-solid border-[#68b0ab]"
onClick={handleExport}
disabled={isExporting}>
{isExporting ? "Exporting..." : "Export"}
disabled={isExporting || orders.length === 0}>
{isExporting ? "Exporting..." : label}
<Download className="ml-2 h-5 w-5" />
</Button>
);
Expand Down
Loading
Loading