blob: e0cb925df4af4c2068a0f495096f4b1ea92f7612 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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 Keidar7fdf7332018-03-20 14:45:40 +020016import { connect } from 'react-redux';
talig8e9c0652017-12-20 14:30:43 +020017import VersionsPageCreationActionHelper from './VersionsPageCreationActionHelper.js';
18import VersionsPageActionHelper from '../VersionsPageActionHelper.js';
19import VersionsPageCreationView from './VersionsPageCreationView.jsx';
20import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020021import { VERSION_CREATION_FORM_NAME } from './VersionsPageCreationConstants.js';
talig8e9c0652017-12-20 14:30:43 +020022
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023export const mapStateToProps = ({ versionsPage: { versionCreation } }) => {
24 let { genericFieldInfo } = versionCreation;
25 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
talig8e9c0652017-12-20 14:30:43 +020026
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027 return { ...versionCreation, isFormValid };
talig8e9c0652017-12-20 14:30:43 +020028};
29
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030export 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 };
talig8e9c0652017-12-20 14:30:43 +020060};
61
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020062export default connect(mapStateToProps, mapActionsToProps)(
63 VersionsPageCreationView
64);