diff --git a/src/widgets/detail/sertifikat.tsx b/src/widgets/detail/sertifikat.tsx new file mode 100644 index 0000000..f913e67 --- /dev/null +++ b/src/widgets/detail/sertifikat.tsx @@ -0,0 +1,55 @@ +'use client'; +import { useTranslations } from 'next-intl'; +import { FileDown, Loader2 } from 'lucide-react'; +import React, { useState } from 'react'; + +const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL; + +export default function Sertifikat({ document_id }: { document_id: number }) { + const t = useTranslations(); + const [loading, setLoading] = useState(false); + + const handleClick = async () => { + setLoading(true); + try { + const url = `${baseUrl}/documents/${document_id}/certificate/`; + const res = await fetch(url); + const blob = await res.blob(); + const objectUrl = URL.createObjectURL(blob); + window.open(objectUrl, '_blank'); + URL.revokeObjectURL(objectUrl); + } finally { + setLoading(false); + } + }; + + return ( + + ); +}