talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 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 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { connect } from 'react-redux'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 17 | import VersionsPageCreationActionHelper from './VersionsPageCreationActionHelper.js'; |
| 18 | import VersionsPageActionHelper from '../VersionsPageActionHelper.js'; |
| 19 | import VersionsPageCreationView from './VersionsPageCreationView.jsx'; |
| 20 | import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 21 | import { VERSION_CREATION_FORM_NAME } from './VersionsPageCreationConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 23 | export const mapStateToProps = ({ versionsPage: { versionCreation } }) => { |
| 24 | let { genericFieldInfo } = versionCreation; |
| 25 | let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 27 | return { ...versionCreation, isFormValid }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 30 | export const mapActionsToProps = ( |
| 31 | dispatch, |
| 32 | { itemId, itemType, additionalProps } |
| 33 | ) => { |
| 34 | return { |
| 35 | onDataChanged: (deltaData, customValidations) => |
| 36 | ValidationHelper.dataChanged(dispatch, { |
| 37 | deltaData, |
| 38 | formName: VERSION_CREATION_FORM_NAME, |
| 39 | customValidations |
| 40 | }), |
| 41 | onCancel: () => VersionsPageCreationActionHelper.close(dispatch), |
| 42 | onSubmit: ({ baseVersion, payload }) => { |
| 43 | VersionsPageCreationActionHelper.close(dispatch); |
| 44 | VersionsPageCreationActionHelper.createVersion(dispatch, { |
| 45 | baseVersion, |
| 46 | itemId, |
| 47 | payload |
| 48 | }).then(response => { |
| 49 | VersionsPageActionHelper.onNavigateToVersion(dispatch, { |
| 50 | version: response, |
| 51 | itemId, |
| 52 | itemType, |
| 53 | additionalProps |
| 54 | }); |
| 55 | }); |
| 56 | }, |
| 57 | onValidateForm: () => |
| 58 | ValidationHelper.validateForm(dispatch, VERSION_CREATION_FORM_NAME) |
| 59 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 62 | export default connect(mapStateToProps, mapActionsToProps)( |
| 63 | VersionsPageCreationView |
| 64 | ); |