.
This commit is contained in:
parent
cbc1b1b2c3
commit
445d1bfb0e
@ -22,6 +22,7 @@ import { useCallback, useEffect, useState } from "react";
|
|||||||
import { Trans } from "react-i18next";
|
import { Trans } from "react-i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useQuotes } from "../hooks";
|
import { useQuotes } from "../hooks";
|
||||||
|
import { DownloadQuoteDialog } from "./DownloadQuoteDialog";
|
||||||
|
|
||||||
const QuotePDFPreview = ({
|
const QuotePDFPreview = ({
|
||||||
quote,
|
quote,
|
||||||
@ -33,8 +34,8 @@ const QuotePDFPreview = ({
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { useReport, getQuotePDFFilename, useDownloader } = useQuotes();
|
const { useReport, getQuotePDFFilename, useDownloader } = useQuotes();
|
||||||
//const { download: downloadPDFFile } = useDownloader();
|
const { download, ...downloadProps } = useDownloader();
|
||||||
const { report, download, isInProgress } = useReport();
|
const { report, preview, isInProgress } = useReport();
|
||||||
const [URLReport, setURLReport] = useState<string | undefined>(undefined);
|
const [URLReport, setURLReport] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
const handleFinishDownload = useCallback(() => {
|
const handleFinishDownload = useCallback(() => {
|
||||||
@ -43,10 +44,14 @@ const QuotePDFPreview = ({
|
|||||||
});
|
});
|
||||||
}, [toast]);
|
}, [toast]);
|
||||||
|
|
||||||
|
const handleDownload = useCallback(() => {
|
||||||
|
if (quote) download(quote.id, getQuotePDFFilename(quote));
|
||||||
|
}, [quote]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
if (!isInProgress && quote && quote.id) {
|
if (quote && quote.id) {
|
||||||
download(quote.id);
|
preview(quote.id);
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
@ -120,14 +125,7 @@ const QuotePDFPreview = ({
|
|||||||
{t("common.print")}
|
{t("common.print")}
|
||||||
</span>
|
</span>
|
||||||
</Button>*/}
|
</Button>*/}
|
||||||
<Button
|
<Button size='sm' variant='outline' className='h-8 gap-1' onClick={handleDownload}>
|
||||||
size='sm'
|
|
||||||
variant='outline'
|
|
||||||
className='h-8 gap-1'
|
|
||||||
onClick={() => {
|
|
||||||
//downloadPDFFile(quote.id, getQuotePDFFilename(quote));
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DownloadIcon className='h-3.5 w-3.5' />
|
<DownloadIcon className='h-3.5 w-3.5' />
|
||||||
<span className='xl:sr-only 2xl:not-sr-only 2xl:whitespace-nowrap'>
|
<span className='xl:sr-only 2xl:not-sr-only 2xl:whitespace-nowrap'>
|
||||||
{t("quotes.list.preview.download_quote")}
|
{t("quotes.list.preview.download_quote")}
|
||||||
@ -170,10 +168,14 @@ const QuotePDFPreview = ({
|
|||||||
)}
|
)}
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className='py-4'>
|
<CardContent className='py-4'>
|
||||||
<PDFViewer file={URLReport} className='object-contain' />
|
<PDFViewer
|
||||||
|
file={URLReport}
|
||||||
|
className='object-contain'
|
||||||
|
onThumbnailClick={handleDownload}
|
||||||
|
/>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
{/*<DownloadQuoteDialog {...downloadProps} onFinishDownload={handleFinishDownload} />*/}
|
<DownloadQuoteDialog {...downloadProps} onFinishDownload={handleFinishDownload} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -240,7 +240,7 @@ export const useQuotes = () => {
|
|||||||
const auth = dataSource.getApiAuthorization();
|
const auth = dataSource.getApiAuthorization();
|
||||||
const [report, setReport] = useState<Blob | undefined>(undefined);
|
const [report, setReport] = useState<Blob | undefined>(undefined);
|
||||||
|
|
||||||
const downloader = useDownloader({
|
const { download, ...rest } = useDownloader({
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: auth,
|
Authorization: auth,
|
||||||
},
|
},
|
||||||
@ -257,16 +257,16 @@ export const useQuotes = () => {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const download = useCallback(
|
const preview = useCallback(
|
||||||
(id: string) => {
|
(id: string) => {
|
||||||
return downloader.download(actions.getQuotePDFDownloadURL(id), "");
|
return download(actions.getQuotePDFDownloadURL(id), "");
|
||||||
},
|
},
|
||||||
[downloader]
|
[download]
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...downloader,
|
...rest,
|
||||||
download,
|
preview,
|
||||||
report,
|
report,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -26,10 +26,11 @@ export interface PDFViewerProps {
|
|||||||
| {
|
| {
|
||||||
data: Uint8Array;
|
data: Uint8Array;
|
||||||
};
|
};
|
||||||
|
onThumbnailClick?: () => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PDFViewer = ({ file, className }: PDFViewerProps): JSX.Element => {
|
export const PDFViewer = ({ file, onThumbnailClick, className }: PDFViewerProps): JSX.Element => {
|
||||||
const [numPages, setNumPages] = useState<number>(0);
|
const [numPages, setNumPages] = useState<number>(0);
|
||||||
const [pageNumber, setPageNumber] = useState<number>(1);
|
const [pageNumber, setPageNumber] = useState<number>(1);
|
||||||
const [renderedPageNumber, setRenderedPageNumber] = useState<number | undefined>(undefined);
|
const [renderedPageNumber, setRenderedPageNumber] = useState<number | undefined>(undefined);
|
||||||
@ -94,9 +95,12 @@ export const PDFViewer = ({ file, className }: PDFViewerProps): JSX.Element => {
|
|||||||
onLoadSuccess={onDocumentLoadSuccess}
|
onLoadSuccess={onDocumentLoadSuccess}
|
||||||
loading={<LoadingSpinner className='w-full mx-auto mt-32' />}
|
loading={<LoadingSpinner className='w-full mx-auto mt-32' />}
|
||||||
options={options}
|
options={options}
|
||||||
className={`w-full aspect-[3/4] relative bg-white shadow w-[${
|
className={cn(
|
||||||
containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth
|
`w-full aspect-[3/4] relative bg-white shadow w-[${
|
||||||
}]`}
|
containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth
|
||||||
|
}]`,
|
||||||
|
onThumbnailClick ? "cursor-pointer" : ""
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{/**
|
{/**
|
||||||
* IMPORTANT: Keys are necessary so that React will know which Page component
|
* IMPORTANT: Keys are necessary so that React will know which Page component
|
||||||
@ -114,6 +118,7 @@ export const PDFViewer = ({ file, className }: PDFViewerProps): JSX.Element => {
|
|||||||
pageNumber={renderedPageNumber}
|
pageNumber={renderedPageNumber}
|
||||||
canvasBackground={"white"}
|
canvasBackground={"white"}
|
||||||
width={containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth}
|
width={containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth}
|
||||||
|
onClick={() => (onThumbnailClick ? onThumbnailClick() : null)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Page
|
<Page
|
||||||
@ -123,6 +128,7 @@ export const PDFViewer = ({ file, className }: PDFViewerProps): JSX.Element => {
|
|||||||
canvasBackground={"white"}
|
canvasBackground={"white"}
|
||||||
onRenderSuccess={onPageRenderSuccess}
|
onRenderSuccess={onPageRenderSuccess}
|
||||||
width={containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth}
|
width={containerWidth ? Math.min(containerWidth, maxWidth) : maxWidth}
|
||||||
|
onClick={() => (onThumbnailClick ? onThumbnailClick() : null)}
|
||||||
/>
|
/>
|
||||||
</Document>
|
</Document>
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user