@@ -24,37 +24,37 @@ const variantFromMsgType = (type: MsgType) => {
24
24
} ;
25
25
26
26
export const GlobalSnackbar : FC = ( ) => {
27
- const [ open , setOpen ] = useState < boolean > ( false ) ;
28
- const [ notification , setNotification ] = useState < NotificationMsg > ( ) ;
29
-
27
+ const [ notificationMsg , setNotificationMsg ] = useState < NotificationMsg > ( ) ;
30
28
useCustomEvent < NotificationMsg > ( SnackbarEventType , ( event ) => {
31
- setNotification ( event . detail ) ;
32
- setOpen ( true ) ;
29
+ setNotificationMsg ( event . detail ) ;
33
30
} ) ;
34
31
35
- if ( ! notification ) {
32
+ const hasNotification = notificationMsg !== undefined ;
33
+ if ( ! hasNotification ) {
36
34
return null ;
37
35
}
38
36
39
37
return (
40
38
< EnterpriseSnackbar
41
- key = { notification . msg }
42
- open = { open }
43
- variant = { variantFromMsgType ( notification . msgType ) }
44
- onClose = { ( ) => setOpen ( false ) }
45
- autoHideDuration = { notification . msgType === MsgType . Error ? 22000 : 6000 }
39
+ key = { notificationMsg . msg }
40
+ open = { hasNotification }
41
+ variant = { variantFromMsgType ( notificationMsg . msgType ) }
42
+ onClose = { ( ) => setNotificationMsg ( undefined ) }
43
+ autoHideDuration = {
44
+ notificationMsg . msgType === MsgType . Error ? 22000 : 6000
45
+ }
46
46
anchorOrigin = { { vertical : "bottom" , horizontal : "right" } }
47
47
message = {
48
48
< div css = { { display : "flex" } } >
49
- { notification . msgType === MsgType . Error && (
49
+ { notificationMsg . msgType === MsgType . Error && (
50
50
< ErrorIcon css = { styles . errorIcon } />
51
51
) }
52
52
53
53
< div css = { { maxWidth : 670 } } >
54
- < span css = { styles . messageTitle } > { notification . msg } </ span >
54
+ < span css = { styles . messageTitle } > { notificationMsg . msg } </ span >
55
55
56
- { notification . additionalMsgs &&
57
- notification . additionalMsgs . map ( ( msg , index ) => (
56
+ { notificationMsg . additionalMsgs &&
57
+ notificationMsg . additionalMsgs . map ( ( msg , index ) => (
58
58
< AdditionalMessageDisplay key = { index } message = { msg } />
59
59
) ) }
60
60
</ div >
0 commit comments