MCPcopy Create free account
hub / github.com/code100x/cms / CertificateComponent

Function CertificateComponent

src/components/Certificate.tsx:16–123  ·  view source on GitHub ↗
({
  certificateId,
  certificateSlug,
  course,
  userName,
}: OneCertificate & { userName: string })

Source from the content-addressed store, hash-verified

14import { useMemo, useState, useEffect } from 'react';
15
16export const CertificateComponent = ({
17 certificateId,
18 certificateSlug,
19 course,
20 userName,
21}: OneCertificate & { userName: string }) => {
22 const [loading, setLoading] = useState(true);
23
24 const certificateDetails = useMemo(
25 () => ({
26 certificateId,
27 course,
28 userName,
29 certificateSlug,
30 }),
31 [certificateId, course, userName, certificateSlug],
32 );
33
34 const { certificateImageUrl } = useGenerateCertificate({
35 certificateDetails,
36 userName,
37 });
38
39 useEffect(() => {
40 if (certificateImageUrl) {
41 setLoading(false);
42 }
43 }, [certificateImageUrl]);
44
45 const handleDownloadPNG = async () => {
46 if (loading) return;
47 setLoading(true);
48 const downloadUrl = certificateImageUrl;
49 console.log('downloadUrl is : ', downloadUrl);
50 const a = document.createElement('a');
51 a.href = downloadUrl;
52 a.download = 'certificate.png';
53 document.body.appendChild(a);
54 a.click();
55 document.body.removeChild(a);
56 setLoading(false);
57 };
58
59 const handleShareLinkedIn = async () => {
60 if (loading) return;
61 setLoading(true);
62 const certificateUrl = `${window.location.origin}/certificate/verify/${certificateSlug}`;
63 const postContent = `I just earned the "${course.title}" certificate on 100xDevs! Check it out: ${certificateUrl}`;
64 const shareUrl = `https://www.linkedin.com/shareArticle?mini=true&url=${encodeURIComponent(
65 certificateUrl,
66 )}&text=${encodeURIComponent(postContent)}`;
67 window.open(shareUrl);
68 setLoading(false);
69 };
70
71 const handleShareTwitter = () => {
72 if (loading) return;
73 setLoading(true);

Callers

nothing calls this directly

Calls 1

useGenerateCertificateFunction · 0.90

Tested by

no test coverage detected