Skip to content

Commit

Permalink
Changed the behavior of cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Chelakhovl committed Dec 20, 2024
1 parent 8501cfb commit 66cfc90
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 97 deletions.
15 changes: 5 additions & 10 deletions FrontEnd/src/components/CookieAcception/CookieMod.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import { useCookies } from 'react-cookie';
import { Link } from 'react-router-dom';
Expand All @@ -7,11 +7,7 @@ import styles from './CookieMod.module.css';
const CookieMod = ({ active, setActive }) => {
const [cookies, setCookie] = useCookies(['cookies']);

useEffect(() => {
if (cookies.cookies !== undefined) {
setActive(false);
}
}, [cookies, setActive]);
const shouldShowModal = cookies.cookies === undefined;

const allowCookies = () => {
const expirationDate = new Date();
Expand All @@ -26,8 +22,7 @@ const CookieMod = ({ active, setActive }) => {
setCookie('cookies', false, { expires: expirationDate, sameSite: 'lax' });
setActive(false);
};

return active ? (
return shouldShowModal && active ? (
<div className={styles['cookie-banner']} data-testid="cookiemodal">
<div className={styles['cookie-content']}>
<div className={styles['cookie-header']}>
Expand All @@ -43,11 +38,11 @@ const CookieMod = ({ active, setActive }) => {
</p>
<p className={styles['cookie-text']}>
Дізнатися більше
<Link to="privacy-policy/" className={styles['cookie-link']}>
<Link to="/privacy-policy" className={styles['cookie-link']}>
про файли cookie.
</Link>
</p>
<div className={styles['cookie-buttons']} >
<div className={styles['cookie-buttons']}>
<button className={styles['allow-all-btn']} onClick={allowCookies}>
Дозволити
</button>
Expand Down
187 changes: 100 additions & 87 deletions FrontEnd/src/routes/ClientRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ToastContainer } from 'react-toastify';
import { Route, Routes, Navigate } from 'react-router-dom';
import { ConfigProvider } from 'antd';
import { SWRConfig } from 'swr';
import React, { useState } from 'react';

import 'react-toastify/dist/ReactToastify.css';
import customTheme from '../pages/CustomThemes/customTheme.js';
Expand All @@ -12,6 +13,7 @@ import CookiesPolicyComponent from '../pages/CookiesPolicyPage/CookiesPolicyComp
import Footer from '../components/Footer/Footer';
import Header from '../components/Header/Header';
import Loader from '../components/Loader/Loader';
import CookieMod from '../components/CookieAcception/CookieMod';
import MainPage from '../pages/LandingPage/MainPage';
import PrivacyPolicy from '../pages/PrivacyPolicyPage/PrivacyPolicyPage';
import ProfileDetailPage from '../pages/ProfileDetail/ProfileDetailPage';
Expand Down Expand Up @@ -39,6 +41,7 @@ import PageWrapper from '../components/PageWrapper/PageWrapper';

function ClientRouter() {
const { isAuth, user, logout, isLoading } = useAuth();
const [isCookieModalActive, setCookieModalActive] = useState(true);

return (
<ConfigProvider theme={customTheme}>
Expand All @@ -57,98 +60,108 @@ function ClientRouter() {
{isLoading ? (
<Loader />
) : (
<PageWrapper>
<Routes>
<Route path="/" element={<MainPage isAuthorized={isAuth} />} />
<Route path="/about-us" element={<AboutUsPage />} />
{isAuth ? (
<Route path="/profile/*" element={<ProfilePage />} />
) : (
<Route path="/profile/*" element={<Navigate to="/" />} />
)}
<Route
path="/profile-detail/:id"
element={<ProfileDetailPage isAuthorized={isAuth} />}
/>
<Route
path="/profiles"
element={<ProfileListPage isAuthorized={isAuth} isSaved={false}/>}
/>
<Route
path="/profiles/saved"
element={<ProfileListPage isAuthorized={isAuth} isSaved={true}/>}
/>
{isAuth ? (
<>
<CookieMod
active={isCookieModalActive}
setActive={setCookieModalActive}
/>
<PageWrapper>
<Routes>
<Route path="/" element={<MainPage isAuthorized={isAuth} />} />
<Route path="/about-us" element={<AboutUsPage />} />
{isAuth ? (
<Route path="/profile/*" element={<ProfilePage />} />
) : (
<Route path="/profile/*" element={<Navigate to="/" />} />
)}
<Route
path="/login"
element={<Navigate to="/profile/user-info" />}
path="/profile-detail/:id"
element={<ProfileDetailPage isAuthorized={isAuth} />}
/>
) : (
<Route path="/login" element={<LoginPage />} />
)}
{isAuth ? (
<Route
path="/sign-up"
element={<Navigate to="/profile/user-info" />}
path="/profiles"
element={
<ProfileListPage isAuthorized={isAuth} isSaved={false} />
}
/>
) : (
<Route path="/sign-up" element={<SignUpPage />} />
)}
<Route
path="/sign-up/completion"
element={<SignUpCompletionPage />}
/>
<Route
path="/sign-up/resend-activation"
element={<ResendActivationPage />}
/>
<Route
path="/activate/:uid/:token"
element={<ActivateProfilePage />}
/>
<Route
path="/reset-password"
element={<SendEmailForgotPasswordPage />}
/>
<Route
path="/reset-password/completion"
element={<ForgotPasswordCompletionPage />}
/>
<Route
path="/password/reset/confirm/:uid/:token"
element={<RestorePasswordPage />}
/>
<Route
path="/reset-password/successfully"
element={<RestorePasswordSuccessPage />}
/>
<Route
path="/reset-password/failed"
element={<RestorePasswordFailedPage />}
/>
<Route path="/privacy-policy" element={<PrivacyPolicy />} />
<Route
path="/terms-and-conditions"
element={<TermsAndConditions />}
/>
<Route
path="/cookies-policy"
element={<CookiesPolicyComponent />}
/>
<Route path="/contact" element={<Contact />} />
<Route
path="/search"
element={<Search isAuthorized={isAuth} userData={user} />}
/>
<Route
path="/moderation/:id/:action"
element={<ModerationModal />}
/>
<Route path="*" element={<ErrorPage404 />} />
</Routes>
</PageWrapper>
<Route
path="/profiles/saved"
element={
<ProfileListPage isAuthorized={isAuth} isSaved={true} />
}
/>
{isAuth ? (
<Route
path="/login"
element={<Navigate to="/profile/user-info" />}
/>
) : (
<Route path="/login" element={<LoginPage />} />
)}
{isAuth ? (
<Route
path="/sign-up"
element={<Navigate to="/profile/user-info" />}
/>
) : (
<Route path="/sign-up" element={<SignUpPage />} />
)}
<Route
path="/sign-up/completion"
element={<SignUpCompletionPage />}
/>
<Route
path="/sign-up/resend-activation"
element={<ResendActivationPage />}
/>
<Route
path="/activate/:uid/:token"
element={<ActivateProfilePage />}
/>
<Route
path="/reset-password"
element={<SendEmailForgotPasswordPage />}
/>
<Route
path="/reset-password/completion"
element={<ForgotPasswordCompletionPage />}
/>
<Route
path="/password/reset/confirm/:uid/:token"
element={<RestorePasswordPage />}
/>
<Route
path="/reset-password/successfully"
element={<RestorePasswordSuccessPage />}
/>
<Route
path="/reset-password/failed"
element={<RestorePasswordFailedPage />}
/>
<Route path="/privacy-policy" element={<PrivacyPolicy />} />
<Route
path="/terms-and-conditions"
element={<TermsAndConditions />}
/>
<Route
path="/cookies-policy"
element={<CookiesPolicyComponent />}
/>
<Route path="/contact" element={<Contact />} />
<Route
path="/search"
element={<Search isAuthorized={isAuth} userData={user} />}
/>
<Route
path="/moderation/:id/:action"
element={<ModerationModal />}
/>
<Route path="*" element={<ErrorPage404 />} />
</Routes>
</PageWrapper>
</>
)}
<Footer />
<Footer />
<ToastContainer
position="top-right"
autoClose={3000}
Expand Down

0 comments on commit 66cfc90

Please sign in to comment.