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';
18 import SoftwareProductCreationActionHelper from './SoftwareProductCreationActionHelper.js';
19 import SoftwareProductCreationView from './SoftwareProductCreationView.jsx';
20 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
21 import SoftwareProductActionHelper from '../SoftwareProductActionHelper.js';
22 import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
23 import {itemTypes as versionItemTypes} from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
24 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
25 import {enums, screenTypes} from 'sdc-app/onboarding/OnboardingConstants.js';
26 import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
28 export const mapStateToProps = ({finalizedLicenseModelList, users: {usersList}, softwareProductList, softwareProduct: {softwareProductCreation, softwareProductCategories} }) => {
29 let {genericFieldInfo} = softwareProductCreation;
30 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
33 for (let i = 0; i < softwareProductList.length; i++) {
34 VSPNames[softwareProductList[i].name.toLowerCase()] = softwareProductList[i].id;
38 data: softwareProductCreation.data,
39 selectedVendorId: softwareProductCreation.selectedVendorId,
40 disableVendor: softwareProductCreation.disableVendor,
41 softwareProductCategories,
42 finalizedLicenseModelList,
44 formReady: softwareProductCreation.formReady,
51 export const mapActionsToProps = (dispatch) => {
53 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
54 onCancel: () => SoftwareProductCreationActionHelper.resetData(dispatch),
55 onSubmit: (softwareProduct, usersList) => {
56 SoftwareProductCreationActionHelper.resetData(dispatch);
57 SoftwareProductCreationActionHelper.createSoftwareProduct(dispatch, {softwareProduct}).then(response => {
58 let {itemId, version} = response;
59 SoftwareProductActionHelper.fetchSoftwareProductList(dispatch).then(() =>
60 PermissionsActionHelper.fetchItemUsers(dispatch, {itemId, allUsers: usersList}).then(() =>
61 VersionsPageActionHelper.fetchVersions(dispatch, {itemType: versionItemTypes.SOFTWARE_PRODUCT, itemId}).then(() =>
62 ScreensHelper.loadScreen(dispatch, {screen: enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE, screenType: screenTypes.SOFTWARE_PRODUCT,
63 props: {softwareProductId: itemId, version}})
69 onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName)
73 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductCreationView);