blob: bcd6e7fe5bb76cd6289329d3ad423af0bdc50210 [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
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
svishnev091edfd2018-03-19 12:15:19 +02007 *
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,
svishnev091edfd2018-03-19 12:15:19 +020012 * 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 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
svishnev091edfd2018-03-19 12:15:19 +020027export const mapStateToProps = ({users: {usersList}, licenseModelList, finalizedLicenseModelList, archivedLicenseModelList, licenseModel: {licenseModelCreation}}) => {
AviZi280f8012017-06-09 02:39:56 +030028 let {genericFieldInfo} = licenseModelCreation;
29 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
AviZi280f8012017-06-09 02:39:56 +030030 let VLMNames = {};
svishnev091edfd2018-03-19 12:15:19 +020031
32 const allVlmList = [...licenseModelList, ...finalizedLicenseModelList,...archivedLicenseModelList];
33 allVlmList.map((item) => {
34 VLMNames[item.name.toLowerCase()] = item.id;
35 });
AviZi280f8012017-06-09 02:39:56 +030036
talig8e9c0652017-12-20 14:30:43 +020037 return {...licenseModelCreation, isFormValid: isFormValid, VLMNames, usersList};
AviZi280f8012017-06-09 02:39:56 +030038};
39
40export const mapActionsToProps = (dispatch) => {
Michael Landoefa037d2017-02-19 12:57:33 +020041 return {
AviZi280f8012017-06-09 02:39:56 +030042 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
Michael Landoefa037d2017-02-19 12:57:33 +020043 onCancel: () => LicenseModelCreationActionHelper.close(dispatch),
talig8e9c0652017-12-20 14:30:43 +020044 onSubmit: (licenseModel, usersList) => {
Michael Landoefa037d2017-02-19 12:57:33 +020045 LicenseModelCreationActionHelper.close(dispatch);
AviZi280f8012017-06-09 02:39:56 +030046 LicenseModelCreationActionHelper.createLicenseModel(dispatch, {licenseModel}).then(response => {
talig8e9c0652017-12-20 14:30:43 +020047 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 Landoefa037d2017-02-19 12:57:33 +020054 });
AviZi280f8012017-06-09 02:39:56 +030055 },
56 onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName)
Michael Landoefa037d2017-02-19 12:57:33 +020057 };
58};
59
60export default connect(mapStateToProps, mapActionsToProps)(LicenseModelCreationView);