UNPKG

@zohodesk/hooks

Version:

Unified Component Library - Hooks

55 lines (47 loc) 1.29 kB
import * as constants from "./constants"; import { handleChange, handlePrevMonth, handleNextMonth, handlePrevYear, handleNextYear } from "./actions"; const calendarReducer = function (state, action) { let initialState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { value: '' }; let stateValue = initialState; const { data } = action; let newValue; switch (action.type) { case constants.CHANGE: newValue = handleChange(data); stateValue = { ...state, value: newValue }; return stateValue; case constants.PREV_MONTH: newValue = handlePrevMonth(data); stateValue = { ...state, value: newValue }; return stateValue; case constants.NEXT_MONTH: newValue = handleNextMonth(data); stateValue = { ...state, value: newValue }; return stateValue; case constants.PREV_YEAR: newValue = handlePrevYear(data); stateValue = { ...state, value: newValue }; return stateValue; case constants.NEXT_YEAR: newValue = handleNextYear(data); stateValue = { ...state, value: newValue }; return stateValue; default: return stateValue; } }; export default calendarReducer;