sertificate downloaded added

This commit is contained in:
nabijonovdavronbek619@gmail.com
2026-04-02 21:27:55 +05:00
parent 0f84999259
commit 60b29aa7de

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}