1
- import React , { useState , useEffect } from ' react' ;
2
- import ' ./BannerRedirect.scss' ;
3
- import { MdClose } from "react-icons/md" ;
1
+ import React , { useState , useEffect } from " react"
2
+ import " ./BannerRedirect.scss"
3
+ import { MdClose } from "react-icons/md"
4
4
5
5
function BannerRedirect ( ) {
6
- const [ isOpen , setIsOpen ] = useState ( true ) ;
6
+ const [ isOpen , setIsOpen ] = useState ( true )
7
7
8
- const WEBSITES = Object . freeze ( {
9
- ES : 'https://es.bitlogic.io' ,
10
- EN : 'https://en.bitlogic.io' ,
11
- } ) ;
12
-
13
- const titleEs = `¿Te gustaría visitar nuestro sitio en español?` ;
14
- const titleEn = `Would you like to visit our English site?` ;
8
+ const REDIRECT = Object . freeze ( {
9
+ title : `Would you like to visit our English site?` ,
10
+ url : "https://en.bitlogic.io" ,
11
+ callToAction : "Let’s go!" ,
12
+ } )
15
13
16
14
const closeBanner = ( ) => {
17
- setIsOpen ( false ) ;
15
+ setIsOpen ( false )
18
16
19
- if ( typeof window !== ' undefined' ) {
20
- localStorage . setItem ( ' BannerRedirect' , ' closed' )
17
+ if ( typeof window !== " undefined" ) {
18
+ localStorage . setItem ( " BannerRedirect" , " closed" )
21
19
}
22
- } ;
23
-
24
- const userLanguage = typeof window !== 'undefined' ? navigator ?. language : '' ;
25
- const userLocation = typeof window !== 'undefined' ? window ?. location ?. origin : ''
20
+ }
26
21
27
22
useEffect ( ( ) => {
28
- if (
29
- ( userLanguage ?. startsWith ( 'es' ) && userLocation ?. includes ( 'es' ) ) ||
30
- ( userLanguage ?. startsWith ( 'en' ) && userLocation ?. includes ( 'en' ) )
31
- ) {
32
- closeBanner ( )
23
+ const bannerStorage =
24
+ typeof window !== "undefined"
25
+ ? localStorage . getItem ( "BannerRedirect" )
26
+ : undefined
27
+ if ( bannerStorage === "closed" ) {
28
+ setIsOpen ( false )
33
29
}
34
- } , [ userLanguage , userLocation ] ) ;
35
-
36
- const bannerStorage = typeof window !== 'undefined'
37
- ? localStorage . getItem ( 'BannerRedirect' )
38
- : undefined
30
+ } , [ ] )
39
31
40
- if ( bannerStorage === 'closed' || ! isOpen ) return null ;
32
+ if ( ! isOpen ) return null
41
33
42
34
return (
43
- < section className = 'BannerRedirect container' >
44
- < div className = 'BannerRedirect__wrapper' >
45
- < div className = 'd-flex flex-direction-row' >
46
- < h6 > { userLanguage ?. startsWith ( 'es' )
47
- ? titleEs
48
- : titleEn }
49
- </ h6 >
50
- < button aria-label = 'Close Banner'
51
- onClick = { ( ) => closeBanner ( ) }
52
- >
35
+ < section className = "BannerRedirect container" >
36
+ < div className = "BannerRedirect__wrapper" >
37
+ < div className = "d-flex flex-direction-row" >
38
+ < h6 > { REDIRECT . title } </ h6 >
39
+ < button aria-label = "Close Banner" onClick = { closeBanner } >
53
40
< MdClose />
54
41
</ button >
55
42
</ div >
56
- < button className = 'BannerRedirect__wrapper__btn'
57
- onClick = { ( ) => closeBanner ( ) }
58
- >
59
- < a href = { userLanguage ?. startsWith ( 'es' )
60
- ? WEBSITES . ES
61
- : WEBSITES . EN }
62
- >
63
- { userLanguage ?. startsWith ( 'es' ) ? 'Vamos!' : 'Let´s go!' }
64
- </ a >
43
+ < button className = "BannerRedirect__wrapper__btn" onClick = { closeBanner } >
44
+ < a href = { REDIRECT . url } > { REDIRECT . callToAction } </ a >
65
45
</ button >
66
46
</ div >
67
47
</ section >
68
- ) ;
48
+ )
69
49
}
70
50
71
- export default BannerRedirect ;
51
+ export default BannerRedirect
0 commit comments