AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | /*! |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 2 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
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 |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [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, |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 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. |
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 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 27 | export const mapStateToProps = ({users: {usersList}, licenseModelList, licenseModel: {licenseModelCreation}}) => { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | let {genericFieldInfo} = licenseModelCreation; |
| 29 | let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 30 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 31 | let VLMNames = {}; |
| 32 | for (let i = 0; i < licenseModelList.length; i++) { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 33 | VLMNames[licenseModelList[i].name.toLowerCase()] = licenseModelList[i].id; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 34 | } |
| 35 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 36 | return {...licenseModelCreation, isFormValid: isFormValid, VLMNames, usersList}; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | export const mapActionsToProps = (dispatch) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 40 | return { |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 41 | onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}), |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 42 | onCancel: () => LicenseModelCreationActionHelper.close(dispatch), |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 43 | onSubmit: (licenseModel, usersList) => { |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 44 | LicenseModelCreationActionHelper.close(dispatch); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 45 | LicenseModelCreationActionHelper.createLicenseModel(dispatch, {licenseModel}).then(response => { |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame^] | 46 | let {itemId, version} = response; |
| 47 | LicenseModelActionHelper.fetchLicenseModels(dispatch).then(() => |
| 48 | PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers: usersList}).then(() => |
| 49 | VersionsPageActionHelper.fetchVersions(dispatch, {itemType: versionItemTypes.LICENSE_MODEL, itemId}).then(() => |
| 50 | ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, screenType: screenTypes.LICENSE_MODEL, |
| 51 | props: {licenseModelId: itemId, version}}) |
| 52 | ))); |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 53 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 54 | }, |
| 55 | onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName) |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 56 | }; |
| 57 | }; |
| 58 | |
| 59 | export default connect(mapStateToProps, mapActionsToProps)(LicenseModelCreationView); |