@@ -13,36 +13,44 @@ import { useDispatch, useSelector } from "react-redux";
13
13
import { Container , Message , Transition } from "semantic-ui-react" ;
14
14
import PropTypes from "prop-types" ;
15
15
16
- import { clearError } from "../actions" ;
17
- import { getError } from "../selectors" ;
16
+ import { clearNotification } from "../actions" ;
17
+ import { getNotification } from "../selectors" ;
18
18
19
19
import styles from "./Notification.module.scss" ;
20
20
21
21
const AUTO_CLOSE_TIMEOUT = 16000 ;
22
22
23
- export default function Notification ( { icon, header, message, closable } ) {
23
+ export default function Notification ( {
24
+ icon,
25
+ header,
26
+ message,
27
+ closable,
28
+ error,
29
+ success,
30
+ } ) {
24
31
const dispatch = useDispatch ( ) ;
25
- const error = useSelector ( getError ) ;
32
+ const notification = useSelector ( getNotification ) ;
26
33
const timer = useRef ( null ) ;
27
34
28
- const hide = ( ) => dispatch ( clearError ) ;
29
- const visible = message || error ? true : false ;
35
+ const hide = ( ) => dispatch ( clearNotification ) ;
36
+ const visible = message || notification ? true : false ;
37
+ const actionIcon = notification ?. isError ? "warning sign" : "info circle" ;
30
38
31
39
if ( closable && visible ) {
32
40
clearTimeout ( timer . current ) ;
33
41
timer . current = setTimeout ( ( ) => hide ( ) , AUTO_CLOSE_TIMEOUT ) ;
34
42
}
35
-
36
43
return (
37
44
< Transition visible = { visible } duration = { 300 } >
38
45
< Container text className = { styles . container } >
39
46
< Message
40
- icon = { icon }
41
- header = { header }
42
- content = { message || error ?. message }
47
+ icon = { icon || actionIcon }
48
+ header = { header || notification ?. header }
49
+ content = { message || notification ?. message }
43
50
onDismiss = { closable ? hide : null }
44
51
size = "small"
45
- error
52
+ error = { error || ( notification && notification . isError ) }
53
+ success = { success || ( notification && ! notification . isError ) }
46
54
/>
47
55
</ Container >
48
56
</ Transition >
@@ -54,11 +62,15 @@ Notification.propTypes = {
54
62
header : PropTypes . string ,
55
63
message : PropTypes . string ,
56
64
closable : PropTypes . bool ,
65
+ error : PropTypes . bool ,
66
+ success : PropTypes . bool ,
57
67
} ;
58
68
59
69
Notification . defaultProps = {
60
- icon : "warning sign" ,
61
- header : "An error has occurred" ,
70
+ icon : null ,
71
+ header : null ,
62
72
message : null ,
63
73
closable : true ,
74
+ error : false ,
75
+ success : false ,
64
76
} ;
0 commit comments