accountSettlementReducer.js 1.23 KB
'use strict';

import AccountSettlementInitialState from './accountSettlementInitialState'
import Immutable, {List, Record} from 'immutable';

const {
    ACCOUNT_LIST_REQUEST,
    ACCOUNT_LIST_SUCCESS,
    ACCOUNT_LIST_FAILURE,

} = require('../../constants/actionTypes').default;

const initialState = new AccountSettlementInitialState;

export default function messageReducer(state = initialState, action) {

    if (!(state instanceof AccountSettlementInitialState)) return initialState.merge(state);
    switch (action.type) {
        case ACCOUNT_LIST_REQUEST: {
            let nextState =  state.set('isFetching', true)
            .set('error', null);
            return nextState;
        }
            break;
        case ACCOUNT_LIST_SUCCESS:{
            const {jsonData} = state;
            let origin = jsonData.toJS();
            let data = [...origin, ...action.payload];
            let nextState =  state.set('isFetching',false).set('jsonData', List(data));
            return nextState;
        }
            break;
        case ACCOUNT_LIST_FAILURE:{
            let nextState = state.set('isFetching',false)
            .set('error',action.playload);
            return nextState;
        }
            break;

    }

    return state;
}