Merge pull request #10 from DavronNabijonv/dev

sertificate downloaded added
This commit is contained in:
Davronbek Nabijonov
2026-04-02 21:30:09 +05:00
committed by GitHub

View File

@@ -12,17 +12,28 @@ export default function Sertifikat({ document_id }: { document_id: number }) {
const handleClick = async () => {
setLoading(true);
try {
const url = `${baseUrl}/documents/${document_id}/certificate/`;
const url = `${baseUrl}/shared/certificate/${document_id}/pdf/`;
const res = await fetch(url);
const blob = await res.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);
} finally {
setLoading(false);
}
};
// const handleClick = () => {
// const url = `${baseUrl}/documents/${document_id}/pdf/`;
// window.open(url, '_blank');
// };
return (
<button
onClick={handleClick}