blob: ad14c6c249dc10b7d41ea14e32ccd0418cf96700 [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 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { connect } from 'react-redux';
Avi Ziv61070c92017-07-26 17:37:57 +030017import i18n from 'nfvo-utils/i18n/i18n.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020018import { actionTypes as globalModalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
Avi Ziv61070c92017-07-26 17:37:57 +030019import 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
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020024const mapStateToProps = ({
25 licenseModel: {
26 licenseKeyGroup: { licenseKeyGroupsEditor: { data } },
27 limitEditor
28 },
29 currentScreen
30}) => {
31 let { props: { licenseModelId, version } } = currentScreen;
32 return {
33 parent: data,
34 limitEditor,
35 licenseModelId,
36 version
37 };
Avi Ziv61070c92017-07-26 17:37:57 +030038};
39
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020040const mapActionsToProps = dispatch => {
41 return {
42 onDataChanged: (deltaData, formName, customValidations) =>
43 ValidationHelper.dataChanged(dispatch, {
44 deltaData,
45 formName,
46 customValidations
47 }),
48 onSubmit: (limit, licenseKeyGroup, licenseModelId, version) =>
49 LicenseKeyGroupsActionHelper.submitLimit(dispatch, {
50 limit,
51 licenseKeyGroup,
52 licenseModelId,
53 version
54 }),
55 onDelete: ({
56 limit,
57 parent,
58 licenseModelId,
59 version,
60 onCloseLimitEditor,
61 selectedLimit
62 }) =>
63 dispatch({
64 type: globalModalActionTypes.GLOBAL_MODAL_WARNING,
65 data: {
66 msg: i18n('Are you sure you want to delete {name}?', {
67 name: limit.name
68 }),
69 confirmationButtonText: i18n('Delete'),
70 title: i18n('Delete'),
71 onConfirmed: () =>
72 LicenseKeyGroupsActionHelper.deleteLimit(dispatch, {
73 limit,
74 licenseKeyGroup: parent,
75 licenseModelId,
76 version
77 }).then(
78 () =>
79 selectedLimit === limit.id &&
80 onCloseLimitEditor()
81 )
82 }
83 })
84 };
Avi Ziv61070c92017-07-26 17:37:57 +030085};
86
talig8e9c0652017-12-20 14:30:43 +020087export default connect(mapStateToProps, mapActionsToProps)(Limits);