|
| 1 | +import { formatAmount } from "@stellar-split/sdk"; |
| 2 | +import type { Invoice } from "@stellar-split/sdk"; |
| 3 | + |
| 4 | +interface Props { |
| 5 | + invoice: Invoice; |
| 6 | + total: bigint; |
| 7 | +} |
| 8 | + |
| 9 | +/** |
| 10 | + * InvoicePDF — print-only invoice layout + "Download PDF" button. |
| 11 | + * The button is hidden in print view via print:hidden. |
| 12 | + * The #invoice-print section is shown only in print via the global @media print styles. |
| 13 | + */ |
| 14 | +export default function InvoicePDF({ invoice, total }: Props) { |
| 15 | + const deadline = invoice.deadline > 0 |
| 16 | + ? new Date(invoice.deadline * 1000).toLocaleString() |
| 17 | + : "No deadline"; |
| 18 | + |
| 19 | + return ( |
| 20 | + <> |
| 21 | + {/* Trigger button — hidden when printing */} |
| 22 | + <button |
| 23 | + type="button" |
| 24 | + onClick={() => window.print()} |
| 25 | + className="px-3 py-1.5 rounded-lg bg-indigo-600 hover:bg-indigo-500 text-sm font-semibold transition-colors print:hidden" |
| 26 | + > |
| 27 | + Download PDF |
| 28 | + </button> |
| 29 | + |
| 30 | + {/* Print-only content */} |
| 31 | + <div id="invoice-print" className="hidden print:block text-black bg-white p-8 text-sm leading-relaxed"> |
| 32 | + <h1 className="text-2xl font-bold mb-1">Invoice #{invoice.id}</h1> |
| 33 | + <p className="text-gray-500 mb-6">StellarSplit On-Chain Invoice</p> |
| 34 | + |
| 35 | + <table className="w-full mb-6 text-left border-collapse"> |
| 36 | + <tbody> |
| 37 | + <tr className="border-b border-gray-200"> |
| 38 | + <th className="py-1.5 pr-4 font-semibold w-32">Status</th> |
| 39 | + <td className="py-1.5">{invoice.status}</td> |
| 40 | + </tr> |
| 41 | + <tr className="border-b border-gray-200"> |
| 42 | + <th className="py-1.5 pr-4 font-semibold">Creator</th> |
| 43 | + <td className="py-1.5 font-mono break-all">{invoice.creator}</td> |
| 44 | + </tr> |
| 45 | + <tr className="border-b border-gray-200"> |
| 46 | + <th className="py-1.5 pr-4 font-semibold">Deadline</th> |
| 47 | + <td className="py-1.5">{deadline}</td> |
| 48 | + </tr> |
| 49 | + <tr> |
| 50 | + <th className="py-1.5 pr-4 font-semibold">Total</th> |
| 51 | + <td className="py-1.5">{formatAmount(total)} USDC</td> |
| 52 | + </tr> |
| 53 | + </tbody> |
| 54 | + </table> |
| 55 | + |
| 56 | + <h2 className="font-semibold text-base mb-2">Recipients</h2> |
| 57 | + <table className="w-full border-collapse"> |
| 58 | + <thead> |
| 59 | + <tr className="border-b-2 border-gray-300"> |
| 60 | + <th className="text-left py-1.5 pr-4">Address</th> |
| 61 | + <th className="text-right py-1.5">Amount (USDC)</th> |
| 62 | + </tr> |
| 63 | + </thead> |
| 64 | + <tbody> |
| 65 | + {invoice.recipients.map((r, i) => ( |
| 66 | + <tr key={i} className="border-b border-gray-100"> |
| 67 | + <td className="py-1.5 pr-4 font-mono break-all">{r.address}</td> |
| 68 | + <td className="py-1.5 text-right">{formatAmount(r.amount)}</td> |
| 69 | + </tr> |
| 70 | + ))} |
| 71 | + </tbody> |
| 72 | + </table> |
| 73 | + </div> |
| 74 | + </> |
| 75 | + ); |
| 76 | +} |
0 commit comments