Skip to content

Commit 5d69468

Browse files
committed
Product Grid quantity not resetting after adding to it cart #5
1 parent b7babf2 commit 5d69468

File tree

6 files changed

+36
-25
lines changed

6 files changed

+36
-25
lines changed

dist/app.bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<meta charset="utf-8">
44
<meta name="viewport" content="width=device-width, initial-scale=1.0">
55
<title>Veggy - React Shopping Cart Demo</title>
6-
<link rel="shortcut icon" href="favicon.ico" />
6+
<link rel="shortcut icon" href="favicon.ico" />
7+
78
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" />
89
<link rel="stylesheet" href="dist/style.css" />
910
<link rel="prefetch" href="https://res.cloudinary.com/sivadass/image/upload/v1494699523/icons/bare-tree.png" />
@@ -12,6 +13,5 @@
1213
<body>
1314
<div id="root"></div>
1415
<script src="dist/app.bundle.js"></script>
15-
<script async defer src="https://buttons.github.io/buttons.js"></script>
1616
</body>
1717
</html>

src/components/Counter.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ class Counter extends Component {
4040
})
4141
};
4242

43-
43+
resetQuantity(){
44+
this.setState({
45+
value: 1
46+
})
47+
}
4448
render() {
4549
return (
4650
<div className="stepper-input">

src/components/Footer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ const Footer = (props) =>{
44
return(
55
<footer>
66
<p className="footer-links">
7-
<a href="https://twitter.com/NSivadass" target="_blank">Say Hi on Twitter</a>
8-
<span> / </span>
97
<a href="https://github.com/sivadass/react-shopping-cart" target="_blank">View Source on Github</a>
108
<span> / </span>
9+
<a href="mailto:contact@sivadass.in" target="_blank">Need any help?</a>
10+
<span> / </span>
11+
<a href="https://twitter.com/NSivadass" target="_blank">Say Hi on Twitter</a>
12+
<span> / </span>
1113
<a href="https://sivadass.in" target="_blank">Read My Blog</a>
1214
</p>
1315
<p>&copy; 2017 <strong>Veggy</strong> - Organic Green Store</p>

src/components/Product.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ class Product extends Component{
77
this.state = {
88
selectedProduct: {},
99
quickViewProdcut: {},
10-
buttonLabel: "ADD TO CART"
10+
buttonLabel: "ADD TO CART",
1111
}
12-
}
12+
}
13+
resetQuantity(){
1314

15+
}
1416
addToCart(image, name, price, id, quantity){
1517
this.setState({
1618
selectedProduct: {
@@ -27,7 +29,10 @@ class Product extends Component{
2729
buttonLabel: "✔ ADDED"
2830
}, function(){
2931
setTimeout(() => {
30-
this.setState({ buttonLabel: "ADD TO CART" });
32+
this.setState({
33+
buttonLabel: "ADD TO CART",
34+
selectedProduct: {}
35+
});
3136
}, 5000);
3237
});
3338
}
@@ -56,7 +61,7 @@ class Product extends Component{
5661
</div>
5762
<h4 className="product-name">{this.props.name}</h4>
5863
<p className="product-price">{this.props.price}</p>
59-
<Counter productQuantity={quantity} updateQuantity={this.props.updateQuantity}/>
64+
<Counter productQuantity={quantity} updateQuantity={this.props.updateQuantity} resetQuantity={this.resetQuantity}/>
6065
<div className="product-action">
6166
<button type="button" onClick={this.addToCart.bind(this, image, name, price, id, quantity)}>{this.state.buttonLabel}</button>
6267
</div>

src/index.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class App extends Component{
7373
let productID = selectedProducts.id;
7474
let productQty = selectedProducts.quantity;
7575
if(this.checkProduct(productID)){
76+
console.log('hi');
7677
let index = cartItem.findIndex((x => x.id == productID));
7778
cartItem[index].quantity = Number(cartItem[index].quantity) + Number(productQty);
7879
this.setState({
@@ -86,8 +87,13 @@ class App extends Component{
8687
cartBounce: true,
8788
});
8889
setTimeout(function(){
89-
this.setState({cartBounce:false});
90-
}.bind(this),1000);
90+
this.setState({
91+
cartBounce:false,
92+
quantity: 1
93+
});
94+
console.log(this.state.quantity);
95+
console.log(this.state.cart);
96+
}.bind(this),1000);
9197
this.sumTotalItems(this.state.cart);
9298
this.sumTotalAmount(this.state.cart);
9399
}
@@ -126,19 +132,13 @@ class App extends Component{
126132
totalAmount: total
127133
})
128134
}
129-
//Update Quantity
130-
updateQuantity(qty){
131-
console.log("hola!")
132-
this.setState({
133-
moq: qty
134-
})
135-
}
135+
136136
//Reset Quantity
137137
updateQuantity(qty){
138-
console.log("hola!")
139-
this.setState({
140-
quantity: qty
141-
})
138+
console.log("quantity added...")
139+
this.setState({
140+
quantity: qty
141+
})
142142
}
143143
// Open Modal
144144
openModal(product){

0 commit comments

Comments
 (0)