feat: update PDF generation to download file directly and rename button

This commit is contained in:
Marco Pedone 2026-02-03 11:34:05 +01:00
parent 42c15dfe96
commit e68e8a7003

View file

@ -111,11 +111,17 @@ export function SchedaAnnuncioStampabile({ data }: { data: Annunci }) {
); );
} }
const blob = await response.blob(); const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
toast.success("PDF generato con successo!", { toast.success("PDF generato con successo!", {
id: "generate-pdf", id: "generate-pdf",
}); });
window.open(url, "_blank"); const url = window.URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `scheda-annuncio-${data.codice}.pdf`;
document.body.appendChild(link);
link.click();
link.remove();
window.URL.revokeObjectURL(url);
} catch (error) { } catch (error) {
toast.error( toast.error(
`Errore durante la generazione del PDF: ${(error as Error).message}`, `Errore durante la generazione del PDF: ${(error as Error).message}`,
@ -133,7 +139,7 @@ export function SchedaAnnuncioStampabile({ data }: { data: Annunci }) {
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<h1 className="font-bold text-2xl">Scheda Annuncio Stampabile</h1> <h1 className="font-bold text-2xl">Scheda Annuncio Stampabile</h1>
<div className="flex gap-2"> <div className="flex gap-2">
<Button onClick={() => generatePdf()}>Genera Scheda</Button> <Button onClick={() => generatePdf()}>Scarica Scheda</Button>
<Popover onOpenChange={setOpenPopover} open={openPopover}> <Popover onOpenChange={setOpenPopover} open={openPopover}>
<PopoverTrigger asChild> <PopoverTrigger asChild>