blob: 71f41710db2c607f5160fb2d03699d41203ddf0d [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
Michael Landoefa037d2017-02-19 12:57:33 +02002 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
AviZi280f8012017-06-09 02:39:56 +03007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
AviZi280f8012017-06-09 02:39:56 +030012 * 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 Landoefa037d2017-02-19 12:57:33 +020015 */
Michael Landoefa037d2017-02-19 12:57:33 +020016import {connect} from 'react-redux';
Michael Landoefa037d2017-02-19 12:57:33 +020017import LicenseModelCreationActionHelper from './LicenseModelCreationActionHelper.js';
18import LicenseModelCreationView from './LicenseModelCreationView.jsx';
AviZi280f8012017-06-09 02:39:56 +030019import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
20import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020021import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
22import {itemTypes as versionItemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
23import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
24import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
25import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
Michael Landoefa037d2017-02-19 12:57:33 +020026
talig8e9c0652017-12-20 14:30:43 +020027export const mapStateToProps = ({users: {usersList}, licenseModelList, licenseModel: {licenseModelCreation}}) => {
AviZi280f8012017-06-09 02:39:56 +030028 let {genericFieldInfo} = licenseModelCreation;
29 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
Michael Landoefa037d2017-02-19 12:57:33 +020030
AviZi280f8012017-06-09 02:39:56 +030031 let VLMNames = {};
32 for (let i = 0; i < licenseModelList.length; i++) {
talig8e9c0652017-12-20 14:30:43 +020033 VLMNames[licenseModelList[i].name.toLowerCase()] = licenseModelList[i].id;
AviZi280f8012017-06-09 02:39:56 +030034 }
35
talig8e9c0652017-12-20 14:30:43 +020036 return {...licenseModelCreation, isFormValid: isFormValid, VLMNames, usersList};
AviZi280f8012017-06-09 02:39:56 +030037};
38
39export const mapActionsToProps = (dispatch) => {
Michael Landoefa037d2017-02-19 12:57:33 +020040 return {
AviZi280f8012017-06-09 02:39:56 +030041 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
Michael Landoefa037d2017-02-19 12:57:33 +020042 onCancel: () => LicenseModelCreationActionHelper.close(dispatch),
talig8e9c0652017-12-20 14:30:43 +020043 onSubmit: (licenseModel, usersList) => {
Michael Landoefa037d2017-02-19 12:57:33 +020044 LicenseModelCreationActionHelper.close(dispatch);
AviZi280f8012017-06-09 02:39:56 +030045 LicenseModelCreationActionHelper.createLicenseModel(dispatch, {licenseModel}).then(response => {
talig8e9c0652017-12-20 14:30:43 +020046 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 Landoefa037d2017-02-19 12:57:33 +020053 });
AviZi280f8012017-06-09 02:39:56 +030054 },
55 onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName)
Michael Landoefa037d2017-02-19 12:57:33 +020056 };
57};
58
59export default connect(mapStateToProps, mapActionsToProps)(LicenseModelCreationView);