Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 1 | /*! |
| 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 | */ |
| 16 | import {connect} from 'react-redux'; |
| 17 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 18 | import {actionTypes as globalModalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js'; |
| 19 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 20 | import Limits from 'sdc-app/onboarding/licenseModel/limits/Limits.jsx'; |
| 21 | |
| 22 | import LicenseKeyGroupsActionHelper from './LicenseKeyGroupsActionHelper.js'; |
| 23 | |
| 24 | const mapStateToProps = ({licenseModel: {licenseKeyGroup: {licenseKeyGroupsEditor: {data}}, limitEditor}, currentScreen}) => { |
| 25 | let {props: {licenseModelId, version}} = currentScreen; |
| 26 | return { |
| 27 | parent: data, |
| 28 | limitEditor, |
| 29 | licenseModelId, |
| 30 | version |
| 31 | }; |
| 32 | }; |
| 33 | |
| 34 | const 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, |
| 42 | version}), |
| 43 | onDelete: ({limit, parent, licenseModelId, version, onCloseLimitEditor, selectedLimit}) => dispatch({ |
| 44 | type: globalModalActionTypes.GLOBAL_MODAL_WARNING, |
| 45 | data:{ |
| 46 | msg: i18n(`Are you sure you want to delete ${limit.name}?`), |
| 47 | confirmationButtonText: i18n('Delete'), |
miriame | 4a5e1d0 | 2017-10-26 12:01:01 +0300 | [diff] [blame] | 48 | title: i18n('Delete'), |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 49 | onConfirmed: ()=> LicenseKeyGroupsActionHelper.deleteLimit(dispatch, {limit, licenseKeyGroup: parent, licenseModelId, version}).then(() => |
| 50 | selectedLimit === limit.id && onCloseLimitEditor() |
| 51 | ) |
| 52 | } |
| 53 | }) |
| 54 | }; |
| 55 | }; |
| 56 | |
| 57 | export default connect(mapStateToProps, mapActionsToProps)(Limits); |