Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom styles, other small touch-ups, hide the cookie consent when close btn is pressed #1165

Merged
merged 4 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions app/scripts/components/common/cookie-consent/index.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#cookie-consent{

@media screen and (min-width: 768px) {
bottom: 0;
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved
right: 0;
}
}

.hide-modal {
transition: bottom 1.125s ease-in-out 0.125s, opacity 1s ease-in-out 0.125s;
}

.close {
& svg {
@media screen and (min-width: 768px) {
right: -50px;
}
}
.animation--fade-out {
transition: opacity 0.5s ease-in-out 0.125s;
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved
}
28 changes: 16 additions & 12 deletions app/scripts/components/common/cookie-consent/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from 'react';

import { Icon } from '@trussworks/react-uswds';
import {
USWDSAlert,
Expand Down Expand Up @@ -38,41 +37,46 @@ export const CookieConsent = ({
)}; path=/; expires=${closeConsent ? '0' : setCookieExpiration()}`;
};

const addAttribute = copy && copy?.replaceAll('<a', `<a target="_blank" rel="noopener" role="link"`);
const addAttribute =
copy &&
copy?.replaceAll('<a', `<a target="_blank" rel="noopener" role="link"`);
useEffect(() => {
const cookieValue = {
responded: cookieConsentResponded,
answer: cookieConsentAnswer
};
setCookie(cookieValue, closeConsent);
onFormInteraction();
}, [cookieConsentResponded, cookieConsentAnswer]);
}, [cookieConsentResponded, cookieConsentAnswer, closeConsent]);
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved

return (
<div
id='cookie-consent'
className={`margin-2 shadow-2 position-fixed z-top maxw-tablet-lg bottom-65px ${
cookieConsentResponded || closeConsent
? 'hide-modal bottom-neg-500 '
: ''
className={`margin-0 tablet:margin-2 shadow-2 position-fixed z-top maxw-full tablet:maxw-tablet-lg animation--fade-out right-0 bottom-0 ${
cookieConsentResponded || closeConsent ? ' opacity-0' : 'opacity-1'
}`}
>
<USWDSAlert
type='info'
heading={title && title}
headingLevel='h1'
headingLevel='h2'
hanbyul-here marked this conversation as resolved.
Show resolved Hide resolved
noIcon={true}
className='radius-lg'
>
<USWDSButton
type='button'
className='usa-modal__close close padding-0'
type='button '
className='width-3 height-3 padding-0 position-absolute right-2 top-2'
onClick={() => {
setCloseConsent(true);
}}
unstyled
>
<Icon.Close />
<Icon.Close size={3} />
</USWDSButton>
{addAttribute && <div dangerouslySetInnerHTML={{ __html: addAttribute }} />}

{addAttribute && (
<div dangerouslySetInnerHTML={{ __html: addAttribute }} />
)}
<USWDSButtonGroup className='padding-top-2'>
<USWDSButton
onClick={() => {
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/components/common/cookie-consent/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const NO_COOKIE = 'NO COOKIE';
export const COOKIE_CONSENT_KEY = `veda--CookieConsent`;
10 changes: 6 additions & 4 deletions app/scripts/components/common/layout-root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import MetaTags from '../meta-tags';
import PageFooter from '../page-footer';
import Banner from '../banner';
import { CookieConsent } from '../cookie-consent';
import { COOKIE_CONSENT_KEY, NO_COOKIE } from '../cookie-consent/utils';

import { LayoutRootContext } from './context';

Expand Down Expand Up @@ -52,26 +53,27 @@ function LayoutRoot(props: { children?: ReactNode }) {
}
return null;
};
const { children } = props;

const getCookie = () => {
const cookie = readCookie('CookieConsent');
const cookie = readCookie(COOKIE_CONSENT_KEY);
if (cookie) {
const cookieContents = JSON.parse(cookie);
if (cookieContents.answer) setGoogleTagManager();
return cookieContents;
}
return 'NO COOKIE';
return NO_COOKIE;
};

const showForm = () => {
const cookieContents = getCookie();
if (cookieContents === 'NO COOKIE') {
if (cookieContents === NO_COOKIE) {
return true;
} else {
return !cookieContents.responded;
}
};
const { children } = props;


useEffect(() => {
!cookieConsentContent && setGoogleTagManager();
Expand Down
Loading