From 5705cf6a39a8c4c0bde1b76993e709c9ba45888d Mon Sep 17 00:00:00 2001 From: "mihailo.vojinovic" Date: Wed, 11 Feb 2026 16:56:26 +0100 Subject: Make download button download an invoice --- src/components/invoice-generator.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/components/invoice-generator.tsx b/src/components/invoice-generator.tsx index 3389c25..792dfbc 100644 --- a/src/components/invoice-generator.tsx +++ b/src/components/invoice-generator.tsx @@ -9,9 +9,11 @@ import { SubmitHandler, } from "react-hook-form"; import { Input } from "./ui/input"; -import React from "react"; +import React, { useActionState } from "react"; import { cn } from "@/utils/cn"; import { Button } from "./ui/button"; +import { generateInvoiceAction } from "@/lib/actions"; +import { generateInvoice } from "@/lib/generate"; const defaultItem = { description: "", @@ -45,8 +47,17 @@ export const InvoiceGenerator = () => { const lineItems = useWatch({ control, name: "line_items" }); const currency = watch("currency", "USD"); - const onSubmit: SubmitHandler = (data) => { + const onSubmit: SubmitHandler = async (data) => { console.log(data); + const blob = await generateInvoice(data); + const a = document.createElement("a"); + a.href = URL.createObjectURL(blob); + a.download = "invoice.pdf"; + document.body.appendChild(a); + a.click(); + + document.body.removeChild(a); + a.remove(); }; return ( -- cgit v1.3.1