-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Facundo Martinez
authored and
Facundo Martinez
committed
Feb 16, 2021
1 parent
99f7b20
commit 0241f8d
Showing
13 changed files
with
314 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from "react"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { | ||
removeCartItem, | ||
addProduct, | ||
reduceCartItem, | ||
} from "./../../../redux/Cart/cart.actions"; | ||
|
||
const Item = (product) => { | ||
const dispatch = useDispatch(); | ||
const { | ||
productName, | ||
productThumbnail, | ||
productPrice, | ||
quantity, | ||
documentID, | ||
} = product; | ||
const handleRemoveCartItem = (documentID) => { | ||
dispatch(removeCartItem({ documentID })); | ||
}; | ||
const handleAddProduct = (product) => { | ||
dispatch(addProduct(product)); | ||
}; | ||
const handleReduceItem = (product) => { | ||
dispatch(reduceCartItem(product)); | ||
}; | ||
return ( | ||
<table className="cartItem" border="0" cellSpacing="0" cellPadding="0"> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<img src={productThumbnail} alt={productName} /> | ||
</td> | ||
<td>{productName}</td> | ||
<td> | ||
<span | ||
onClick={() => handleReduceItem(product)} | ||
className="cartBtn" | ||
>{`< `}</span> | ||
<span>{quantity}</span> | ||
<span | ||
onClick={() => handleAddProduct(product)} | ||
className="cartBtn" | ||
>{` >`}</span> | ||
</td> | ||
<td>${productPrice}</td> | ||
<td align="center"> | ||
<span | ||
className="cartBtn" | ||
onClick={() => handleRemoveCartItem(documentID)} | ||
> | ||
X | ||
</span> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
); | ||
}; | ||
|
||
export default Item; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React from "react"; | ||
import { useSelector } from "react-redux"; | ||
import { | ||
selectCartItems, | ||
selectCartTotal, | ||
} from "./../../redux/Cart/cart.selectors"; | ||
import { createStructuredSelector } from "reselect"; | ||
import { useHistory } from "react-router-dom"; | ||
import "./styles.scss"; | ||
import Button from "../forms/Button"; | ||
import Item from "./Item"; | ||
|
||
const Checkout = () => { | ||
const history = useHistory(); | ||
const { cartItems } = useSelector( | ||
createStructuredSelector({ cartItems: selectCartItems }) | ||
); | ||
const { total } = useSelector( | ||
createStructuredSelector({ total: selectCartTotal }) | ||
); | ||
const errorMsg = "You have no items in your cart."; | ||
return ( | ||
<div className="checkout"> | ||
<h1>Checkout</h1> | ||
<div className="cart"> | ||
{cartItems.length > 0 ? ( | ||
<table border="0" cellPadding="0" cellSpacing="0"> | ||
<tbody> | ||
<tr> | ||
<table | ||
className="checkoutHeader" | ||
border="0" | ||
cellPadding="10" | ||
cellSpacing="0" | ||
> | ||
<tbody> | ||
<tr> | ||
<th>Product</th> | ||
<th>Description</th> | ||
<th>Quantity</th> | ||
<th>Price</th> | ||
<th>Remove</th> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</tr> | ||
|
||
<tr> | ||
<table border="0" cellPadding="0" cellSpacing="0"> | ||
<tbody> | ||
{cartItems.map((item, index) => { | ||
return ( | ||
<tr key={index}> | ||
<td> | ||
<Item {...item} /> | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
</tr> | ||
|
||
<tr> | ||
<table | ||
align="right" | ||
border="0" | ||
cellSpacing="0" | ||
cellPadding="10" | ||
> | ||
<tr align="right"> | ||
<td> | ||
<h3>Total: ${total}</h3> | ||
</td> | ||
</tr> | ||
<tr> | ||
<table border="0" cellPadding="10" cellSpacing="0"> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<Button onClick={() => history.goBack()}> | ||
Continue Shopping | ||
</Button> | ||
</td> | ||
<td> | ||
<Button>Checkout</Button> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</tr> | ||
</table> | ||
</tr> | ||
</tbody> | ||
</table> | ||
) : ( | ||
<p>{errorMsg}</p> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Checkout; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
.checkout { | ||
margin: 2rem auto; | ||
|
||
h1 { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
h1, | ||
p { | ||
text-align: center; | ||
} | ||
|
||
.checkoutHeader { | ||
border-bottom: 1px solid black; | ||
} | ||
|
||
.cart { | ||
max-width: 100rem; | ||
margin: 0 auto; | ||
|
||
table { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.checkoutHeader, | ||
.cart { | ||
width: 100%; | ||
text-align: left; | ||
|
||
th, | ||
td { | ||
width: 22%; | ||
} | ||
} | ||
|
||
.cartItem { | ||
td img { | ||
display: block; | ||
width: 100%; | ||
} | ||
} | ||
|
||
.cartBtns { | ||
display: block; | ||
width: 100%; | ||
} | ||
|
||
.cartBtn { | ||
cursor: pointer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
import Checkout from "../../components/Checkout"; | ||
|
||
const Cart = () => { | ||
return ( | ||
<div> | ||
<Checkout /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Cart; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const cartTypes = { | ||
ADD_TO_CART: "ADD_TO_CART", | ||
REMOVE_CART_ITEM: "REMOVE_CART_ITEM", | ||
REDUCE_CART_ITEM: "REDUCE_CART_ITEM", | ||
}; | ||
|
||
export default cartTypes; |
Oops, something went wrong.