Skip to content

Commit

Permalink
Merge pull request #77 from JimTheCat/CU-8692r5m3u_Add-cookie-notific…
Browse files Browse the repository at this point in the history
…ation-and-logic-for-cookies_Patryk-Kosiski

feature: Create cookie notification
  • Loading branch information
JimTheCat authored Dec 14, 2024
2 parents aa8d7e2 + e5ffe67 commit ec3d26c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
43 changes: 43 additions & 0 deletions frontend/src/Components/CookiesPopup/CookiesPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {useEffect, useState} from 'react';
import {Button, Group, Modal, Text, UnstyledButton} from '@mantine/core';

export const CookiesPopup = () => {
const [opened, setOpened] = useState<boolean>(false);

useEffect(() => {
const hasAcceptedCookies = localStorage.getItem('cookiesAccepted');
if (!hasAcceptedCookies && !window.location.pathname.includes('/privacy')) {
setOpened(true);
}
}, []);

const handleAccept = () => {
localStorage.setItem('cookiesAccepted', 'true'); // Save to local storage
setOpened(false);
};

return (
<Modal
opened={opened}
onClose={() => setOpened(false)}
title="Używamy ciasteczek 🍪"
centered
closeOnEscape={false}
closeOnClickOutside={false}
withCloseButton={false}
size="md"
>
<Text>
Nasza strona korzysta z ciasteczek w celu zapewnienia najlepszej jakości usług. Kontynuując
przeglądanie, akceptujesz naszą <UnstyledButton c={'blue'} onClick={() => window.open("/privacy", '_blank')}>politykę
prywatności</UnstyledButton>.
</Text>

<Group justify="flex-end" mt="md">
<Button onClick={handleAccept} color="blue">
Akceptuję
</Button>
</Group>
</Modal>
);
}
1 change: 1 addition & 0 deletions frontend/src/Components/CookiesPopup/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CookiesPopup.tsx';
1 change: 1 addition & 0 deletions frontend/src/Pages/Root/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const Root = () => {
<Route path="/login" element={<Login/>}/>
<Route path="/register" element={<Register/>}/>
<Route path="/passwordrecovery" element={<Recovery/>}/>
<Route path="/privacy" element={<div>Privacy</div>}/>
</Route>

{/*Protected routes*/}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {BrowserRouter} from "react-router-dom";
import {I18nextProvider} from "react-i18next";
import {i18nInitializer} from "./Services/Utils";
import {ThemeProvider} from "./Providers/ThemeProvider.tsx";
import {CookiesPopup} from "./Components/CookiesPopup";

i18nInitializer();

Expand All @@ -27,6 +28,7 @@ createRoot(document.getElementById('root')!).render(
<ThemeProvider>
<BrowserRouter>
<I18nextProvider i18n={i18next}>
<CookiesPopup/>
<App/>
</I18nextProvider>
</BrowserRouter>
Expand Down

0 comments on commit ec3d26c

Please sign in to comment.