2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
27 * NotificationModal options:
29 * show: whether to show notification or not,
30 * type: the type of the notification. valid values are: 'default', 'error',
31 * 'warning', 'success' msg: the notification content. could be a string or
32 * node (React component) title: the notification title timeout: timeout for
33 * the notification to fade out. if timeout == 0 then the notification is
34 * rendered until the user closes it
37 import React, {Component, PropTypes} from 'react';
38 import {connect} from 'react-redux';
39 import Button from 'react-bootstrap/lib/Button.js';
41 import i18n from 'utils/i18n/i18n.js';
42 import Modal from 'generic-components/modal/Modal.jsx';
43 import NotificationConstants from './NotificationConstants.js';
52 const mapActionsToProps = (dispatch) => {
54 onCloseClick: () => dispatch({type: NotificationConstants.NOTIFY_CLOSE})
58 const mapStateToProps = ({notification}) => {
60 let show = notification !== null && notification.title !== 'Conflict';
61 let mapResult = {show};
63 mapResult = {show, ...notification};
69 class NotificationModal extends Component {
73 type: PropTypes.oneOf(['default', 'error', 'warning', 'success']),
75 title: PropTypes.string,
76 timeout: PropTypes.number
79 static defaultProps = {
87 state = {type: undefined};
89 componentWillReceiveProps(nextProps) {
90 if (this.props.show !== nextProps.show && nextProps.show === false) {
91 this.setState({type: this.props.type});
94 this.setState({type: undefined});
98 componentDidUpdate() {
99 if (this.props.timeout) {
100 setTimeout(this.props.onCloseClick, this.props.timeout);
105 let {title, type, msg, show} = this.props;
107 type = this.state.type;
110 <Modal show={this.props.show}
111 className={`notification-modal ${typeClass[type]}`}>
113 <Modal.Title>{title}</Modal.Title>
115 <Modal.Body>{msg}</Modal.Body>
117 <Button bsStyle={typeClass[type]}
118 onClick={this.props.onCloseClick}>{i18n('OK')}</Button>
125 export default connect(mapStateToProps, mapActionsToProps)(NotificationModal);