2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import React from 'react';
18 import PropTypes from 'prop-types';
19 import { connect } from 'react-redux';
27 } from 'sdc-ui/lib/react';
28 import i18n from 'nfvo-utils/i18n/i18n.js';
29 import { modalContentComponents } from 'sdc-app/common/modal/ModalContentMapper.js';
30 import { actionTypes, typeEnum } from './GlobalModalConstants.js';
32 const GlobalModalFooter = ({
36 confirmationButtonText,
39 let actionButtonClick;
41 actionButtonClick = () => {
48 actionButtonText={onConfirmed ? confirmationButtonText : undefined}
49 actionButtonClick={actionButtonClick}
50 closeButtonText={cancelButtonText}
64 GlobalModalFooter.defaultProps = {
65 confirmationButtonText: i18n('OK'),
66 cancelButtonText: i18n('Cancel')
69 GlobalModalFooter.propTypes = {
70 confirmationButtonText: PropTypes.string,
71 cancelButtonText: PropTypes.string
74 export const mapStateToProps = ({ modal }) => {
82 export const mapActionToProps = dispatch => {
84 onClose: () => dispatch({ type: actionTypes.GLOBAL_MODAL_CLOSE })
88 export class GlobalModalView extends React.Component {
91 type: PropTypes.oneOf(['default', 'error', 'warning', 'success']),
92 title: PropTypes.string,
93 modalComponentProps: PropTypes.object,
94 modalComponentName: PropTypes.string,
95 onConfirmed: PropTypes.func,
96 onDeclined: PropTypes.func,
97 confirmationButtonText: PropTypes.string,
98 cancelButtonText: PropTypes.string,
99 bodyClassName: PropTypes.string
102 static defaultProps = {
118 confirmationButtonText,
123 const ComponentToRender = modalContentComponents[modalComponentName];
128 size={modalComponentProps && modalComponentProps.size}>
129 <ModalHeader type={type} onClose={onClose}>
130 <ModalTitle>{title}</ModalTitle>
132 <ModalBody className={bodyClassName}>
133 {ComponentToRender ? (
134 <ComponentToRender {...modalComponentProps} />
135 ) : msg && typeof msg === 'string' ? (
138 {msg.split('\n').map((txt, i) => (
149 {(onConfirmed || onDeclined || type !== typeEnum.DEFAULT) && (
151 onConfirmed={onConfirmed}
152 onDeclined={onDeclined}
154 confirmationButtonText={confirmationButtonText}
155 cancelButtonText={cancelButtonText}
162 componentDidUpdate() {
163 if (this.props.timeout) {
164 setTimeout(this.props.onClose, this.props.timeout);
169 GlobalModalView.propTypes = {
170 show: PropTypes.bool,
171 type: PropTypes.oneOf(['custom', 'error', 'alert', 'info']),
172 title: PropTypes.string,
173 modalComponentProps: PropTypes.object,
174 modalComponentName: PropTypes.string,
175 onConfirmed: PropTypes.func,
176 onDeclined: PropTypes.func,
177 confirmationButtonText: PropTypes.string,
178 cancelButtonText: PropTypes.string
181 export default connect(mapStateToProps, mapActionToProps, null, {