blob: fd5fe6dd21a1e1df927316ffb8b78a19356eee1e [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';
18import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
19import Limits from 'sdc-app/onboarding/licenseModel/limits/Limits.jsx';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020020import { actionTypes as globalModalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
Avi Ziv61070c92017-07-26 17:37:57 +030021import EntitlementPoolsActionHelper from './EntitlementPoolsActionHelper.js';
22
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023const mapStateToProps = ({
24 licenseModel: {
25 entitlementPool: { entitlementPoolEditor: { data } },
26 limitEditor
27 },
28 currentScreen
29}) => {
30 let { props: { licenseModelId, version } } = currentScreen;
31 return {
32 parent: data,
33 limitEditor,
34 licenseModelId,
35 version
36 };
Avi Ziv61070c92017-07-26 17:37:57 +030037};
38
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020039const mapActionsToProps = dispatch => {
40 return {
41 onDataChanged: (deltaData, formName, customValidations) =>
42 ValidationHelper.dataChanged(dispatch, {
43 deltaData,
44 formName,
45 customValidations
46 }),
47 onSubmit: (limit, entitlementPool, licenseModelId, version) =>
48 EntitlementPoolsActionHelper.submitLimit(dispatch, {
49 limit,
50 entitlementPool,
51 licenseModelId,
52 version
53 }),
54 onDelete: ({
55 limit,
56 parent,
57 licenseModelId,
58 version,
59 onCloseLimitEditor,
60 selectedLimit
61 }) =>
62 dispatch({
63 type: globalModalActionTypes.GLOBAL_MODAL_WARNING,
64 data: {
65 msg: i18n('Are you sure you want to delete {name}?', {
66 name: limit.name
67 }),
68 confirmationButtonText: i18n('Delete'),
69 title: i18n('Delete'),
70 onConfirmed: () =>
71 EntitlementPoolsActionHelper.deleteLimit(dispatch, {
72 limit,
73 entitlementPool: parent,
74 licenseModelId,
75 version
76 }).then(
77 () =>
78 selectedLimit === limit.id &&
79 onCloseLimitEditor()
80 )
81 }
82 })
83 };
Avi Ziv61070c92017-07-26 17:37:57 +030084};
85
talig8e9c0652017-12-20 14:30:43 +020086export default connect(mapStateToProps, mapActionsToProps)(Limits);