Skip to content

Commit 63b24f0

Browse files
authored
YH-729: added cookie warning to landing page (#438)
* YH-729: added cookie warning to landing page * YH-729: fixed styles and added Text according to review
1 parent 1867b1d commit 63b24f0

File tree

6 files changed

+140
-0
lines changed

6 files changed

+140
-0
lines changed

Diff for: public/locales/ru/landing.json

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
"second": "Определите свой текущий уровень и выявите пробелы в знаниях для более целенаправленного обучения или подготовки к поиску работы."
8080
}
8181
},
82+
"cookies": {
83+
"text": "Этот сайт использует файлы cookie для улучшения пользовательского опыта. Продолжая пользоваться сайтом вы даёте согласие на использование файлов cookie.",
84+
"link": "Подробнее",
85+
"agree.button": "Согласиться"
86+
},
8287
"footer": {
8388
"slogan": "Выбери, каким будет IT завтра, вместе c нами",
8489
"about": "YeaHub — это полностью открытый проект, призванный объединить и улучшить IT-сферу. Наш исходный код доступен для просмотра на GitHub. Дизайн проекта также открыт для ознакомления в Figma.",

Diff for: src/app/layouts/LandingLayout/ui/LandingLayout.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Suspense } from 'react';
22
import { Outlet } from 'react-router-dom';
33

4+
import { CookiesWarning } from '@/widgets/Landing/CookiesWarningBlock';
45
import { Footer } from '@/widgets/Landing/Footer';
56
import { Header } from '@/widgets/Landing/Header';
67

@@ -16,6 +17,7 @@ export const LandingLayout = () => {
1617
</Suspense>
1718
</div>
1819
<Footer />
20+
<CookiesWarning />
1921
</div>
2022
);
2123
};

Diff for: src/shared/config/i18n/i18nTranslations.ts

+3
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ export enum Landing {
490490
PROGRESS_SUBTITLE = 'progress.subtitle',
491491
PROGRESS_ADVANTAGES_FIRST = 'progress.advantages.first',
492492
PROGRESS_ADVANTAGES_SECOND = 'progress.advantages.second',
493+
COOKIES_TEXT = 'cookies.text',
494+
COOKIES_LINK = 'cookies.link',
495+
COOKIES_AGREE = 'cookies.agree.button',
493496
FOOTER_SLOGAN = 'footer.slogan',
494497
FOOTER_ABOUT = 'footer.about',
495498
FOOTER_DOCS = 'footer.docs',

Diff for: src/widgets/Landing/CookiesWarningBlock/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { CookiesWarning } from './ui/CookiesWarning';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.wrapper {
2+
position: fixed;
3+
bottom: 0;
4+
z-index: 1000;
5+
gap: 10px;
6+
margin: 20px;
7+
padding: 24px;
8+
width: 90%;
9+
max-width: 1120px;
10+
min-height: 96px;
11+
box-shadow: 0 4px 10px 0 rgba(106 99 118 0.10);
12+
border-radius: 24px;
13+
background-color: var(--color-white-900);
14+
}
15+
16+
.cookie-wrapper{
17+
display: flex;
18+
justify-content: space-between;
19+
align-items: center;
20+
gap: 10px;
21+
width: 100%;
22+
}
23+
24+
.text {
25+
width: 773px;
26+
}
27+
28+
.link{
29+
display: inline;
30+
}
31+
32+
.btn{
33+
flex-shrink: 0;
34+
width: 256px;
35+
font-size: var(--font-size-p-l);
36+
}
37+
38+
@media (width < 1024px) {
39+
.wrapper {
40+
max-width: 708px;
41+
min-height: 124px;
42+
}
43+
44+
.btn{
45+
width: 170px;
46+
}
47+
}
48+
49+
@media (width <= 768px) {
50+
.wrapper {
51+
right: 0;
52+
left: 0;
53+
margin: 20px auto;
54+
max-width: 328px;
55+
min-height: auto;
56+
}
57+
58+
.text {
59+
width: 280px;
60+
}
61+
62+
.cookie-wrapper{
63+
flex-direction: column;
64+
align-items: flex-start;
65+
gap: 16px;
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { useEffect, useRef, useState } from 'react';
2+
import { createPortal } from 'react-dom';
3+
import { useTranslation } from 'react-i18next';
4+
5+
import { i18Namespace } from '@/shared/config/i18n';
6+
import { Landing } from '@/shared/config/i18n/i18nTranslations';
7+
import { Button } from '@/shared/ui/Button';
8+
import { Text } from '@/shared/ui/Text';
9+
10+
import styles from './CookiesWarning.module.css';
11+
12+
const createPortalRoot = () => {
13+
const cookieRoot = document.createElement('div');
14+
cookieRoot.setAttribute('id', 'cookie-root');
15+
16+
return cookieRoot;
17+
};
18+
19+
export const CookiesWarning = () => {
20+
const { t } = useTranslation(i18Namespace.landing);
21+
22+
const portalRootRef = useRef(document.getElementById('cookie-root') || createPortalRoot());
23+
const [isAgreed, setIsAgreed] = useState(false);
24+
25+
useEffect(() => {
26+
if (!isAgreed) {
27+
document.querySelector('body')!.appendChild(portalRootRef.current);
28+
const portal = portalRootRef.current;
29+
30+
return () => {
31+
portal.remove();
32+
};
33+
}
34+
}, [isAgreed]);
35+
36+
const handleClick = () => {
37+
setIsAgreed(true);
38+
};
39+
40+
return createPortal(
41+
<div role="alert" className={styles.wrapper}>
42+
<div className={styles['cookie-wrapper']}>
43+
<Text className={styles.text} variant="body3" color="black-700">
44+
{t(Landing.COOKIES_TEXT)}{' '}
45+
<a
46+
rel="noopener noreferrer"
47+
href="https://docs.google.com/document/d/19JvySToaMm3pkohGkHwqhJjGl3IzldIc3qnQpAoVFVc/edit?tab=t.0#heading=h.gjdgxs"
48+
target="_blank"
49+
>
50+
<Text className={styles.link} variant="body3" color="purple-700">
51+
{t(Landing.COOKIES_LINK)}
52+
</Text>
53+
</a>
54+
</Text>
55+
<Button className={styles.btn} variant="primary" onClick={handleClick}>
56+
{t(Landing.COOKIES_AGREE)}
57+
</Button>
58+
</div>
59+
</div>,
60+
portalRootRef.current,
61+
);
62+
};

0 commit comments

Comments
 (0)