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
198d7348
Commit
198d7348
authored
May 11, 2021
by
Shaphen Pangburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-48 Shaphen Pangburn]: Clear global state cart when logging out
parent
39ca21a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
3 deletions
+12
-3
cart_actions.js
ecom-web/src/actions/cart_actions.js
+5
-0
session-container.jsx
ecom-web/src/components/session/session-container.jsx
+3
-2
session.jsx
ecom-web/src/components/session/session.jsx
+1
-0
cart_reducer.js
ecom-web/src/reducers/cart_reducer.js
+3
-1
No files found.
ecom-web/src/actions/cart_actions.js
View file @
198d7348
import
*
as
ApiUtil
from
'../util/cart_api_util'
;
export
const
RECEIVE_USER_CART
=
"RECEIVE_USER_CART"
;
export
const
CLEAR_USER_CART
=
"CLEAR_USER_CART"
;
const
receiveUserCart
=
cart
=>
({
type
:
RECEIVE_USER_CART
,
cart
})
export
const
clearUserCart
=
()
=>
({
type
:
CLEAR_USER_CART
})
export
const
fetchUserCart
=
userEmail
=>
dispatch
=>
ApiUtil
.
fetchUserCart
(
userEmail
)
.
then
(
cart
=>
dispatch
(
receiveUserCart
(
cart
)));
...
...
ecom-web/src/components/session/session-container.jsx
View file @
198d7348
import
{
connect
}
from
'react-redux'
;
import
Session
from
'./session'
;
import
{
login
,
logOut
}
from
'../../actions/session_actions'
;
import
{
fetchUserCart
,
createUserCart
}
from
'../../actions/cart_actions'
;
import
{
fetchUserCart
,
createUserCart
,
clearUserCart
}
from
'../../actions/cart_actions'
;
const
mSTP
=
state
=>
({
currentUser
:
state
.
user
...
...
@@ -11,7 +11,8 @@ const mDTP = dispatch => ({
login
:
(
userResponse
)
=>
dispatch
(
login
(
userResponse
)),
logOut
:
()
=>
dispatch
(
logOut
()),
getUserCart
:
userId
=>
dispatch
(
fetchUserCart
(
userId
)),
createCart
:
newCart
=>
dispatch
(
createUserCart
(
newCart
))
createCart
:
newCart
=>
dispatch
(
createUserCart
(
newCart
)),
clearCart
:
()
=>
dispatch
(
clearUserCart
())
});
export
default
connect
(
mSTP
,
mDTP
)(
Session
);
\ No newline at end of file
ecom-web/src/components/session/session.jsx
View file @
198d7348
...
...
@@ -42,6 +42,7 @@ export default class Session extends Component {
logOutSuccess
=
(
response
)
=>
{
this
.
props
.
logOut
()
this
.
props
.
clearCart
()
this
.
setState
({
logIn
:
false
})
}
...
...
ecom-web/src/reducers/cart_reducer.js
View file @
198d7348
import
{
RECEIVE_USER_CART
}
from
'../actions/cart_actions'
;
import
{
RECEIVE_USER_CART
,
CLEAR_USER_CART
}
from
'../actions/cart_actions'
;
const
initialState
=
[]
...
...
@@ -8,6 +8,8 @@ const cartReducer = (state = initialState, action) => {
switch
(
action
.
type
)
{
case
RECEIVE_USER_CART
:
return
newState
.
cart
=
action
.
cart
.
data
.
cartItems
case
CLEAR_USER_CART
:
return
[]
default
:
return
state
;
}
...
...
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