5fa85daad8e0e9084c33e366bdd67ed78f990fd4
[aai/sparky-fe.git] / src / generic-components / dateRangeSelector / DateRangeSelectorReducer.js
1 /*
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 import {dateRangeActionTypes} from 'generic-components/dateRange/DateRangeConstants.js';
27 import {dateRangeSelectorActionTypes} from 'generic-components/dateRangeSelector/DateRangeSelectorConstants.js';
28 import {MESSAGE_LEVEL_DANGER} from 'utils/GlobalConstants.js';
29
30 export default (state = {}, action) => {
31
32   switch (action.type) {
33
34     case dateRangeActionTypes.DATE_RANGE_CHANGE:
35       return {
36         ...state,
37         startDate: action.data.dateRange.startDate,
38         endDate: action.data.dateRange.endDate,
39         periodErrText: '',
40         periodErrSev: ''
41       };
42
43     case dateRangeActionTypes.INVALID_DATE_RANGE:
44       return {
45         ...state,
46         startDate: action.data.dateRange.startDate,
47         endDate: action.data.dateRange.endDate,
48         periodErrText: action.data.errorMsg,
49         periodErrSev: MESSAGE_LEVEL_DANGER
50       };
51
52     case dateRangeSelectorActionTypes.EVENT_PERIOD_CHANGE:
53       return {
54         ...state,
55         startDate: action.data.dateRange.startDate,
56         endDate: action.data.dateRange.endDate,
57         period: action.data.period,
58         periodErrText: '',
59         periodErrSev: ''
60       };
61   }
62   return state;
63 };