All files / date-picker index.js

93.33% Statements 14/15
62.5% Branches 5/8
100% Functions 12/12
93.33% Lines 14/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49            26x             12x                       11x 1x 1x 1x 1x 1x 1x 1x 1x   2x 2x 2x                      
import moment from 'moment';
import { connect } from 'react-redux';
import DatePicker from './components/DatePicker';
import { actions } from './reducer';
 
export function convertDateToTimestamp(date) {
  return date ?
    moment(date, 'MM/DD/YYYY').unix() :
    null;
}
 
// default export = container
export default connect(
  (state, ownProps) => ({
    loading: ownProps.staticData ? false : state.date.loading,
    startDate: convertDateToTimestamp(state.date.startDate),
    endDate: convertDateToTimestamp(state.date.endDate),
    isOpen: state.date.open,
    calendarOpen: state.date.calendarOpen,
    minDate: ownProps.staticData ? null : state.date.minDate,
    maxDate: state.date.maxDate,
    month: state.date.month,
    presets: state.date.presets,
    // add state here
  }),
  dispatch => ({
    open: () => dispatch(actions.open()),
    close: () => dispatch(actions.close()),
    setMonth: timestamp => dispatch(actions.setMonth(timestamp)),
    setStartDate: date => dispatch(actions.setStartDate(date)),
    clearStartDate: () => dispatch(actions.clearStartDate()),
    clearEndDate: () => dispatch(actions.clearEndDate()),
    setEndDate: date => dispatch(actions.setEndDate(date)),
    setDateRange: (start, end) => dispatch(actions.setDateRange(start, end)),
    selectPreset: (preset) => {
      Eif (preset.range !== Infinity) {
        dispatch(actions.setDatePreset(preset));
        dispatch(actions.close());
      } else {
        dispatch(actions.openCalendar());
      }
    },
  }),
)(DatePicker);
 
// export reducer, actions and action types
export reducer, { actions, actionTypes, presets } from './reducer';
export middleware from './middleware';