mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Invoice number in downloaded pdf document
This commit is contained in:
@@ -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