Checkpoint: Ajout du bouton de téléchargement direct du PDF annoté BAP : route Express /api/download-bap/:filename avec Content-Disposition attachment, bouton Télécharger dans InvoicesBAP (apparaît après validation), boutons Voir + Télécharger dans l'Historique BAP. Correction du layout PDF (2 colonnes) également incluse.

This commit is contained in:
Manus
2026-04-12 10:05:02 -04:00
parent 3cbd705249
commit 9d71f1e34a
4 changed files with 87 additions and 15 deletions

View File

@@ -19,8 +19,21 @@ import {
Building2,
User,
FileText,
Download,
} from "lucide-react";
// Helper : télécharge un PDF annoté BAP depuis son URL de stockage
function downloadBapPdf(pdfUrl: string, supplierName?: string | null) {
const filename = pdfUrl.split('/').pop() || 'BAP.pdf';
const downloadUrl = `/api/download-bap/${filename}`;
const a = document.createElement('a');
a.href = downloadUrl;
a.download = supplierName ? `BAP_${supplierName.replace(/[^a-zA-Z0-9]/g, '_')}.pdf` : filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
export default function BapHistory() {
const { data: entries, isLoading, refetch } = trpc.bapHistory.getAll.useQuery();
const deleteMutation = trpc.bapHistory.delete.useMutation();
@@ -236,15 +249,27 @@ export default function BapHistory() {
</TableCell>
<TableCell>
{entry.exportMode === "browser" && entry.pdfUrl ? (
<Button
variant="ghost"
size="sm"
className="h-7 px-2 text-blue-600 hover:text-blue-700"
onClick={() => window.open(entry.pdfUrl!, "_blank")}
>
<Monitor className="h-3.5 w-3.5 mr-1" />
<span className="text-xs">Voir PDF</span>
</Button>
<div className="flex items-center gap-1">
<Button
variant="ghost"
size="sm"
className="h-7 px-2 text-blue-600 hover:text-blue-700"
onClick={() => window.open(entry.pdfUrl!, "_blank")}
title="Ouvrir dans le navigateur"
>
<Monitor className="h-3.5 w-3.5 mr-1" />
<span className="text-xs">Voir</span>
</Button>
<Button
variant="ghost"
size="sm"
className="h-7 px-2 text-emerald-600 hover:text-emerald-700 hover:bg-emerald-50"
onClick={() => downloadBapPdf(entry.pdfUrl!, entry.supplierName)}
title="Télécharger le PDF annoté"
>
<Download className="h-3.5 w-3.5" />
</Button>
</div>
) : entry.exportMode === "folder" && entry.exportPath ? (
<div className="flex items-center gap-1 text-orange-600">
<FolderOpen className="h-3.5 w-3.5" />