diff --git a/front-end/package-lock.json b/front-end/package-lock.json index 3cc8731..81bcbbc 100644 --- a/front-end/package-lock.json +++ b/front-end/package-lock.json @@ -20,6 +20,7 @@ "dotenv": "^16.4.7", "framer-motion": "^11.18.1", "gsap": "^3.12.7", + "html-to-image": "^1.11.11", "jsonwebtoken": "^9.0.2", "lucide-react": "^0.475.0", "react": "^18.2.0", @@ -12022,6 +12023,12 @@ "integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==", "license": "MIT" }, + "node_modules/html-to-image": { + "version": "1.11.11", + "resolved": "https://registry.npmjs.org/html-to-image/-/html-to-image-1.11.11.tgz", + "integrity": "sha512-9gux8QhvjRO/erSnDPv28noDZcPZmYE7e1vFsBLKLlRlKDSqNJYebj6Qz1TGd5lsRV+X+xYyjCKjuZdABinWjA==", + "license": "MIT" + }, "node_modules/html-url-attributes": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/html-url-attributes/-/html-url-attributes-3.0.1.tgz", diff --git a/front-end/package.json b/front-end/package.json index 21ed34e..2907be3 100644 --- a/front-end/package.json +++ b/front-end/package.json @@ -26,6 +26,7 @@ "dotenv": "^16.4.7", "framer-motion": "^11.18.1", "gsap": "^3.12.7", + "html-to-image": "^1.11.11", "jsonwebtoken": "^9.0.2", "lucide-react": "^0.475.0", "react": "^18.2.0", diff --git a/front-end/src/pages/CertificateGenerator.jsx b/front-end/src/pages/CertificateGenerator.jsx new file mode 100644 index 0000000..9d0ab70 --- /dev/null +++ b/front-end/src/pages/CertificateGenerator.jsx @@ -0,0 +1,110 @@ +import React, { useRef, useEffect, useState } from "react"; +import { toPng } from "html-to-image"; +import backgroundImage from "../assets/logo.png"; + +const CertificateGenerator = ({ username }) => { + const certificateRef = useRef(null); + const [profile, setProfile] = useState(null); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchGitHubProfile = async () => { + if (!username) { + setError("Username is missing."); + return; + } + + setLoading(true); + setError(null); + + try { + const response = await fetch(`https://api.github.com/users/${username}`); + if (!response.ok) throw new Error("GitHub profile not found"); + + const data = await response.json(); + setProfile(data); + } catch (err) { + setError(err.message); + setProfile(null); + } finally { + setLoading(false); + } + }; + + fetchGitHubProfile(); + }, [username]); + + const handleDownloadCertificate = async () => { + if (certificateRef.current) { + const dataUrl = await toPng(certificateRef.current); + const link = document.createElement("a"); + link.href = dataUrl; + link.download = `${username}_certificate.png`; + link.click(); + } + }; + + return ( +
This is proudly presented to
+ + {loading &&Fetching GitHub Profile...
} + {error &&{error}
} + + {profile && !loading && ( + + )} + ++ For valuable contributions to react-blog Project in Social Winter of Code (SWoC) from January 1, 2025 to March 1, 2025. +
+ +Project Mentor
+OkenHaha
+Date
+{new Date().toLocaleDateString()}
+@@ -45,40 +46,64 @@ const Contributors = () => {