1+ import React , { useState , useEffect } from 'react' ;
2+ import styles from './styles.module.css' ;
3+ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
4+ import { faArrowUpRightFromSquare , faTimes } from "@fortawesome/free-solid-svg-icons" ;
5+ import notificationConfig from '../../config/notification.json' ;
6+
7+ const GlobalNotification = ( ) => {
8+ const [ isVisible , setIsVisible ] = useState ( false ) ;
9+ const [ isAnimating , setIsAnimating ] = useState ( false ) ;
10+
11+ // Don't render if notification is disabled in config
12+ if ( ! notificationConfig . enabled ) return null ;
13+
14+ useEffect ( ( ) => {
15+ const dismissed = localStorage . getItem ( 'eks-workshop-notification-dismissed' ) ;
16+ if ( ! dismissed ) {
17+ setIsVisible ( true ) ;
18+ setTimeout ( ( ) => setIsAnimating ( true ) , 100 ) ;
19+ }
20+ } , [ ] ) ;
21+
22+ const handleDismiss = ( ) => {
23+ setIsAnimating ( false ) ;
24+ setTimeout ( ( ) => {
25+ setIsVisible ( false ) ;
26+ localStorage . setItem ( 'eks-workshop-notification-dismissed' , 'true' ) ;
27+ } , 300 ) ;
28+ } ;
29+
30+ if ( ! isVisible ) return null ;
31+
32+ return (
33+ < div className = { `${ styles . notification } ${ isAnimating ? styles . notificationVisible : '' } ` } >
34+ < span className = { styles . notificationText } >
35+ < b > { notificationConfig . prefix } </ b > { notificationConfig . text } { " " }
36+ < a
37+ href = { notificationConfig . linkUrl }
38+ target = "_blank"
39+ rel = "noopener noreferrer"
40+ >
41+ { notificationConfig . linkText } < FontAwesomeIcon
42+ icon = { faArrowUpRightFromSquare }
43+ className = { styles . linkIcon }
44+ />
45+ </ a >
46+ </ span >
47+ < button
48+ className = { styles . dismissButton }
49+ onClick = { handleDismiss }
50+ aria-label = "Dismiss notification"
51+ >
52+ < FontAwesomeIcon icon = { faTimes } />
53+ </ button >
54+ </ div >
55+ ) ;
56+ } ;
57+
58+ export default GlobalNotification ;
0 commit comments