feat: update PDF generation to download file directly and rename button
This commit is contained in:
parent
42c15dfe96
commit
e68e8a7003
1 changed files with 9 additions and 3 deletions
|
|
@ -111,11 +111,17 @@ export function SchedaAnnuncioStampabile({ data }: { data: Annunci }) {
|
|||
);
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
toast.success("PDF generato con successo!", {
|
||||
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) {
|
||||
toast.error(
|
||||
`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">
|
||||
<h1 className="font-bold text-2xl">Scheda Annuncio Stampabile</h1>
|
||||
<div className="flex gap-2">
|
||||
<Button onClick={() => generatePdf()}>Genera Scheda</Button>
|
||||
<Button onClick={() => generatePdf()}>Scarica Scheda</Button>
|
||||
|
||||
<Popover onOpenChange={setOpenPopover} open={openPopover}>
|
||||
<PopoverTrigger asChild>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue