// app/invoices/page.tsx
'use client';
import { useState } from 'react';
export default function InvoicePage() {
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
const generateInvoice = async () => {
const res = await fetch('/api/generate-pdf', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
html: `
<h1>Invoice #1234</h1>
<p>Bill to: Acme Corp</p>
<table>
<tr><td>Consulting</td><td>10 hrs</td><td>$1,500</td></tr>
</table>
<h2>Total: $1,500</h2>
`,
}),
});
const pdf = await res.json();
setPdfUrl(pdf.url);
};
return (
<div>
<button onClick={generateInvoice}>Generate Invoice PDF</button>
{pdfUrl && (
<a href={pdfUrl} target="_blank" rel="noopener noreferrer">
Download PDF
</a>
)}
</div>
);
}