11import { useTranslations } from 'next-intl'
2- import { forwardRef , useCallback , useState } from 'react'
2+ import { forwardRef , useCallback , useContext , useState } from 'react'
33//BsFiletypeDoc, BsFiletypeMov,
44import {
55 BsFiletypeJpg ,
@@ -18,6 +18,7 @@ import type { LinkType } from '@/types'
1818import { ArrowRight } from '../../icons'
1919import { BaseLink } from './BaseLink'
2020import { getArrowElement , type ResourceLinkProps } from './ResourceLink'
21+ import { FriendlyCaptchaContext } from '@/contexts/FriendlyCaptchaContext'
2122
2223type Variants = 'default' | 'fit'
2324type Type = 'simple' | 'resource' | 'stickyMenu'
@@ -63,6 +64,7 @@ const DownloadableLink = forwardRef<HTMLDivElement, DownloadableLinkProps>(
6364 const openInNewTab = [ 'pdf' , 'png' , 'jpg' ]
6465
6566 const [ notHuman , setNotHuman ] = useState ( false )
67+ const { isHuman, setIsHuman} = useContext ( FriendlyCaptchaContext )
6668
6769 const variantClassName : Partial < Record < string , string > > = {
6870 default : 'w-full' ,
@@ -120,6 +122,7 @@ const DownloadableLink = forwardRef<HTMLDivElement, DownloadableLinkProps>(
120122 setIsFriendlyChallengeDone ( true )
121123 const result = await verifyCaptcha ( solution )
122124 setNotHuman ( result !== true )
125+ setIsHuman ( result == true )
123126 } ,
124127 [ ] ,
125128 )
@@ -153,9 +156,38 @@ const DownloadableLink = forwardRef<HTMLDivElement, DownloadableLinkProps>(
153156 </ div >
154157 )
155158
159+ const downloadable = (
160+ < BaseLink
161+ className = { twMerge (
162+ `${ commonResourceLinkWrapperClassName } ` ,
163+ ! isHuman && 'pt-20' ,
164+ ) }
165+ type = { linkType }
166+ href = { linkType === 'downloadableFile' ? fileUrl : url }
167+ { ...( extension &&
168+ openInNewTab ?. includes ( extension . toLowerCase ( ) ) && {
169+ target : '_blank' ,
170+ } ) }
171+ >
172+ < span
173+ className = { `flex h-full w-inherit items-center justify-start gap-x-2 ${ contentVariantClassName [ variant ] } ` }
174+ >
175+ { linkElement }
176+ { getArrowElement (
177+ extension && openInNewTab ?. includes ( extension . toLowerCase ( ) )
178+ ? 'externalUrl'
179+ : linkType ,
180+ ) }
181+ </ span >
182+
183+ < span className = 'h-px w-[0%] bg-grey-40 transition-all duration-300 group-hover:w-full' />
184+ </ BaseLink >
185+ )
186+
187+
156188 return (
157189 < div ref = { ref } >
158- < button
190+ { ! isHuman && < button
159191 type = 'button'
160192 onClick = { handleRequestFile }
161193 className = {
@@ -192,7 +224,8 @@ const DownloadableLink = forwardRef<HTMLDivElement, DownloadableLinkProps>(
192224 < div className = 'h-px w-[0%] bg-grey-40 transition-all duration-300 group-hover:w-full' />
193225 ) }
194226 </ button >
195- { showModal && (
227+ }
228+ { showModal && ! notHuman && (
196229 < Modal
197230 isOpen = { showModal }
198231 onClose = { handleClose }
@@ -226,34 +259,12 @@ const DownloadableLink = forwardRef<HTMLDivElement, DownloadableLinkProps>(
226259 </ Typography >
227260 ) }
228261 { isFriendlyChallengeDone && ! notHuman && (
229- < BaseLink
230- className = { twMerge (
231- `${ commonResourceLinkWrapperClassName } ` ,
232- 'pt-20' ,
233- ) }
234- type = { linkType }
235- href = { linkType === 'downloadableFile' ? fileUrl : url }
236- { ...( extension &&
237- openInNewTab ?. includes ( extension . toLowerCase ( ) ) && {
238- target : '_blank' ,
239- } ) }
240- >
241- < span
242- className = { `flex h-full w-inherit items-center justify-start gap-x-2 ${ contentVariantClassName [ variant ] } ` }
243- >
244- { linkElement }
245- { getArrowElement (
246- extension && openInNewTab ?. includes ( extension . toLowerCase ( ) )
247- ? 'externalUrl'
248- : linkType ,
249- ) }
250- </ span >
251-
252- < span className = 'h-px w-[0%] bg-grey-40 transition-all duration-300 group-hover:w-full' />
253- </ BaseLink >
262+ downloadable
254263 ) }
255264 </ Modal >
256- ) }
265+
266+ ) }
267+ { isHuman && downloadable }
257268 </ div >
258269 )
259270 } ,
0 commit comments