All files / owid-grapher/site CookieNotice.tsx

14.04% Statements 8/57
100% Branches 0/0
0% Functions 0/1
14.04% Lines 8/57

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 671x 1x 1x 1x 1x 1x 1x 1x                                                                                                                      
import * as React from "react"
import { useEffect, useState } from "react"
import classnames from "classnames"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faCheck } from "@fortawesome/free-solid-svg-icons/faCheck"
import { Action, getTodayDate } from "./CookiePreferencesManager"
 
export const CookieNotice = ({
    accepted,
    outdated,
    dispatch,
}: {
    accepted: boolean
    outdated: boolean
    dispatch: any
}) => {
    const [mounted, setMounted] = useState(false)

    useEffect(() => {
        setTimeout(() => {
            setMounted(true)
        }, 200)
    }, [])

    return (
        <div
            className={classnames("cookie-notice", {
                open: mounted && (!accepted || outdated),
            })}
            data-test="cookie-notice"
        >
            <div className="wrapper">
                <div className="owid-row">
                    <div className="owid-col owid-col--lg-1 explanation">
                        <p>
                            We use cookies to give you the best experience on
                            our website. By continuing without changing your
                            cookie settings, we assume you agree to this.
                        </p>
                    </div>
                    <div className="owid-col owid-col--lg-0 actions">
                        <a href="/privacy-policy" className="button">
                            Manage preferences
                        </a>
                        <button
                            className="button accept"
                            onClick={() =>
                                dispatch({
                                    type: Action.Accept,
                                    payload: { date: getTodayDate() },
                                })
                            }
                            data-test="accept"
                            data-track-note="cookie-notice"
                        >
                            <span className="icon">
                                <FontAwesomeIcon icon={faCheck} />
                            </span>
                            I agree
                        </button>
                    </div>
                </div>
            </div>
        </div>
    )
}