2 * NotificationModal options:
4 * show: whether to show notification or not,
5 * type: the type of the notification. valid values are: 'default', 'error', 'warning', 'success'
6 * msg: the notification content. could be a string or node (React component)
7 * title: the notification title
8 * timeout: timeout for the notification to fade out. if timeout == 0 then the notification is rendered until the user closes it
11 import React, {Component, PropTypes} from 'react';
12 import {connect} from 'react-redux';
13 import Button from 'react-bootstrap/lib/Button.js';
15 import i18n from 'nfvo-utils/i18n/i18n.js';
16 import Modal from 'nfvo-components/modal/Modal.jsx';
17 import SubmitErrorResponse from 'nfvo-components/SubmitErrorResponse.jsx';
18 import NotificationConstants from './NotificationConstants.js';
27 const mapActionsToProps = (dispatch) => {
28 return {onCloseClick: () => dispatch({type: NotificationConstants.NOTIFY_CLOSE})};
31 const mapStateToProps = ({notification}) => {
33 let show = notification !== null && notification.title !== 'Conflict';
34 let mapResult = {show};
36 mapResult = {show, ...notification};
42 export class NotificationModal extends Component {
46 type: PropTypes.oneOf(['default', 'error', 'warning', 'success']),
47 title: PropTypes.string,
49 validationResponse: PropTypes.object,
50 timeout: PropTypes.number
53 static defaultProps = {
61 state = {type: undefined};
63 componentWillReceiveProps(nextProps) {
64 if (this.props.show !== nextProps.show && nextProps.show === false) {
65 this.setState({type: this.props.type});
68 this.setState({type: undefined});
72 componentDidUpdate() {
73 if (this.props.timeout) {
74 setTimeout(this.props.onCloseClick, this.props.timeout);
79 let {title, type, msg, show, validationResponse, onCloseClick} = this.props;
81 type = this.state.type;
83 if (validationResponse) {
84 msg = (<SubmitErrorResponse validationResponse={validationResponse}/>);
87 <Modal show={show} className={`notification-modal ${typeClass[type]}`}>
89 <Modal.Title>{title}</Modal.Title>
91 <Modal.Body>{msg}</Modal.Body>
93 <Button bsStyle={typeClass[type]} onClick={onCloseClick}>{i18n('OK')}</Button>
100 export default connect(mapStateToProps, mapActionsToProps)(NotificationModal);