svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 16 | import {connect} from 'react-redux'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import LicenseModelCreationActionHelper from './LicenseModelCreationActionHelper.js'; |
| 18 | import LicenseModelCreationView from './LicenseModelCreationView.jsx'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 19 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 20 | import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 21 | import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js'; |
| 22 | import {itemTypes as versionItemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
| 23 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
| 24 | import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js'; |
| 25 | import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 26 | |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 27 | export const mapStateToProps = ({users: {usersList}, licenseModelList, finalizedLicenseModelList, archivedLicenseModelList, licenseModel: {licenseModelCreation}}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | let {genericFieldInfo} = licenseModelCreation; |
| 29 | let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 30 | let VLMNames = {}; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 31 | |
| 32 | const allVlmList = [...licenseModelList, ...finalizedLicenseModelList,...archivedLicenseModelList]; |
| 33 | allVlmList.map((item) => { |
| 34 | VLMNames[item.name.toLowerCase()] = item.id; |
| 35 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 36 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 37 | return {...licenseModelCreation, isFormValid: isFormValid, VLMNames, usersList}; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | export const mapActionsToProps = (dispatch) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 41 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 42 | onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 43 | onCancel: () => LicenseModelCreationActionHelper.close(dispatch), |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 44 | onSubmit: (licenseModel, usersList) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 45 | LicenseModelCreationActionHelper.close(dispatch); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 46 | LicenseModelCreationActionHelper.createLicenseModel(dispatch, {licenseModel}).then(response => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 47 | let {itemId, version} = response; |
| 48 | LicenseModelActionHelper.fetchLicenseModels(dispatch).then(() => |
| 49 | PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers: usersList}).then(() => |
| 50 | VersionsPageActionHelper.fetchVersions(dispatch, {itemType: versionItemTypes.LICENSE_MODEL, itemId}).then(() => |
| 51 | ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, screenType: screenTypes.LICENSE_MODEL, |
| 52 | props: {licenseModelId: itemId, version}}) |
| 53 | ))); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 54 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 55 | }, |
| 56 | onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName) |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 57 | }; |
| 58 | }; |
| 59 | |
| 60 | export default connect(mapStateToProps, mapActionsToProps)(LicenseModelCreationView); |