2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 import i18n from 'utils/i18n/i18n';
24 import moment from 'moment';
28 DATE_PICKER_PLACEHOLDER,
33 } from 'generic-components/dateRange/DateRangeConstants';
35 function buildInvalidDateRangeAction(startDate, endDate, errorMessage) {
37 type: dateRangeActionTypes.INVALID_DATE_RANGE,
43 errorMsg: errorMessage
48 function buildDateRangeAction(startDate, endDate) {
50 type: dateRangeActionTypes.DATE_RANGE_CHANGE,
61 onStartDateChange(startDate, endDate) {
62 if (endDate && endDate.isBefore(startDate)) {
63 var errorMessage = i18n(START_DATE) +
65 moment(new Date(startDate)).format(DATE_PICKER_PLACEHOLDER) +
67 i18n(IS_AFTER_END_DATE);
68 return buildInvalidDateRangeAction(startDate, endDate, errorMessage);
70 return buildDateRangeAction(startDate, endDate);
73 onEndDateChange(startDate, endDate) {
74 if (startDate && startDate.isAfter(endDate)) {
75 var errorMessage = i18n(END_DATE) +
77 moment(new Date(endDate)).format(DATE_PICKER_PLACEHOLDER) +
79 i18n(IS_BEFORE_START_DATE);
80 return buildInvalidDateRangeAction(startDate, endDate, errorMessage);
82 return buildDateRangeAction(startDate, endDate);