blob: bd8f21a7c58ca6c983768cae8826210e3bc70408 [file] [log] [blame]
Avi Ziv61070c92017-07-26 17:37:57 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16import {connect} from 'react-redux';
17import i18n from 'nfvo-utils/i18n/i18n.js';
18import {actionTypes as globalModalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
19import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
20import Limits from 'sdc-app/onboarding/licenseModel/limits/Limits.jsx';
21
22import LicenseKeyGroupsActionHelper from './LicenseKeyGroupsActionHelper.js';
23
talig8e9c0652017-12-20 14:30:43 +020024const mapStateToProps = ({licenseModel: {licenseKeyGroup: {licenseKeyGroupsEditor: {data}}, limitEditor}, currentScreen}) => {
Avi Ziv61070c92017-07-26 17:37:57 +030025 let {props: {licenseModelId, version}} = currentScreen;
26 return {
talig8e9c0652017-12-20 14:30:43 +020027 parent: data,
Avi Ziv61070c92017-07-26 17:37:57 +030028 limitEditor,
29 licenseModelId,
30 version
31 };
32};
33
34const mapActionsToProps = (dispatch) => {
35 return {
36 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
37 onSubmit: (limit, licenseKeyGroup, licenseModelId, version) => LicenseKeyGroupsActionHelper.submitLimit(dispatch,
38 {
39 limit,
40 licenseKeyGroup,
41 licenseModelId,
talig8e9c0652017-12-20 14:30:43 +020042 version}),
Avi Ziv61070c92017-07-26 17:37:57 +030043 onDelete: ({limit, parent, licenseModelId, version, onCloseLimitEditor, selectedLimit}) => dispatch({
44 type: globalModalActionTypes.GLOBAL_MODAL_WARNING,
45 data:{
talig8e9c0652017-12-20 14:30:43 +020046 msg: i18n('Are you sure you want to delete {name}?', {name: limit.name}),
Avi Ziv61070c92017-07-26 17:37:57 +030047 confirmationButtonText: i18n('Delete'),
miriame4a5e1d02017-10-26 12:01:01 +030048 title: i18n('Delete'),
talig8e9c0652017-12-20 14:30:43 +020049 onConfirmed: ()=> LicenseKeyGroupsActionHelper.deleteLimit(dispatch, {limit, licenseKeyGroup: parent, licenseModelId, version}).then(() =>
Avi Ziv61070c92017-07-26 17:37:57 +030050 selectedLimit === limit.id && onCloseLimitEditor()
51 )
52 }
53 })
54 };
55};
56
talig8e9c0652017-12-20 14:30:43 +020057export default connect(mapStateToProps, mapActionsToProps)(Limits);