studentReducer.js 3.86 KB
'use strict';

import InitialState from './studentInitialState';
import Immutable, {Map} from 'immutable';

const {
	SET_PLATFORM,
	SET_ZIMA_URL,

	QUERY_REGISTER_PAGE_INFO_REQUEST,
	QUERY_REGISTER_PAGE_INFO_SUCCESS,
	QUERY_REGISTER_PAGE_INFO_FAILURE,

	QUERY_PROVINCE_REQUEST,
	QUERY_PROVINCE_SUCCESS,
	QUERY_PROVINCE_FAILURE,

	QUERY_STUDENT_PRODUCTS_REQUEST,
	QUERY_STUDENT_PRODUCTS_SUCCESS,
	QUERY_STUDENT_PRODUCTS_FAILURE,

	QUERY_SCHOOL_INFO_LIST_REQUEST,
	QUERY_SCHOOL_INFO_LIST_SUCCESS,
	QUERY_SCHOOL_INFO_LIST_FAILURE,

	UPDATE_REGISTER_PAGE_CELLS,
	UPDATE_CUR_SCHOOL_INFO,
	UPDATE_PROVINCE_SCHOOL_PAGE_INFO,
	UPDATE_PICKER_INFO,
	UPDATE_SEARCH_RESULT_PAGE_INFO,

	SELECT_PROVINCE_ITEM,
	SELECT_SCHOOL_ITEM,
	CHECK_AGREE_YOHO_PROTOCOL,

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

const initialState = new InitialState;

export default function studentReducer(state=initialState, action) {
    switch(action.type) {
		case SET_ZIMA_URL:{
			return state.set('zimaRegisterUrl', action.payload);
		}
        case QUERY_REGISTER_PAGE_INFO_REQUEST: {
            return state.setIn(['registerPageInfo', 'isFetching'], true);
        }
		case QUERY_REGISTER_PAGE_INFO_SUCCESS: {
			return state.setIn(['registerPageInfo', 'isFetching'], false)
			.setIn(['registerPageInfo', 'verifiedStudentTotal'], action.payload.studentTotal)
			.setIn(['registerPageInfo', 'educationLevelList'], Immutable.fromJS(action.payload.educationLevelList))
			.setIn(['registerPageInfo', 'schoolYearList'], Immutable.fromJS(action.payload.schoolYearList))
			.setIn(['registerPageInfo', 'error'], null);
		}
		case QUERY_REGISTER_PAGE_INFO_FAILURE: {
			return state.setIn(['registerPageInfo', 'isFetching'], false)
			.setIn(['registerPageInfo', 'error'], action.payload);
		}

		case QUERY_STUDENT_PRODUCTS_REQUEST: {
			return state.setIn(['productPageInfo', 'isFetching'], true);
		}
		case QUERY_STUDENT_PRODUCTS_SUCCESS:{
			return state.setIn(['productPageInfo','studentProducts'],Immutable.fromJS(action.payload));
		}
		case QUERY_STUDENT_PRODUCTS_FAILURE:{
			return state.setIn(['productPageInfo', 'isFetching'], false)
			.setIn(['productPageInfo', 'error'], action.payload);
		}
		case UPDATE_REGISTER_PAGE_CELLS: {
			return state.setIn(['registerPageInfo', 'registerPageCells'], action.payload.newRegisterPageCells)
			.setIn(['registerPageInfo','registerNowEnable'], action.payload.registerNowEnable);
		}
		case QUERY_PROVINCE_SUCCESS: {
			return state.setIn(['registerPageInfo', 'provinceWithLatterList'], Immutable.fromJS(action.payload.latterProvincelistSort))
			.setIn(['registerPageInfo', 'provinceLatterList'], Immutable.fromJS(action.payload.latterList));
		}
		case QUERY_SCHOOL_INFO_LIST_SUCCESS: {
			return state.setIn(['registerPageInfo', 'schoolCodeValueInfo'], Immutable.fromJS(action.payload.schoolCodeValueInfo))
			.setIn(['registerPageInfo', 'curSchoolListInfo'], Immutable.fromJS(action.payload.curSchoolInfo));
		}
		case UPDATE_PROVINCE_SCHOOL_PAGE_INFO: {
			return state.setIn(['registerPageInfo', 'provinceSchoolPageInfo'], Immutable.fromJS(action.payload));
		}
		case UPDATE_SEARCH_RESULT_PAGE_INFO: {
			return state.setIn(['registerPageInfo', 'searchResultPageInfo'], Immutable.fromJS(action.payload));
		}
		case UPDATE_PICKER_INFO: {
			return state.setIn(['registerPageInfo', 'pickerInfo'],action.payload);
		}
		case SELECT_PROVINCE_ITEM: {
			return state.setIn(['registerPageInfo', 'curProvinceItem'], Immutable.fromJS(action.payload));
		}
		case SELECT_SCHOOL_ITEM: {
			return state.setIn(['registerPageInfo', 'cueSchoolItem'], Immutable.fromJS(action.payload));
		}
		case SHOW_TIP_MESSAGE: {
			return state.set('tipMessage',action.payload);
		}
		case HIDE_TIP_MESSAGE: {
			return state.set('tipMessage','');
		}
		case CHECK_AGREE_YOHO_PROTOCOL: {
			return state.setIn(['registerPageInfo', 'agreeYohoProtocol'], action.payload);
		}
    }

    return state;
}