From 7d29f40ab28efa8f5eff0641cc060e88a2d37789 Mon Sep 17 00:00:00 2001 From: BOHA Date: Fri, 27 Mar 2026 10:42:29 +0100 Subject: [PATCH] fix: offers table PDF button opens blob from NAS instead of print page Co-Authored-By: Claude Opus 4.6 (1M context) --- src/admin/pages/Offers.tsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/admin/pages/Offers.tsx b/src/admin/pages/Offers.tsx index a301dfb..119be91 100644 --- a/src/admin/pages/Offers.tsx +++ b/src/admin/pages/Offers.tsx @@ -223,24 +223,20 @@ export default function Offers() { if (pdfLoading) return; setPdfLoading(quotation.id); try { - const response = await apiFetch(`${API_BASE}/offers-pdf/${quotation.id}`); + const response = await apiFetch( + `${API_BASE}/offers/${quotation.id}/file`, + ); if (response.status === 401) return; if (!response.ok) { - alert.error("Nepodařilo se vygenerovat PDF"); + alert.error("PDF soubor nenalezen — otevřete nabídku a uložte ji"); return; } - const html = await response.text(); - const w = window.open("", "_blank"); - if (w) { - w.document.open(); - w.document.write(html); - w.document.close(); - w.onload = () => w.print(); - } else { - alert.error("Prohlížeč zablokoval vyskakovací okno"); - } + const blob = await response.blob(); + const url = URL.createObjectURL(blob); + window.open(url, "_blank"); + setTimeout(() => URL.revokeObjectURL(url), 60000); } catch { - alert.error("Chyba při generování PDF"); + alert.error("Chyba připojení"); } finally { setPdfLoading(null); } @@ -753,7 +749,7 @@ export default function Offers() {