refoundStatisticsReducer.js 1.67 KB
'use strict';

import InitialState from './refoundStatisticsInitialState';

import Immutable, {List, Record} from 'immutable';

const {
    REFOUND_STATS_REQUEST,
    REFOUND_STATS_SUCCESS,
    REFOUND_STATS_FAILURE,
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function refoundStatisticsReducer(state = initialState, action) {
    if (!(state instanceof InitialState)) return initialState.merge(state);

    switch (action.type) {
        case REFOUND_STATS_REQUEST:{
            let nextState =  state.set('isFetching', true)
				.set('error', null)
			return nextState;
        }
            break;
        case REFOUND_STATS_SUCCESS: {
            let nextState =  state.set('isFetching', false)
                .set('error', null)
                .set('refoundSum', action.payload.refoundSum)
                .set('sumRatio', action.payload.sumRatio)
                .set('sumRise', action.payload.sumRise)
                .set('refoundCount', action.payload.refoundCount)
                .set('countRatio',action.payload.countRatio)
                .set('countRise',action.payload.countRise)
                .set('refoundPercent',action.payload.refoundPercent)
                .set('percentRatio',action.payload.percentRatio)
                .set('percentRise',action.payload.percentRise)
                .setIn('trendInSixMonth', Immutable.fromJS(action.payload.trendInSixMonth));
            return nextState;
        }
            break;
        case REFOUND_STATS_FAILURE: {
            return state.set('isFetching', false)
	      		.set('error', action.payload);
        }
            break;
        default:
    }

    return state;
}