2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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=========================================================
22 * NotificationModal options:
24 * show: whether to show notification or not,
25 * type: the type of the notification. valid values are: 'default', 'error',
26 * 'warning', 'success' msg: the notification content. could be a string or
27 * node (React component) title: the notification title timeout: timeout for
28 * the notification to fade out. if timeout == 0 then the notification is
29 * rendered until the user closes it
32 import React, {Component, PropTypes} from 'react';
33 import {connect} from 'react-redux';
34 import Button from 'react-bootstrap/lib/Button.js';
36 import i18n from 'utils/i18n/i18n.js';
37 import Modal from 'generic-components/modal/Modal.jsx';
38 import NotificationConstants from './NotificationConstants.js';
47 const mapActionsToProps = (dispatch) => {
49 onCloseClick: () => dispatch({type: NotificationConstants.NOTIFY_CLOSE})
53 const mapStateToProps = ({notification}) => {
55 let show = notification !== null && notification.title !== 'Conflict';
56 let mapResult = {show};
58 mapResult = {show, ...notification};
64 class NotificationModal extends Component {
68 type: PropTypes.oneOf(['default', 'error', 'warning', 'success']),
70 title: PropTypes.string,
71 timeout: PropTypes.number
74 static defaultProps = {
82 state = {type: undefined};
84 componentWillReceiveProps(nextProps) {
85 if (this.props.show !== nextProps.show && nextProps.show === false) {
86 this.setState({type: this.props.type});
89 this.setState({type: undefined});
93 componentDidUpdate() {
94 if (this.props.timeout) {
95 setTimeout(this.props.onCloseClick, this.props.timeout);
100 let {title, type, msg, show} = this.props;
102 type = this.state.type;
105 <Modal show={this.props.show}
106 className={`notification-modal ${typeClass[type]}`}>
108 <Modal.Title>{title}</Modal.Title>
110 <Modal.Body>{msg}</Modal.Body>
112 <Button bsStyle={typeClass[type]}
113 onClick={this.props.onCloseClick}>{i18n('OK')}</Button>
120 export default connect(mapStateToProps, mapActionsToProps)(NotificationModal);