1+ import React , { useEffect , useState } from "react" ;
2+ import Link from "next/link" ;
3+ import {
4+ Alert ,
5+ Button ,
6+ Chip ,
7+ Typography
8+ } from "@material-tailwind/react" ;
9+
10+ const OFFER_STORAGE_KEY = "hideOfferBar" ;
11+
12+ export function OfferBar ( ) {
13+
14+ const [ isVisible , setIsVisible ] = useState ( false ) ;
15+
16+
17+ useEffect ( ( ) => {
18+ const shouldHide = localStorage . getItem ( OFFER_STORAGE_KEY ) ;
19+ if ( ! shouldHide ) {
20+ setIsVisible ( true ) ;
21+ }
22+
23+ const hideUntil = Number ( shouldHide ) ;
24+ const now = new Date ( ) . getTime ( ) ;
25+ if ( hideUntil && now > hideUntil ) {
26+ setIsVisible ( true ) ;
27+ }
28+ } , [ ] ) ;
29+
30+ const handleClose = ( ) => {
31+ setIsVisible ( false ) ;
32+ // add 2 days
33+ const hideUntil = new Date ( ) . getTime ( ) + 2 * 24 * 60 * 60 * 1000 ;
34+ localStorage . setItem ( OFFER_STORAGE_KEY , hideUntil . toString ( ) ) ;
35+ } ;
36+
37+
38+ function Icon ( ) {
39+ return (
40+ < svg xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" className = "h-6 w-6" stroke-width = "2" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M6 18L18 6M6 6l12 12" > </ path > </ svg >
41+ ) ;
42+ }
43+
44+ return (
45+ < >
46+ { isVisible && (
47+ < Alert variant = "ghost" className = "w-full bg-blue-gray-50 justify-center rounded-none" >
48+
49+ < div className = "flex flex-wrap items-center justify-center !text-blue-gray-900" >
50+ < Link href = "/blocks" className = "font-medium m-0 flex items-center" >
51+ < Chip variant = "outlined" value = "NEW" className = "mr-2 !text-blue-gray-900 py-1 px-2" /> Material Tailwind Blocks</ Link > , a comprehensive compilation of < Typography className = "font-bold mx-1" > 170+</ Typography >
52+ blocks, now available for your use.
53+
54+ < Link href = "/blocks" className = "font-bold" >
55+ Check out
56+ →
57+ </ Link >
58+ < button className = "font-bold ml-10 mb-0 !text-grey-900"
59+ onClick = { ( ) => handleClose ( ) }
60+ >
61+ < Icon />
62+ </ button >
63+ </ div >
64+ </ Alert >
65+ ) }
66+ </ >
67+ ) ;
68+ }
69+
70+ export default OfferBar ;
0 commit comments