Created
May 24, 2017 09:48
-
-
Save hieuhani/b1e5cbf79727b06eeffd09e7b0b76080 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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