[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / creation / SoftwareProductCreation.js
1 /*!
2  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 import {connect} from 'react-redux';
17
18 import OnboardingActionHelper from 'sdc-app/onboarding/OnboardingActionHelper.js';
19 import SoftwareProductCreationActionHelper from './SoftwareProductCreationActionHelper.js';
20 import SoftwareProductCreationView from './SoftwareProductCreationView.jsx';
21 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
22 import SoftwareProductActionHelper  from '../SoftwareProductActionHelper.js';
23
24 export const mapStateToProps = ({finalizedLicenseModelList, softwareProductList, softwareProduct: {softwareProductCreation, softwareProductCategories} }) => {
25         let {genericFieldInfo} = softwareProductCreation;
26         let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
27
28         let VSPNames = {};
29         for (let i = 0; i < softwareProductList.length; i++) {
30                 VSPNames[softwareProductList[i].name] = softwareProductList[i].id;
31         }
32
33         return {
34                 data: softwareProductCreation.data,
35                 selectedVendorId: softwareProductCreation.selectedVendorId,
36                 disableVendor: softwareProductCreation.disableVendor,
37                 softwareProductCategories,
38                 finalizedLicenseModelList,
39                 isFormValid,
40                 formReady: softwareProductCreation.formReady,
41                 genericFieldInfo,
42                 VSPNames
43         };
44 };
45
46 export const mapActionsToProps = (dispatch) => {
47         return {
48                 onDataChanged: (deltaData, formName, customValidations) => ValidationHelper.dataChanged(dispatch, {deltaData, formName, customValidations}),
49                 onCancel: () => SoftwareProductCreationActionHelper.resetData(dispatch),
50                 onSubmit: (softwareProduct) => {
51                         SoftwareProductCreationActionHelper.resetData(dispatch);
52                         SoftwareProductCreationActionHelper.createSoftwareProduct(dispatch, {softwareProduct}).then(response => {
53                                 SoftwareProductActionHelper.fetchSoftwareProductList(dispatch).then(() => {
54                                         let {vendorId: licenseModelId, licensingVersion} = softwareProduct;
55                                         OnboardingActionHelper.navigateToSoftwareProductLandingPage(dispatch, {softwareProductId: response.vspId, licenseModelId, licensingVersion});
56                                 });
57                         });
58                 },
59                 onValidateForm: (formName) => ValidationHelper.validateForm(dispatch, formName)
60         };
61 };
62
63 export default connect(mapStateToProps, mapActionsToProps, null, {withRef: true})(SoftwareProductCreationView);