Skip to content

Commit

Permalink
Cookie Banner homepage (#2400)
Browse files Browse the repository at this point in the history
* Cookie Banner homepage

* Remove link to terms and add link cookies

* move buttons
  • Loading branch information
PopDaph authored Nov 6, 2023
1 parent 2820e9e commit ee7bfcc
Showing 1 changed file with 83 additions and 9 deletions.
92 changes: 83 additions & 9 deletions front/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {

const defaultFlexClasses = "flex flex-col gap-4";

import { Transition } from "@headlessui/react";

import {
SignInDropDownButton,
SignUpDropDownButton,
Expand Down Expand Up @@ -90,6 +92,9 @@ export default function Home({
const scrollRef3 = useRef<HTMLDivElement | null>(null);
const scrollRef4 = useRef<HTMLDivElement | null>(null);

const [showCookieBanner, setShowCookieBanner] = useState<boolean>(true);
const [hasAcceptedCookies, setHasAcceptedCookies] = useState<boolean>(false);

useEffect(() => {
if (logoRef.current) {
const logoPosition = logoRef.current.offsetTop;
Expand Down Expand Up @@ -752,21 +757,34 @@ export default function Home({
</div>

<Footer />
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${gaTrackingId}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
<CookieBanner
className="fixed bottom-4 right-4"
show={showCookieBanner}
onClickAccept={() => {
setHasAcceptedCookies(true);
setShowCookieBanner(false);
}}
onClickRefuse={() => {
setShowCookieBanner(false);
}}
/>
{hasAcceptedCookies && (
<>
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${gaTrackingId}`}
strategy="afterInteractive"
/>
<Script id="google-analytics" strategy="afterInteractive">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaTrackingId}');
`}
</Script>
</>
</Script>
</>
)}
</main>
</>
);
Expand Down Expand Up @@ -969,3 +987,59 @@ const Footer = () => {
</div>
);
};

const CookieBanner = ({
show,
onClickAccept,
onClickRefuse,
className,
}: {
show: boolean;
onClickAccept: () => void;
onClickRefuse: () => void;
className?: string;
}) => {
return (
<Transition
show={show}
enter="transition-opacity s-duration-300"
appear={true}
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-opacity duration-300"
leaveFrom="opacity-100"
leaveTo="opacity-0"
className={classNames(
"z-30 flex w-64 flex-col gap-3 rounded-xl border border-structure-100 bg-white p-4 shadow-xl",
className || ""
)}
>
<div className="text-sm font-normal text-element-900">
We use{" "}
<A variant="primary">
<Link
href="https://dust-tt.notion.site/Cookie-Policy-ec63a7fb72104a7babff1bf413e2c1ec"
target="_blank"
>
cookies
</Link>
</A>{" "}
to improve your experience on our site.
</div>
<div className="flex gap-2">
<Button
variant="tertiary"
size="sm"
label="Reject"
onClick={onClickRefuse}
/>
<Button
variant="primary"
size="sm"
label="Accept All"
onClick={onClickAccept}
/>
</div>
</Transition>
);
};

0 comments on commit ee7bfcc

Please sign in to comment.