1
+ import React , { FC , useEffect , useState } from 'react' ;
2
+
3
+ const localStorageKey = 'modal-has-been-shown'
4
+
5
+ const Modal : FC = ( ) => {
6
+ const [ show , setShow ] = useState < boolean > ( ) ;
7
+
8
+ useEffect ( ( ) => {
9
+ if ( window ) {
10
+ const localStorageValue = localStorage . getItem ( localStorageKey )
11
+ if ( ! localStorageValue ) {
12
+ setShow ( true )
13
+ localStorage . setItem ( localStorageKey , 'true' )
14
+ }
15
+ }
16
+ } , [ ] ) ;
17
+
18
+ const handleModalClose = ( ) : void => {
19
+ setShow ( false )
20
+ }
21
+
22
+ if ( ! show ) {
23
+ return null
24
+ }
25
+
26
+ return < div className = 'modal' >
27
+ < div className = 'modal__content' >
28
+ < div className = 'modal__content__header' >
29
+ < strong > Caution!</ strong >
30
+ </ div >
31
+ < div className = 'modal__content__content' >
32
+ < p > The application shows flashing colors.</ p >
33
+ < p > Please, keep the color mode "off", if you are affected by it.</ p >
34
+ </ div >
35
+ < div className = 'modal__content__footer' >
36
+ < button type = "button" onClick = { handleModalClose } > Close</ button >
37
+ </ div >
38
+ </ div >
39
+ </ div >
40
+ }
41
+
42
+ export default Modal ;
0 commit comments