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
72c2834d
Commit
72c2834d
authored
May 10, 2021
by
Shaphen Pangburn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[AFP-48 Shaphen Pangburn]: Add redux cycle to persist user cart to global state
parent
7ebecb53
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
6 deletions
+53
-6
cart_actions.js
ecom-web/src/actions/cart_actions.js
+11
-0
product_actions.js
ecom-web/src/actions/product_actions.js
+1
-1
product-item.jsx
ecom-web/src/components/product-market/product-item.jsx
+24
-1
product-market-container.jsx
...rc/components/product-market/product-market-container.jsx
+4
-1
product-market.jsx
ecom-web/src/components/product-market/product-market.jsx
+1
-0
user_reducer.js
ecom-web/src/reducers/user_reducer.js
+7
-3
cart_api_util.js
ecom-web/src/util/cart_api_util.js
+5
-0
No files found.
ecom-web/src/actions/cart_actions.js
0 → 100644
View file @
72c2834d
import
*
as
ApiUtil
from
'../util/cart_api_util'
;
export
const
RECEIVE_USER_CART
=
"RECEIVE_USER_CART"
;
const
receiveUserCart
=
cart
=>
({
type
:
RECEIVE_USER_CART
,
cart
})
export
const
fetchUserCart
=
userId
=>
dispatch
=>
ApiUtil
.
fetchUserCart
(
userId
)
.
then
(
cart
=>
dispatch
(
receiveUserCart
(
cart
)));
\ No newline at end of file
ecom-web/src/actions/product_actions.js
View file @
72c2834d
ecom-web/src/components/product-market/product-item.jsx
View file @
72c2834d
...
...
@@ -7,6 +7,7 @@ export default class ProductItem extends Component {
constructor
(
props
)
{
super
(
props
)
this
.
state
=
{
orderItemQuantity
:
0
,
showDetailsModal
:
false
}
this
.
handleSubmit
=
this
.
handleSubmit
.
bind
(
this
);
...
...
@@ -18,12 +19,29 @@ export default class ProductItem extends Component {
this
.
setState
({
showDetailsModal
:
!
prevState
});
}
handleChange
(
type
)
{
return
e
=>
{
this
.
setState
({
[
type
]:
e
.
target
.
value
})
}
}
calculateDiscount
(
price
,
discount
)
{
return
(
price
*
((
100
-
discount
)
/
100
)).
toFixed
(
2
);
}
handleSubmit
(
e
,
product
)
{
e
.
preventDefault
();
// const newCart = Object.assign({}, this.props.cart);
// const newCartItem = {
// productRef: {
// id: product.sku,
// sku: product.sku,
// upc: product.upc,
// },
// quantity: this.state.orderItemQuantity;
// }
// newCart.cartItems.push(newCartItem);
// this.ptops.addCartItem(newCart);
}
render
()
{
...
...
@@ -56,7 +74,12 @@ export default class ProductItem extends Component {
{
"Save "
+
this
.
props
.
item
.
promo
+
"% on this item!"
}
</
p
>
:
""
}
<
form
onSubmit=
{
e
=>
this
.
handleSubmit
(
e
,
this
.
props
.
item
)
}
className=
"add-cart-and-quantity"
>
<
input
className=
"order-quantity"
type=
"number"
placeholder=
"Qty"
/>
<
input
className=
"order-quantity"
type=
"number"
placeholder=
"Qty"
onChange=
{
this
.
handleChange
(
"orderItemQuantity"
)
}
/>
<
button
className=
"add-to-cart-button"
>
Add to Cart
</
button
>
</
form
>
...
...
ecom-web/src/components/product-market/product-market-container.jsx
View file @
72c2834d
import
{
connect
}
from
'react-redux'
;
import
ProductMarket
from
'./product-market'
;
import
{
fetchProducts
,
fetchPromotions
}
from
'../../actions/product_actions'
;
import
{
fetchUserCart
}
from
'../../actions/cart_actions'
;
const
mSTP
=
state
=>
({
products
:
state
.
market
.
products
,
promotions
:
state
.
market
.
promotions
,
user
:
state
.
user
});
const
mDTP
=
dispatch
=>
({
getProducts
:
()
=>
dispatch
(
fetchProducts
()),
getPromotions
:
()
=>
dispatch
(
fetchPromotions
())
getPromotions
:
()
=>
dispatch
(
fetchPromotions
()),
getUserCart
:
userId
=>
dispatch
(
fetchUserCart
(
userId
))
});
export
default
connect
(
mSTP
,
mDTP
)(
ProductMarket
);
\ No newline at end of file
ecom-web/src/components/product-market/product-market.jsx
View file @
72c2834d
...
...
@@ -14,6 +14,7 @@ export default class ProductMarket extends Component {
componentDidMount
()
{
this
.
props
.
getProducts
();
this
.
props
.
getPromotions
();
// this.props.getUserCart(this.props.user.emailAddress);
}
render
()
{
...
...
ecom-web/src/reducers/user_reducer.js
View file @
72c2834d
import
{
SET_CURRENT_USER
,
LOGOUT_USER
}
from
'../actions/session_actions'
import
{
RECEIVE_USER_CART
}
from
'../actions/cart_actions'
;
const
initialState
=
{
currentUser
:
null
}
const
initialState
=
{
currentUser
:
null
,
cart
:
{},
}
const
userReducer
=
(
state
=
initialState
,
action
)
=>
{
Object
.
freeze
(
state
);
let
newState
=
Object
.
assign
({},
state
);
switch
(
action
.
type
)
{
case
SET_CURRENT_USER
:
return
newState
.
currentUser
=
{
emailAddress
:
'fakeEmail@123'
};
case
LOGOUT_USER
:
return
newState
.
currentUser
=
null
;
case
RECEIVE_USER_CART
:
return
newState
.
cart
=
action
.
cart
default
:
return
state
;
}
...
...
ecom-web/src/util/cart_api_util.js
0 → 100644
View file @
72c2834d
import
axios
from
'axios'
;
export
const
fetchUserCart
=
userId
=>
{
return
axios
.
get
(
`http://localhost:8080/api/carts/
${
userId
}
`
)
}
\ No newline at end of file
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