Commit 1277bb91 authored by Shaphen Pangburn's avatar Shaphen Pangburn

[AFP-131 Shaphen Pangburn, Joe Lu]: Add user iamge url to global state

parent 1c287b9e
...@@ -2,11 +2,16 @@ import {postUser} from '../util/session-api-util' ...@@ -2,11 +2,16 @@ import {postUser} from '../util/session-api-util'
export const SET_CURRENT_USER = "SET_CURRENT_USER" export const SET_CURRENT_USER = "SET_CURRENT_USER"
export const LOGOUT_USER = "LOGOUT_USER" export const LOGOUT_USER = "LOGOUT_USER"
export const SET_USER_IMAGE = "SET_USER_IMAGE"
export const setCurrentUser = (user) => { export const setCurrentUser = (user) => {
return {type: SET_CURRENT_USER, user} return {type: SET_CURRENT_USER, user}
} }
export const setUserImage = (image) => {
return {type: SET_USER_IMAGE, image}
}
export const logoutUser = () => { export const logoutUser = () => {
return {type: LOGOUT_USER} return {type: LOGOUT_USER}
} }
...@@ -17,6 +22,10 @@ export const login = (user) => dispatch => { ...@@ -17,6 +22,10 @@ export const login = (user) => dispatch => {
) )
) )
} }
export const addUserImage = image => dispatch => {
return dispatch(setUserImage(image))
}
// export const login = () => { // export const login = () => {
// return (dispatch) => { // return (dispatch) => {
// return dispatch(setCurrentUser()); // return dispatch(setCurrentUser());
......
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Session from './session'; import Session from './session';
import {login, logOut} from '../../actions/session_actions'; import {login, logOut, addUserImage} from '../../actions/session_actions';
import { fetchUserCart, createUserCart, clearUserCart } from '../../actions/cart_actions'; import { fetchUserCart, createUserCart, clearUserCart } from '../../actions/cart_actions';
const mSTP = state => ({ const mSTP = state => ({
...@@ -9,6 +9,7 @@ const mSTP = state => ({ ...@@ -9,6 +9,7 @@ const mSTP = state => ({
const mDTP = dispatch => ({ const mDTP = dispatch => ({
login: (userResponse) => dispatch(login(userResponse)), login: (userResponse) => dispatch(login(userResponse)),
addUserImage: image => dispatch(addUserImage(image)),
logOut: () => dispatch(logOut()), logOut: () => dispatch(logOut()),
getUserCart: userId => dispatch(fetchUserCart(userId)), getUserCart: userId => dispatch(fetchUserCart(userId)),
createCart: newCart => dispatch(createUserCart(newCart)), createCart: newCart => dispatch(createUserCart(newCart)),
......
...@@ -18,10 +18,12 @@ export default class Session extends Component { ...@@ -18,10 +18,12 @@ export default class Session extends Component {
} }
loginSuccess = (response) => { loginSuccess = (response) => {
console.log(response);
const {accessToken, tokenId, googleId: userId, profileObj} = response const {accessToken, tokenId, googleId: userId, profileObj} = response
const {email, familyName: lastName, givenName: firstName} = profileObj const {email, familyName: lastName, givenName: firstName, imageUrl} = profileObj
const userResponse = {idToken: tokenId, userId, email, firstName, lastName, accessToken} const userResponse = {idToken: tokenId, userId, email, firstName, lastName, accessToken}
this.props.login(userResponse) this.props.login(userResponse)
this.props.addUserImage(imageUrl)
this.setState({logIn: true}) this.setState({logIn: true})
// try grabbing user cart // try grabbing user cart
...@@ -56,11 +58,7 @@ export default class Session extends Component { ...@@ -56,11 +58,7 @@ export default class Session extends Component {
onSuccess={this.loginSuccess} onSuccess={this.loginSuccess}
onFailure={this.loginFailed} onFailure={this.loginFailed}
cookiePolicy={'single_host_origin'} cookiePolicy={'single_host_origin'}
/> : <GoogleLogout /> : ""
clientId={clientId}
buttonText="Logout"
onLogoutSuccess={this.logOutSuccess}
></GoogleLogout>
} }
</div> </div>
) )
......
import {SET_CURRENT_USER, LOGOUT_USER} from '../actions/session_actions' import {SET_CURRENT_USER, LOGOUT_USER, SET_USER_IMAGE} from '../actions/session_actions'
const initialState = { const initialState = {
currentUser: null, currentUser: null,
userImage: null
} }
const userReducer = (state = initialState, action) => { const userReducer = (state = initialState, action) => {
...@@ -11,6 +12,9 @@ const userReducer = (state = initialState, action) => { ...@@ -11,6 +12,9 @@ const userReducer = (state = initialState, action) => {
case SET_CURRENT_USER: case SET_CURRENT_USER:
newState.currentUser = action.user.data; newState.currentUser = action.user.data;
return newState; return newState;
case SET_USER_IMAGE:
newState.userImage = action.image;
return newState;
case LOGOUT_USER: case LOGOUT_USER:
return newState.currentUser = null; return newState.currentUser = null;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment