2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 * NotificationModal options:
26 * show: whether to show notification or not,
27 * type: the type of the notification. valid values are: 'default', 'error',
28 * 'warning', 'success' msg: the notification content. could be a string or
29 * node (React component) title: the notification title timeout: timeout for
30 * the notification to fade out. if timeout == 0 then the notification is
31 * rendered until the user closes it
34 import React, {Component, PropTypes} from 'react';
35 import {connect} from 'react-redux';
36 import Button from 'react-bootstrap/lib/Button.js';
38 import i18n from 'utils/i18n/i18n.js';
39 import Modal from 'generic-components/modal/Modal.jsx';
40 import NotificationConstants from './NotificationConstants.js';
49 const mapActionsToProps = (dispatch) => {
51 onCloseClick: () => dispatch({type: NotificationConstants.NOTIFY_CLOSE})
55 const mapStateToProps = ({notification}) => {
57 let show = notification !== null && notification.title !== 'Conflict';
58 let mapResult = {show};
60 mapResult = {show, ...notification};
66 class NotificationModal extends Component {
70 type: PropTypes.oneOf(['default', 'error', 'warning', 'success']),
72 title: PropTypes.string,
73 timeout: PropTypes.number
76 static defaultProps = {
84 state = {type: undefined};
86 componentWillReceiveProps(nextProps) {
87 if (this.props.show !== nextProps.show && nextProps.show === false) {
88 this.setState({type: this.props.type});
91 this.setState({type: undefined});
95 componentDidUpdate() {
96 if (this.props.timeout) {
97 setTimeout(this.props.onCloseClick, this.props.timeout);
102 let {title, type, msg, show} = this.props;
104 type = this.state.type;
107 <Modal show={this.props.show}
108 className={`notification-modal ${typeClass[type]}`}>
110 <Modal.Title>{title}</Modal.Title>
112 <Modal.Body>{msg}</Modal.Body>
114 <Button bsStyle={typeClass[type]}
115 onClick={this.props.onCloseClick}>{i18n('OK')}</Button>
122 export default connect(mapStateToProps, mapActionsToProps)(NotificationModal);