Skip to content

Commit

Permalink
Merge pull request #52 from marbiano/accept-cookies
Browse files Browse the repository at this point in the history
Accept cookies functionality
  • Loading branch information
okbel committed Nov 5, 2020
2 parents 55f6cf8 + df562cb commit b6160b4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.root {
@apply text-center p-6 bg-primary text-sm flex-row justify-center items-center font-medium fixed bottom-0 w-full z-30;
@apply text-center p-6 bg-primary text-sm flex-row justify-center items-center font-medium fixed bottom-0 w-full z-30 transition-all duration-300 ease-out;

@screen md {
@apply flex text-left;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import cn from 'classnames'
import { FC } from 'react'
import s from './FeatureBar.module.css'

import s from './Featurebar.module.css'

interface Props {
interface FeatureBarProps {
className?: string
title: string
description?: string
hide?: boolean
action?: React.ReactNode
}

const Featurebar: FC<Props> = ({
const FeatureBar: React.FC<FeatureBarProps> = ({
title,
description,
className,
Expand All @@ -21,7 +19,9 @@ const Featurebar: FC<Props> = ({
const rootClassName = cn(
s.root,
{
'transition-transform transform duration-500 ease-out translate-y-full': hide,
transform: true,
'translate-y-0 opacity-100': !hide,
'translate-y-full opacity-0': hide,
},
className
)
Expand All @@ -36,4 +36,4 @@ const Featurebar: FC<Props> = ({
)
}

export default Featurebar
export default FeatureBar
1 change: 1 addition & 0 deletions components/common/FeatureBar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './FeatureBar'
1 change: 0 additions & 1 deletion components/common/Featurebar/index.ts

This file was deleted.

10 changes: 6 additions & 4 deletions components/common/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import cn from 'classnames'
import { useRouter } from 'next/router'
import type { Page } from '@bigcommerce/storefront-data-hooks/api/operations/get-all-pages'
import { CommerceProvider } from '@bigcommerce/storefront-data-hooks'
import { useAcceptCookies } from '@lib/hooks/useAcceptCookies'
import { CartSidebarView } from '@components/cart'
import { Container, Sidebar, Button, Modal, Toast } from '@components/ui'
import { Navbar, Featurebar, Footer } from '@components/common'
import { Navbar, FeatureBar, Footer } from '@components/common'
import { LoginView, SignUpView, ForgotPassword } from '@components/auth'
import { useUI } from '@components/ui/context'
import { usePreventScroll } from '@react-aria/overlays'
Expand All @@ -28,7 +29,7 @@ const Layout: FC<Props> = ({ children, pageProps }) => {
closeToast,
displayToast,
} = useUI()
const [acceptedCookies, setAcceptedCookies] = useState(false)
const { acceptedCookies, onAcceptCookies } = useAcceptCookies()
const [hasScrolled, setHasScrolled] = useState(false)
const { locale = 'en-US' } = useRouter()

Expand Down Expand Up @@ -78,15 +79,16 @@ const Layout: FC<Props> = ({ children, pageProps }) => {
{modalView === 'SIGNUP_VIEW' && <SignUpView />}
{modalView === 'FORGOT_VIEW' && <ForgotPassword />}
</Modal>
<Featurebar
<FeatureBar
title="This site uses cookies to improve your experience. By clicking, you agree to our Privacy Policy."
hide={acceptedCookies}
action={
<Button className="mx-5" onClick={() => setAcceptedCookies(true)}>
<Button className="mx-5" onClick={onAcceptCookies}>
Accept cookies
</Button>
}
/>

{/* <Toast open={displayToast} onClose={closeModal}>
{toastText}
</Toast> */}
Expand Down
2 changes: 1 addition & 1 deletion components/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default as Avatar } from './Avatar'
export { default as Featurebar } from './Featurebar'
export { default as FeatureBar } from './FeatureBar'
export { default as Footer } from './Footer'
export { default as Layout } from './Layout'
export { default as Navbar } from './Navbar'
Expand Down
26 changes: 26 additions & 0 deletions lib/hooks/useAcceptCookies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect, useState } from 'react'
import Cookies from 'js-cookie'

const COOKIE_NAME = 'accept_cookies'

export const useAcceptCookies = () => {
const [acceptedCookies, setAcceptedCookies] = useState(true)

useEffect(() => {
if (!Cookies.get(COOKIE_NAME)) {
setAcceptedCookies(false)
}
}, [])

const acceptCookies = () => {
setAcceptedCookies(true)
Cookies.set(COOKIE_NAME, 'accepted', {
expires: 365,
})
}

return {
acceptedCookies,
onAcceptCookies: acceptCookies,
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"bowser": "^2.11.0",
"classnames": "^2.2.6",
"email-validator": "^2.0.4",
"js-cookie": "^2.2.1",
"keen-slider": "^5.2.4",
"lodash.debounce": "^4.0.8",
"lodash.random": "^3.2.0",
Expand All @@ -37,6 +38,7 @@
"@types/bunyan": "^1.8.6",
"@types/bunyan-prettystream": "^0.1.31",
"@types/classnames": "^2.2.10",
"@types/js-cookie": "^2.2.6",
"@types/lodash.debounce": "^4.0.6",
"@types/lodash.random": "^3.2.6",
"@types/node": "^14.11.2",
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,11 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884"
integrity sha512-jnqIUKDUqJbDIUxm0Uj7bnlMnRm1T/eZ9N+AVMqhPgzrba2GhGG5o/jCTwmdPK709nEZsGoMzXEDUjcXHa3W0g==

"@types/js-cookie@^2.2.6":
version "2.2.6"
resolved "https://registry.yarnpkg.com/@types/js-cookie/-/js-cookie-2.2.6.tgz#f1a1cb35aff47bc5cfb05cb0c441ca91e914c26f"
integrity sha512-+oY0FDTO2GYKEV0YPvSshGq9t7YozVkgvXLty7zogQNuCxBhT9/3INX9Q7H1aRZ4SUDRXAKlJuA4EA5nTt7SNw==

"@types/json-schema@*", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
version "7.0.6"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
Expand Down Expand Up @@ -3626,7 +3631,7 @@ jest-worker@^26.6.1:
merge-stream "^2.0.0"
supports-color "^7.0.0"

js-cookie@2.2.1:
js-cookie@2.2.1, js-cookie@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.1.tgz#69e106dc5d5806894562902aa5baec3744e9b2b8"
integrity sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==
Expand Down

1 comment on commit b6160b4

@vercel
Copy link

@vercel vercel bot commented on b6160b4 Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.