11import { useRef } from "react" ;
22import Image from "next/image" ;
3- import { Button } from "@/components/ui/button" ;
43import { useUserStore } from "@/store/codev-store" ;
54import { BookDown } from "lucide-react" ;
5+ import certificateSvg from "@/public/assets/ssvgs/certificate.svg" ;
66
77import Certificate , {
88 CertificateProps ,
99 handleDownload ,
1010} from "./DashboardDownloadCertificate" ;
11+ import { cn } from "@codevs/ui" ;
12+ import { Tooltip , TooltipContent , TooltipProvider , TooltipTrigger } from "@codevs/ui/tooltip" ;
13+ import { CertificateIcon , CertificateOffIcon } from "./DashboardCertificateIcons" ;
14+ import { Button } from "@codevs/ui/button" ;
15+
16+ function hasLevelTwoBadge ( level : Record < string , number > | undefined ) : boolean {
17+ const validLevels = Object . entries ( level ! ) . filter (
18+ ( [ , levelValue ] ) => levelValue > 0 ,
19+ ) ;
20+
21+ return validLevels . some ( ( [ , levelValue ] ) => levelValue >= 2 ) ;
22+ }
1123
1224const DashboardCertificate = ( ) => {
1325 const { user, userLevel } = useUserStore ( ) ;
@@ -103,9 +115,11 @@ const DashboardCertificate = () => {
103115 }
104116 } ) ( ) ;
105117
118+ const isCertificateUnlocked = hasLevelTwoBadge ( user ?. level ) ;
119+
106120 return (
107121 < >
108- < div className = "absolute left-4 top-4" >
122+ < div className = "absolute left-4 top-4 z-10 " >
109123 < div
110124 style = { {
111125 position : "absolute" ,
@@ -114,34 +128,45 @@ const DashboardCertificate = () => {
114128 width : "1000px" ,
115129 height : "700px" ,
116130 overflow : "hidden" ,
117- zIndex : - 1 ,
131+ visibility : "hidden" ,
132+ pointerEvents : "none" ,
118133 } }
134+ aria-hidden = "true"
119135 >
120136 < Certificate { ...certData } ref = { certRef } />
121137 </ div >
122- < Button
123- className = "md:p-15 md:w-15 h-6 w-10 p-2"
124- onClick = { ( ) => hasLevelTwoBadge ( user ?. level ) && handleDownload ( certRef , certData . name ) }
125- disabled = { ! hasLevelTwoBadge ( user ?. level ) }
126- title = {
127- hasLevelTwoBadge ( user ?. level )
128- ? "Download your certificate"
129- : "Complete more projects to unlock your certificate"
130- }
131- >
132- < BookDown className = { hasLevelTwoBadge ( user ?. level ) ? "" : "opacity-50" } />
133- </ Button >
138+ < Tooltip >
139+ < TooltipTrigger asChild >
140+ < Button
141+ size = "icon"
142+ variant = "ghost"
143+ className = { cn (
144+ "rounded-full inline-flex items-center justify-center" ,
145+ "transition-colors duration-200" ,
146+ isCertificateUnlocked
147+ ? "hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"
148+ : "cursor-not-allowed hover:bg-gray-50 dark:hover:bg-gray-900"
149+ ) }
150+ onClick = { ( ) => isCertificateUnlocked && handleDownload ( certRef , certData . name ) }
151+ >
152+ { isCertificateUnlocked ? (
153+ < CertificateIcon className = "h-6 w-6 text-[#9747FF]" />
154+ ) : (
155+ < CertificateOffIcon className = "h-6 w-6 opacity-50" />
156+ ) }
157+ </ Button >
158+ </ TooltipTrigger >
159+ < TooltipContent side = "bottom" align = "start" >
160+ { isCertificateUnlocked
161+ ? "Download your certificate"
162+ : "Reach level 2 to unlock the certificate" }
163+ </ TooltipContent >
164+ </ Tooltip >
134165 </ div >
135166 </ >
136167 ) ;
137168} ;
138169
139- function hasLevelTwoBadge ( level : Record < string , number > | undefined ) : boolean {
140- const validLevels = Object . entries ( level ! ) . filter (
141- ( [ , levelValue ] ) => levelValue > 0 ,
142- ) ;
143170
144- return validLevels . some ( ( [ , levelValue ] ) => levelValue >= 2 ) ;
145- }
146171
147172export default DashboardCertificate ;
0 commit comments