import { AnyAction, combineReducers } from 'redux'; import { ForecastCalculations } from 'app/modules/forecast/store/forecast.types'; import { FORECAST } from './forecast.constants'; const defaultForecastDetailsState = { monthRate: 0, fixedRate: 0, unfixedRate: 0, fixedPercentage: 0, unfixedPercentage: 0, }; const forecastDetailsReducer = (state = defaultForecastDetailsState, action: AnyAction = { type: '' }) => { switch (action.type) { case FORECAST.FORECAST_SET_DETAILS: return { ...state, ...action.payload, }; default: return state; } }; const forecastAggregationsReducer = ( state: ForecastCalculations[] = [], action: AnyAction = { type: '' } ) => { switch (action.type) { case FORECAST.FORECAST_SET_AGGREGATIONS: return action.payload; default: return state; } }; const forecastSelectedAggregationReducer = (state: number | null = null, action: AnyAction = { type: '' }) => { switch (action.type) { case FORECAST.FORECAST_SELECT_AGGREGATION: return action.payload; default: return state; } }; const forecastReducer = combineReducers({ details: forecastDetailsReducer, aggregations: forecastAggregationsReducer, selectedAggregation: forecastSelectedAggregationReducer, }); export { forecastReducer };