Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tobernguyen/c69e988f8dd2d7890d8c2622a385872d to your computer and use it in GitHub Desktop.
Save tobernguyen/c69e988f8dd2d7890d8c2622a385872d to your computer and use it in GitHub Desktop.
import { fromJS } from 'immutable';
import {
SIGN_IN_BY_EMAIL_REQUEST,
SIGN_IN_BY_EMAIL_SUCCESS,
SIGN_IN_BY_EMAIL_ERROR,
} from './constants';
const initialState = fromJS({
error: null,
user: null,
loading: false,
});
function loginReducer(state = initialState, action) {
const { type, payload } = action;
switch (type) {
case SIGN_IN_BY_EMAIL_REQUEST:
return state.merge(fromJS({
loading: true,
error: null,
}));
case SIGN_IN_BY_EMAIL_SUCCESS:
return state.merge(fromJS({
user: payload.user,
loading: false,
error: null,
}));
case SIGN_IN_BY_EMAIL_ERROR:
return state.merge(fromJS({
user: null,
loading: false,
error: payload.response,
}));
default:
return state;
}
}
export default loginReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment