Fix license key group and entitlement pools required fields
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / entitlementPools / EntitlementPoolsEditorReducer.js
1 /*!
2  * Copyright © 2016-2018 European Support Limited
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 {
17     actionTypes,
18     defaultState,
19     SP_ENTITLEMENT_POOL_FORM
20 } from './EntitlementPoolsConstants.js';
21 import moment from 'moment';
22 import { DATE_FORMAT } from 'sdc-app/onboarding/OnboardingConstants.js';
23
24 export default (state = {}, action) => {
25     switch (action.type) {
26         case actionTypes.entitlementPoolsEditor.OPEN:
27             let entitlementPoolData = { ...action.entitlementPool };
28             let { startDate, expiryDate } = entitlementPoolData;
29             if (startDate) {
30                 entitlementPoolData.startDate = moment(
31                     startDate,
32                     DATE_FORMAT
33                 ).format(DATE_FORMAT);
34             }
35             if (expiryDate) {
36                 entitlementPoolData.expiryDate = moment(
37                     expiryDate,
38                     DATE_FORMAT
39                 ).format(DATE_FORMAT);
40             }
41             return {
42                 ...state,
43                 formReady: null,
44                 formName: SP_ENTITLEMENT_POOL_FORM,
45                 genericFieldInfo: {
46                     name: {
47                         isValid: true,
48                         errorText: '',
49                         validations: [
50                             { type: 'required', data: true },
51                             { type: 'maxLength', data: 120 },
52                             { type: 'validateName', data: true }
53                         ]
54                     },
55                     description: {
56                         isValid: true,
57                         errorText: '',
58                         validations: [{ type: 'maxLength', data: 1000 }]
59                     },
60                     type: {
61                         isValid: true,
62                         errorText: '',
63                         validations: [{ type: 'required', data: true }]
64                     },
65                     increments: {
66                         isValid: true,
67                         errorText: '',
68                         validations: [{ type: 'maxLength', data: 120 }]
69                     },
70                     thresholdUnits: {
71                         isValid: true,
72                         errorText: '',
73                         validations: []
74                     },
75                     thresholdValue: {
76                         isValid: true,
77                         errorText: '',
78                         validations: []
79                     },
80                     startDate: {
81                         isValid: true,
82                         errorText: '',
83                         validations: []
84                     },
85                     expiryDate: {
86                         isValid: true,
87                         errorText: '',
88                         validations: []
89                     },
90                     manufacturerReferenceNumber: {
91                         isValid: true,
92                         errorText: '',
93                         validations: [
94                             { type: 'required', data: true },
95                             { type: 'maxLength', data: 100 },
96                             { type: 'validateName', data: true }
97                         ]
98                     }
99                 },
100                 data: action.entitlementPool
101                     ? entitlementPoolData
102                     : defaultState.ENTITLEMENT_POOLS_EDITOR_DATA
103             };
104         case actionTypes.entitlementPoolsEditor.DATA_CHANGED:
105             return {
106                 ...state,
107                 data: {
108                     ...state.data,
109                     ...action.deltaData
110                 }
111             };
112         case actionTypes.entitlementPoolsEditor.CLOSE:
113             return {};
114
115         case actionTypes.entitlementPoolsEditor.LIMITS_LIST_LOADED:
116             return {
117                 ...state,
118                 limitsList: action.response.results
119             };
120         default:
121             return state;
122     }
123 };