Skip to content

Commit 0e0331a

Browse files
committed
Add delete option feature
1 parent 0aa3782 commit 0e0331a

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/components/cart/cart-item.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const CartItem = ( {
4545
event.stopPropagation();
4646
let newQty;
4747

48-
// If the previous cart request is still updatingProduct, then return.
49-
if ( updatingProduct || ( 'decrement' === type && 1 === productCount ) ) {
48+
// If the previous cart request is still updatingProduct or removingProduct, then return.
49+
if ( updatingProduct || removingProduct || ( 'decrement' === type && 1 === productCount ) ) {
5050
return;
5151
}
5252

@@ -85,7 +85,7 @@ const CartItem = ( {
8585
<div className="cart-product-title-wrap relative">
8686
<h3 className="cart-product-title text-brand-orange">{ item?.data?.name }</h3>
8787
{item?.data?.description ? <p>{item?.data?.description}</p> : ''}
88-
<button className="cart-remove-item absolute right-0 top-0 px-4 py-2 flex items-center text-22px leading-22px bg-transparent border border-brand-bright-grey" onClick={ ( event ) => handleRemoveProductClick( event, item?.cartKey, products ) }>&times;</button>
88+
<button className="cart-remove-item absolute right-0 top-0 px-4 py-2 flex items-center text-22px leading-22px bg-transparent border border-brand-bright-grey" onClick={ ( event ) => handleRemoveProductClick( event, item?.key ) }>&times;</button>
8989
</div>
9090

9191
<footer className="cart-product-footer flex justify-between p-4 border-t border-brand-bright-grey">

src/components/cart/cart-items-container.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const CartItemsContainer = () => {
4343
<div className="woo-next-cart-total-container lg:col-span-1 p-5 pt-0">
4444
<h2>Cart Total</h2>
4545
<div className="flex grid grid-cols-3 bg-gray-100 mb-4">
46-
<p className="col-span-2 p-2 mb-0">Total</p>
46+
<p className="col-span-2 p-2 mb-0">Total({totalQty})</p>
4747
<p className="col-span-1 p-2 mb-0">{cartItems?.[0]?.currency ?? ''}{ totalPrice }</p>
4848
</div>
4949

src/utils/cart/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export const viewCart = ( setCart, setProcessing = () => {} ) => {
5757
} )
5858
.catch( err => {
5959
console.log( 'err', err );
60+
setProcessing(false);
6061
} );
6162
};
6263

@@ -77,6 +78,7 @@ export const updateCart = ( cartKey, qty = 1, setCart, setUpdatingProduct ) => {
7778
} )
7879
.catch( err => {
7980
console.log( 'err', err );
81+
setUpdatingProduct(false);
8082
} );
8183
};
8284

@@ -104,6 +106,7 @@ export const deleteCartItem = ( cartKey, setCart, setRemovingProduct ) => {
104106
} )
105107
.catch( err => {
106108
console.log( 'err', err );
109+
setRemovingProduct(false);
107110
} );
108111
};
109112

@@ -121,9 +124,7 @@ export const clearCart = ( setCart, setClearCartProcessing ) => {
121124

122125
axios.delete( CART_ENDPOINT, addOrViewCartConfig )
123126
.then( ( res ) => {
124-
const formattedCartData = getFormattedCartData( res?.data ?? [] )
125-
setCart( formattedCartData );
126-
setClearCartProcessing(false);
127+
viewCart( setCart, setClearCartProcessing )
127128
} )
128129
.catch( err => {
129130
console.log( 'err', err );

0 commit comments

Comments
 (0)