2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import {connect} from 'react-redux';
17 import LicenseModelCreationActionHelper from './LicenseModelCreationActionHelper.js';
18 import LicenseModelCreationView from './LicenseModelCreationView.jsx';
19 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
20 import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
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';
27 export const mapStateToProps = ({users: {usersList}, licenseModelList, licenseModel: {licenseModelCreation}}) => {
28 let {genericFieldInfo} = licenseModelCreation;
29 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
32 for (let i = 0; i < licenseModelList.length; i++) {
33 VLMNames[licenseModelList[i].name.toLowerCase()] = licenseModelList[i].id;
36 return {...licenseModelCreation, isFormValid: isFormValid, VLMNames, usersList};
39 export const mapActionsToProps = (dispatch) => {
41 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
42 onCancel: () => LicenseModelCreationActionHelper.close(dispatch),
43 onSubmit: (licenseModel, usersList) => {
44 LicenseModelCreationActionHelper.close(dispatch);
45 LicenseModelCreationActionHelper.createLicenseModel(dispatch, {licenseModel}).then(response => {
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}})
55 onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName)
59 export default connect(mapStateToProps, mapActionsToProps)(LicenseModelCreationView);