Fix license key group and entitlement pools required fields
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / licenseModel / licenseKeyGroups / LicenseKeyGroupsEditorReducer.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     LKG_FORM_NAME
20 } from './LicenseKeyGroupsConstants.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.licenseKeyGroupsEditor.OPEN:
27             let licenseKeyGroupData = { ...action.licenseKeyGroup };
28             let { startDate, expiryDate } = licenseKeyGroupData;
29             if (startDate) {
30                 licenseKeyGroupData.startDate = moment(
31                     startDate,
32                     DATE_FORMAT
33                 ).format(DATE_FORMAT);
34             }
35             if (expiryDate) {
36                 licenseKeyGroupData.expiryDate = moment(
37                     expiryDate,
38                     DATE_FORMAT
39                 ).format(DATE_FORMAT);
40             }
41             return {
42                 ...state,
43                 data: action.licenseKeyGroup
44                     ? licenseKeyGroupData
45                     : defaultState.licenseKeyGroupsEditor,
46                 formReady: null,
47                 formName: LKG_FORM_NAME,
48                 genericFieldInfo: {
49                     description: {
50                         isValid: true,
51                         errorText: '',
52                         validations: [{ type: 'maxLength', data: 1000 }]
53                     },
54                     name: {
55                         isValid: true,
56                         errorText: '',
57                         validations: [
58                             { type: 'required', data: true },
59                             { type: 'maxLength', data: 120 },
60                             { type: 'validateName', data: true }
61                         ]
62                     },
63                     type: {
64                         isValid: true,
65                         errorText: '',
66                         validations: [{ type: 'required', data: true }]
67                     },
68                     thresholdUnits: {
69                         isValid: true,
70                         errorText: '',
71                         validations: []
72                     },
73                     thresholdValue: {
74                         isValid: true,
75                         errorText: '',
76                         validations: []
77                     },
78                     increments: {
79                         isValid: true,
80                         errorText: '',
81                         validations: [{ type: 'maxLength', data: 120 }]
82                     },
83                     startDate: {
84                         isValid: true,
85                         errorText: '',
86                         validations: []
87                     },
88                     expiryDate: {
89                         isValid: true,
90                         errorText: '',
91                         validations: []
92                     },
93                     manufacturerReferenceNumber: {
94                         isValid: true,
95                         errorText: '',
96                         validations: [{ type: 'maxLength', data: 100 }]
97                     }
98                 }
99             };
100         case actionTypes.licenseKeyGroupsEditor.LIMITS_LIST_LOADED:
101             return {
102                 ...state,
103                 limitsList: action.response.results
104             };
105         case actionTypes.licenseKeyGroupsEditor.CLOSE:
106             return {};
107         default:
108             return state;
109     }
110 };