sertificate downloaded added
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user