mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: Invoice number in downloaded pdf document
This commit is contained in:
@@ -11,8 +11,8 @@ import { compose } from '@/utils';
|
||||
function CreditNotePdfPreviewDialogContent({
|
||||
subscriptionForm: { creditNoteId },
|
||||
}) {
|
||||
const { isLoading, pdfUrl } = usePdfCreditNote(creditNoteId);
|
||||
|
||||
const { isLoading, pdfUrl, filename } = usePdfCreditNote(creditNoteId);
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<div class="dialog__header-actions">
|
||||
@@ -27,7 +27,7 @@ function CreditNotePdfPreviewDialogContent({
|
||||
|
||||
<AnchorButton
|
||||
href={pdfUrl}
|
||||
download={'creditNote.pdf'}
|
||||
download={filename}
|
||||
minimal={true}
|
||||
outlined={true}
|
||||
>
|
||||
|
||||
@@ -14,7 +14,7 @@ function EstimatePdfPreviewDialogContent({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { isLoading, pdfUrl } = usePdfEstimate(estimateId);
|
||||
const { isLoading, pdfUrl, filename } = usePdfEstimate(estimateId);
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
@@ -30,7 +30,7 @@ function EstimatePdfPreviewDialogContent({
|
||||
|
||||
<AnchorButton
|
||||
href={pdfUrl}
|
||||
download={'estimate.pdf'}
|
||||
download={filename}
|
||||
minimal={true}
|
||||
outlined={true}
|
||||
>
|
||||
|
||||
@@ -13,7 +13,7 @@ function InvoicePdfPreviewDialogContent({
|
||||
// #withDialog
|
||||
closeDialog,
|
||||
}) {
|
||||
const { isLoading, pdfUrl } = usePdfInvoice(invoiceId);
|
||||
const { isLoading, pdfUrl, filename } = usePdfInvoice(invoiceId);
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
@@ -29,7 +29,7 @@ function InvoicePdfPreviewDialogContent({
|
||||
|
||||
<AnchorButton
|
||||
href={pdfUrl}
|
||||
download={'invoice.pdf'}
|
||||
download={filename}
|
||||
minimal={true}
|
||||
outlined={true}
|
||||
>
|
||||
|
||||
@@ -11,7 +11,7 @@ import { compose } from '@/utils';
|
||||
function PaymentReceivePdfPreviewDialogContent({
|
||||
subscriptionForm: { paymentReceiveId },
|
||||
}) {
|
||||
const { isLoading, pdfUrl } = usePdfPaymentReceive(paymentReceiveId);
|
||||
const { isLoading, pdfUrl, filename } = usePdfPaymentReceive(paymentReceiveId);
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
@@ -27,7 +27,7 @@ function PaymentReceivePdfPreviewDialogContent({
|
||||
|
||||
<AnchorButton
|
||||
href={pdfUrl}
|
||||
download={'payment.pdf'}
|
||||
download={filename}
|
||||
minimal={true}
|
||||
outlined={true}
|
||||
>
|
||||
|
||||
@@ -13,7 +13,7 @@ function ReceiptPdfPreviewDialogContent({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { isLoading, pdfUrl } = usePdfReceipt(receiptId);
|
||||
const { isLoading, pdfUrl, filename } = usePdfReceipt(receiptId);
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
@@ -29,7 +29,7 @@ function ReceiptPdfPreviewDialogContent({
|
||||
|
||||
<AnchorButton
|
||||
href={pdfUrl}
|
||||
download={'receipt.pdf'}
|
||||
download={filename}
|
||||
minimal={true}
|
||||
outlined={true}
|
||||
>
|
||||
|
||||
@@ -8,6 +8,7 @@ export const useRequestPdf = (httpProps) => {
|
||||
const [isLoaded, setIsLoaded] = React.useState(false);
|
||||
const [pdfUrl, setPdfUrl] = React.useState('');
|
||||
const [response, setResponse] = React.useState(null);
|
||||
const [filename, setFilename] = React.useState<string>('');
|
||||
|
||||
React.useEffect(() => {
|
||||
setIsLoading(true);
|
||||
@@ -25,10 +26,21 @@ export const useRequestPdf = (httpProps) => {
|
||||
// Build a URL from the file
|
||||
const fileURL = URL.createObjectURL(file);
|
||||
|
||||
// Extract the filename from the Content-Disposition header
|
||||
const contentDisposition = response.headers.get('Content-Disposition');
|
||||
let _filename = 'default.pdf'; // Default filename if not provided by server
|
||||
|
||||
if (contentDisposition && contentDisposition.includes('filename=')) {
|
||||
const matches = contentDisposition.match(/filename="(.+)"/);
|
||||
if (matches && matches[1]) {
|
||||
_filename = matches[1];
|
||||
}
|
||||
}
|
||||
setPdfUrl(fileURL);
|
||||
setIsLoading(false);
|
||||
setIsLoaded(true);
|
||||
setResponse(response);
|
||||
setFilename(_filename);
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -37,5 +49,6 @@ export const useRequestPdf = (httpProps) => {
|
||||
isLoaded,
|
||||
pdfUrl,
|
||||
response,
|
||||
filename
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user