Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ecommerce-maven
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
ecommerce-maven
Commits
1277bb91
Commit
1277bb91
authored
May 13, 2021
by
Shaphen Pangburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-131 Shaphen Pangburn, Joe Lu]: Add user iamge url to global state
parent
1c287b9e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
8 deletions
+20
-8
session_actions.js
ecom-web/src/actions/session_actions.js
+9
-0
session-container.jsx
ecom-web/src/components/session/session-container.jsx
+2
-1
session.jsx
ecom-web/src/components/session/session.jsx
+4
-6
user_reducer.js
ecom-web/src/reducers/user_reducer.js
+5
-1
No files found.
ecom-web/src/actions/session_actions.js
View file @
1277bb91
...
...
@@ -2,11 +2,16 @@ import {postUser} from '../util/session-api-util'
export
const
SET_CURRENT_USER
=
"SET_CURRENT_USER"
export
const
LOGOUT_USER
=
"LOGOUT_USER"
export
const
SET_USER_IMAGE
=
"SET_USER_IMAGE"
export
const
setCurrentUser
=
(
user
)
=>
{
return
{
type
:
SET_CURRENT_USER
,
user
}
}
export
const
setUserImage
=
(
image
)
=>
{
return
{
type
:
SET_USER_IMAGE
,
image
}
}
export
const
logoutUser
=
()
=>
{
return
{
type
:
LOGOUT_USER
}
}
...
...
@@ -17,6 +22,10 @@ export const login = (user) => dispatch => {
)
)
}
export
const
addUserImage
=
image
=>
dispatch
=>
{
return
dispatch
(
setUserImage
(
image
))
}
// export const login = () => {
// return (dispatch) => {
// return dispatch(setCurrentUser());
...
...
ecom-web/src/components/session/session-container.jsx
View file @
1277bb91
import
{
connect
}
from
'react-redux'
;
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'
;
const
mSTP
=
state
=>
({
...
...
@@ -9,6 +9,7 @@ const mSTP = state => ({
const
mDTP
=
dispatch
=>
({
login
:
(
userResponse
)
=>
dispatch
(
login
(
userResponse
)),
addUserImage
:
image
=>
dispatch
(
addUserImage
(
image
)),
logOut
:
()
=>
dispatch
(
logOut
()),
getUserCart
:
userId
=>
dispatch
(
fetchUserCart
(
userId
)),
createCart
:
newCart
=>
dispatch
(
createUserCart
(
newCart
)),
...
...
ecom-web/src/components/session/session.jsx
View file @
1277bb91
...
...
@@ -18,10 +18,12 @@ export default class Session extends Component {
}
loginSuccess
=
(
response
)
=>
{
console
.
log
(
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
}
this
.
props
.
login
(
userResponse
)
this
.
props
.
addUserImage
(
imageUrl
)
this
.
setState
({
logIn
:
true
})
// try grabbing user cart
...
...
@@ -56,11 +58,7 @@ export default class Session extends Component {
onSuccess=
{
this
.
loginSuccess
}
onFailure=
{
this
.
loginFailed
}
cookiePolicy=
{
'single_host_origin'
}
/>
:
<
GoogleLogout
clientId=
{
clientId
}
buttonText=
"Logout"
onLogoutSuccess=
{
this
.
logOutSuccess
}
></
GoogleLogout
>
/>
:
""
}
</
div
>
)
...
...
ecom-web/src/reducers/user_reducer.js
View file @
1277bb91
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
=
{
currentUser
:
null
,
userImage
:
null
}
const
userReducer
=
(
state
=
initialState
,
action
)
=>
{
...
...
@@ -11,6 +12,9 @@ const userReducer = (state = initialState, action) => {
case
SET_CURRENT_USER
:
newState
.
currentUser
=
action
.
user
.
data
;
return
newState
;
case
SET_USER_IMAGE
:
newState
.
userImage
=
action
.
image
;
return
newState
;
case
LOGOUT_USER
:
return
newState
.
currentUser
=
null
;
default
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment