Merge pull request #10 from DavronNabijonv/dev
sertificate downloaded added
This commit is contained in:
@@ -12,17 +12,28 @@ export default function Sertifikat({ document_id }: { document_id: number }) {
|
|||||||
const handleClick = async () => {
|
const handleClick = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const url = `${baseUrl}/documents/${document_id}/certificate/`;
|
const url = `${baseUrl}/shared/certificate/${document_id}/pdf/`;
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
const blob = await res.blob();
|
const blob = await res.blob();
|
||||||
const objectUrl = URL.createObjectURL(blob);
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
window.open(objectUrl, '_blank');
|
|
||||||
|
// ✅ window.open o'rniga <a> tag bilan download
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = objectUrl;
|
||||||
|
a.download = `certificate-${document_id}.pdf`;
|
||||||
|
a.click();
|
||||||
|
|
||||||
URL.revokeObjectURL(objectUrl);
|
URL.revokeObjectURL(objectUrl);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const handleClick = () => {
|
||||||
|
// const url = `${baseUrl}/documents/${document_id}/pdf/`;
|
||||||
|
// window.open(url, '_blank');
|
||||||
|
// };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
|
|||||||
Reference in New Issue
Block a user