import React, { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Download, FileText, File as FileIcon, X } from 'lucide-react'; import { exportProjectDocument } from '../../api/client'; import toast from 'react-hot-toast'; interface ExportModalProps { isOpen: boolean; onClose: () => void; projectId: string; } export const ExportModal: React.FC = ({ isOpen, onClose, projectId }) => { const [format, setFormat] = useState<'pdf' | 'docx'>('pdf'); const [template, setTemplate] = useState('official'); const [isExporting, setIsExporting] = useState(false); if (!isOpen) return null; const handleExport = async () => { try { setIsExporting(true); toast.loading('Generowanie dokumentu...', { id: 'export' }); const response = await exportProjectDocument(projectId, format, template); // Create a blob URL and trigger download const blob = new Blob([response.data], { type: response.headers['content-type'] }); const url = window.URL.createObjectURL(blob); // Generate filename based on headers or default let fileName = `Wniosek_${projectId}.${format}`; const contentDisposition = response.headers['content-disposition']; if (contentDisposition && contentDisposition.indexOf('filename=') !== -1) { const matches = contentDisposition.match(/filename="?([^"]+)"?/); if (matches && matches[1]) { fileName = matches[1]; } } const link = document.createElement('a'); link.href = url; link.setAttribute('download', fileName); document.body.appendChild(link); link.click(); link.remove(); window.URL.revokeObjectURL(url); toast.success('Pomyślnie wyeksportowano dokument!', { id: 'export' }); onClose(); } catch (error) { console.error(error); toast.error('Wystąpił błąd podczas generowania dokumentu.', { id: 'export' }); } finally { setIsExporting(false); } }; return (

Eksportuj Wniosek

{/* FORMAT WIDGET */}
{/* TEMPLATE WIDGET */}
{[ { id: 'standard', name: 'Standardowy', desc: 'Dobry na start (Arial 11, klasyczny układ)' }, { id: 'official', name: 'Urzędowy', desc: 'Całkowicie ustrukturyzowany, formalny układ zalecany do urzędów' }, { id: 'modern', name: 'Nowoczesny', desc: 'Więcej przestrzeni i oddechu z subtelnymi akcentami kolorystycznymi' } ].map(tpl => ( ))}
{/* TIP FOR DOCX */} {format === 'docx' && (
ℹ️ W wygenerowanym pliku DOCX spis treści jest początkowo pusty. Po otwarciu dokumentu w Microsoft Word naciśnij F9, aby zaktualizować stronę.
)}
); };