-
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.
adding cart items remove, clear and add from checkout and cart component
- Loading branch information
Showing
6 changed files
with
78 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { clearItem, addItem, removeItem } from '../../redux/cart/cart.actions'; | ||
|
||
import './checkout-item.styles.scss'; | ||
|
||
const CheckoutItem = ({cartItem:{name, imageUrl, price, quantity}}) => ( | ||
const CheckoutItem = ({cartItem, removeItemFromCart, addItem, removeItem}) => { | ||
const {name, imageUrl, price, quantity} = cartItem; | ||
return ( | ||
<div className='checkout-item'> | ||
<div className='image-container'> | ||
<img src={imageUrl} alt='item' /> | ||
</div> | ||
<span className='name'>{name}</span> | ||
<span className='quantity'>{quantity}</span> | ||
|
||
<span className='quantity'> | ||
<div className='arrow' onClick={() => removeItem(cartItem)} >❮</div> | ||
<span className='value'>{quantity}</span> | ||
<div className='arrow' onClick={()=> addItem(cartItem)}>❯</div> | ||
</span> | ||
<span className='price'>{price}</span> | ||
<div className='remove-button'>✕</div> | ||
<div className='remove-button' onClick={() => removeItemFromCart(cartItem)}>✕</div> | ||
</div> | ||
) | ||
) | ||
} | ||
|
||
export default CheckoutItem; | ||
const mapDispatchToProps = dispatch => ({ | ||
removeItemFromCart:item => dispatch(clearItem(item)), | ||
addItem: item => dispatch(addItem(item)), | ||
removeItem: item => dispatch(removeItem(item)) | ||
}) | ||
|
||
|
||
export default connect(null, mapDispatchToProps)(CheckoutItem); |
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,6 +1,8 @@ | ||
const CartActionTypes = { | ||
TOGGLE_CART_HIDDEN: 'TOGGLE_CART_HIDDEN', | ||
ADD_ITEM: 'ADD_ITEM' | ||
ADD_ITEM: 'ADD_ITEM', | ||
REMOVE_ITEM: 'REMOVE_ITEM', | ||
CLEAR_ITEM_FROM_CART: 'CLEAR_ITEM_FROM_CART' | ||
} | ||
|
||
export default CartActionTypes; |
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