caremyway-client/src/reducers/userReducer.js

109 lines
2.5 KiB
JavaScript
Raw Normal View History

import {
IS_SENDING_USER_REQUEST,
SET_USER_REQUEST_ERROR,
CLEAR_USER_REQUEST_ERROR,
SET_USER_REQUEST_SUCCESS,
CLEAR_USER_REQUEST_SUCCESS,
SET_SELF_USER,
SET_COMPLETE_REGISTRATION_STEP,
SET_COMPLETE_REGISTRATION_CLIENT_OR_PROVIDER,
SET_FORM_PHONE_NUMBER,
SET_FORM_BUSINESS_NUMBER,
SET_FORM_SOCIAL_INSURANCE_NUMBER,
SET_EDIT_PROFILE_TAB_ACTIVE_INDEX,
2018-01-21 19:01:59 +00:00
SET_CLEAR_USER_STATE,
USER_INFO_STEP,
CLIENT
} from "../constants/user.constants";
const initialState = {
isSendingUserRequest: false,
userRequestError: "",
userRequestSuccess: "",
selfUser: {},
completeRegistrationCurrentStep: USER_INFO_STEP,
completeRegistrationMaxStep: USER_INFO_STEP,
completeRegistrationClientOrProvider: CLIENT,
phoneNumber: "",
businessNumber: "",
socialInsuranceNumber: "",
editProfileActiveIndex: 0
};
function userReducer(state = initialState, action) {
switch (action.type) {
case IS_SENDING_USER_REQUEST:
return {
...state,
isSendingUserRequest: action.data
};
case SET_USER_REQUEST_ERROR:
return {
...state,
userRequestError: action.data
};
case CLEAR_USER_REQUEST_ERROR:
return {
...state,
userRequestError: ""
};
case SET_USER_REQUEST_SUCCESS:
return {
...state,
userRequestSuccess: action.data
};
case CLEAR_USER_REQUEST_SUCCESS:
return {
...state,
userRequestSuccess: ""
};
case SET_SELF_USER:
return {
...state,
selfUser: action.data
};
case SET_COMPLETE_REGISTRATION_STEP:
return {
...state,
completeRegistrationCurrentStep: action.data,
completeRegistrationMaxStep: Math.max(
action.data,
state.completeRegistrationMaxStep
)
};
case SET_COMPLETE_REGISTRATION_CLIENT_OR_PROVIDER:
return {
...state,
completeRegistrationClientOrProvider: action.data
};
case SET_FORM_PHONE_NUMBER:
return {
...state,
phoneNumber: action.data
};
case SET_FORM_BUSINESS_NUMBER:
return {
...state,
businessNumber: action.data
};
case SET_FORM_SOCIAL_INSURANCE_NUMBER:
return {
...state,
socialInsuranceNumber: action.data
};
case SET_EDIT_PROFILE_TAB_ACTIVE_INDEX:
return {
...state,
editProfileActiveIndex: action.data
};
2018-01-21 19:01:59 +00:00
case SET_CLEAR_USER_STATE:
return {
...initialState
};
default:
return state;
}
}
export default userReducer;