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 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { connect } from 'react-redux'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 17 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 18 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 19 | import Limits from 'sdc-app/onboarding/licenseModel/limits/Limits.jsx'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 20 | import { actionTypes as globalModalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; |
Avi Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 21 | import EntitlementPoolsActionHelper from './EntitlementPoolsActionHelper.js'; |
| 22 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 23 | const 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 Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 37 | }; |
| 38 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 39 | const 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 Ziv | 61070c9 | 2017-07-26 17:37:57 +0300 | [diff] [blame] | 84 | }; |
| 85 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 86 | export default connect(mapStateToProps, mapActionsToProps)(Limits); |