import { PDFViewer } from "@/components"; import { cn } from "@/lib/utils"; import { Card, CardContent } from "@/ui"; import { IListQuotes_Response_DTO } from "@shared/contexts"; import { t } from "i18next"; import { useCallback, useEffect, useState } from "react"; import { useQuotes } from "../hooks"; import { PDFGenerationLoading } from "./PDFGenerationLoading"; const QuotePDFPreview = ({ quote, className, }: { quote?: IListQuotes_Response_DTO; className?: string; }) => { //const navigate = useNavigate(); //const { toast } = useToast(); const { useReport, getQuotePDFFilename, useDownloader } = useQuotes(); const { download } = useDownloader(); const { report, preview, isInProgress, ...otherReportProps } = useReport(); const [URLReport, setURLReport] = useState(undefined); /*const handleFinishDownload = useCallback(() => { toast({ description: t("quotes.downloading_dialog.toast_success"), }); }, [toast]);*/ const handleDownload = useCallback(() => { if (quote) download(quote.id, getQuotePDFFilename(quote)); }, [quote]); useEffect(() => { const timer = setTimeout(() => { if (quote && quote.id) { preview(quote.id); } }, 200); return () => clearTimeout(timer); }, [quote]); useEffect(() => { if (!isInProgress && report) { const blobURL = window.URL && window.URL.createObjectURL ? window.URL.createObjectURL(report) : window.webkitURL.createObjectURL(report); console.log(blobURL); setURLReport(blobURL); return () => { setURLReport(undefined); window.URL.revokeObjectURL(blobURL); }; } }, [report, isInProgress]); if (!quote) { return (

{t("quotes.list.resume.select_quote")}

); } if (isInProgress) { return ; } return ( ); }; QuotePDFPreview.whyDidYouRender = true; export { QuotePDFPreview };