Skip to content

Commit ec9d942

Browse files
committed
fix BannerRedirect
1 parent a7a8a33 commit ec9d942

File tree

2 files changed

+46
-55
lines changed

2 files changed

+46
-55
lines changed
Lines changed: 30 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,51 @@
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"
44

55
function BannerRedirect() {
6-
const [isOpen, setIsOpen] = useState(true);
6+
const [isOpen, setIsOpen] = useState(true)
77

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+
})
1513

1614
const closeBanner = () => {
17-
setIsOpen(false);
15+
setIsOpen(false)
1816

19-
if (typeof window !== 'undefined') {
20-
localStorage.setItem('BannerRedirect', 'closed')
17+
if (typeof window !== "undefined") {
18+
localStorage.setItem("BannerRedirect", "closed")
2119
}
22-
};
23-
24-
const userLanguage = typeof window !== 'undefined' ? navigator?.language : '';
25-
const userLocation = typeof window !== 'undefined' ? window?.location?.origin : ''
20+
}
2621

2722
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)
3329
}
34-
}, [userLanguage, userLocation]);
35-
36-
const bannerStorage = typeof window !== 'undefined'
37-
? localStorage.getItem('BannerRedirect')
38-
: undefined
30+
}, [])
3931

40-
if (bannerStorage === 'closed' || !isOpen) return null;
32+
if (!isOpen) return null
4133

4234
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}>
5340
<MdClose />
5441
</button>
5542
</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>
6545
</button>
6646
</div>
6747
</section>
68-
);
48+
)
6949
}
7050

71-
export default BannerRedirect;
51+
export default BannerRedirect

src/components/layout.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import * as React from "react"
1+
import React, { lazy, Suspense } from "react"
22
import Header from "./header"
33
import "./layout.scss"
44
import Footer from "./Footer/Footer"
55
import ScriptTag from "react-script-tag"
66
import useGlobalConfig from "../hooks/useGlobalConfig"
77
import ThemeProvider from "../context/themeContext"
8-
import { Helmet } from 'react-helmet';
9-
import BannerRedirect from "./BannerRedirect/BannerRedirect"
8+
import { Helmet } from "react-helmet"
9+
10+
const BannerRedirect = lazy(() => import("./BannerRedirect/BannerRedirect"))
1011

1112
const Layout = ({ children, options = {}, location }) => {
1213
const defaultOptions = {
@@ -16,6 +17,9 @@ const Layout = ({ children, options = {}, location }) => {
1617

1718
options = { ...defaultOptions, ...options }
1819

20+
const userLanguage =
21+
typeof window !== "undefined" ? navigator.language : undefined
22+
1923
const config = useGlobalConfig()
2024
const scripts = config?.allStrapiGlobalConfig?.nodes.map(item =>
2125
item?.script?.map(script =>
@@ -44,7 +48,11 @@ const Layout = ({ children, options = {}, location }) => {
4448
<ThemeProvider>
4549
{scripts}
4650
{options.hasHeader && <Header />}
47-
<BannerRedirect />
51+
{userLanguage?.startsWith("en") && (
52+
<Suspense fallback>
53+
<BannerRedirect />
54+
</Suspense>
55+
)}
4856
<Helmet>
4957
<script>
5058
{`
@@ -72,7 +80,10 @@ const Layout = ({ children, options = {}, location }) => {
7280
})();
7381
`}
7482
</script>
75-
<script src="https://leadbooster-chat.pipedrive.com/assets/loader.js" async></script>
83+
<script
84+
src="https://leadbooster-chat.pipedrive.com/assets/loader.js"
85+
async
86+
></script>
7687
</Helmet>
7788
<main>{children}</main>
7889
{options.hasFooter && <Footer />}

0 commit comments

Comments
 (0)