svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 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 |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 12 | * 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 Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 15 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { connect } from 'react-redux'; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 17 | import LicenseModelCreationActionHelper from './LicenseModelCreationActionHelper.js'; |
| 18 | import LicenseModelCreationView from './LicenseModelCreationView.jsx'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 19 | |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 20 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
| 21 | import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 23 | import { itemTypes as versionItemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 24 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 25 | import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 27 | import UniqueTypesHelper from 'sdc-app/common/helpers/UniqueTypesHelper.js'; |
| 28 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 29 | import { itemType } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
| 30 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 31 | export const mapStateToProps = ({ |
| 32 | users: { usersList }, |
| 33 | licenseModelList, |
| 34 | finalizedLicenseModelList, |
| 35 | archivedLicenseModelList, |
| 36 | licenseModel: { licenseModelCreation } |
| 37 | }) => { |
| 38 | let { genericFieldInfo } = licenseModelCreation; |
| 39 | let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo); |
| 40 | let VLMNames = {}; |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 41 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 42 | const allVlmList = [ |
| 43 | ...licenseModelList, |
| 44 | ...finalizedLicenseModelList, |
| 45 | ...archivedLicenseModelList |
| 46 | ]; |
| 47 | allVlmList.map(item => { |
| 48 | VLMNames[item.name.toLowerCase()] = item.id; |
| 49 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 50 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 51 | return { |
| 52 | ...licenseModelCreation, |
| 53 | isFormValid: isFormValid, |
| 54 | VLMNames, |
| 55 | usersList |
| 56 | }; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 57 | }; |
| 58 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 59 | export const mapActionsToProps = dispatch => { |
| 60 | return { |
| 61 | onDataChanged: (deltaData, formName, customValidations) => |
| 62 | ValidationHelper.dataChanged(dispatch, { |
| 63 | deltaData, |
| 64 | formName, |
| 65 | customValidations |
| 66 | }), |
| 67 | onCancel: () => LicenseModelCreationActionHelper.close(dispatch), |
| 68 | onSubmit: (licenseModel, usersList) => { |
| 69 | LicenseModelCreationActionHelper.close(dispatch); |
| 70 | LicenseModelCreationActionHelper.createLicenseModel(dispatch, { |
| 71 | licenseModel |
| 72 | }).then(response => { |
| 73 | let { itemId, version } = response; |
| 74 | LicenseModelActionHelper.fetchLicenseModels(dispatch).then(() => |
| 75 | PermissionsActionHelper.fetchItemUsers(dispatch, { |
| 76 | itemId, |
| 77 | allUsers: usersList |
| 78 | }).then(() => |
| 79 | VersionsPageActionHelper.fetchVersions(dispatch, { |
| 80 | itemType: versionItemTypes.LICENSE_MODEL, |
| 81 | itemId |
| 82 | }).then(() => |
| 83 | ScreensHelper.loadScreen(dispatch, { |
| 84 | screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW, |
| 85 | screenType: screenTypes.LICENSE_MODEL, |
| 86 | props: { licenseModelId: itemId, version } |
| 87 | }) |
| 88 | ) |
| 89 | ) |
| 90 | ); |
| 91 | }); |
| 92 | }, |
| 93 | onValidateForm: formName => |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 94 | ValidationHelper.validateForm(dispatch, formName), |
| 95 | isNameUnique: (value, name, formName) => |
| 96 | UniqueTypesHelper.isNameUnique(dispatch, { |
| 97 | value, |
| 98 | name, |
| 99 | formName, |
| 100 | errorText: `${i18n( |
| 101 | 'License model by the name' |
| 102 | )} ${value} ${i18n('already exists')}. ${i18n( |
| 103 | 'License model name must be unique' |
| 104 | )}`, |
| 105 | itemType: itemType.VLM |
| 106 | }) |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 107 | }; |
Michael Lando | efa037d | 2017-02-19 12:57:33 +0200 | [diff] [blame] | 108 | }; |
| 109 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 110 | export default connect(mapStateToProps, mapActionsToProps)( |
svishnev | 8ae8f7e | 2018-07-02 14:05:17 +0300 | [diff] [blame^] | 111 | LicenseModelCreationView |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 112 | ); |