diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx index 04089fa9b..8929d044c 100644 --- a/components/cart/CartItem/CartItem.tsx +++ b/components/cart/CartItem/CartItem.tsx @@ -1,11 +1,12 @@ -import s from './CartItem.module.css' +import { ChangeEvent, useEffect, useState } from 'react' +import cn from 'classnames' import Image from 'next/image' import Link from 'next/link' -import { ChangeEvent, useEffect, useState } from 'react' import { Trash, Plus, Minus } from '@components/icons' import usePrice from '@lib/bigcommerce/use-price' import useUpdateItem from '@lib/bigcommerce/cart/use-update-item' import useRemoveItem from '@lib/bigcommerce/cart/use-remove-item' +import s from './CartItem.module.css' const CartItem = ({ item, @@ -22,8 +23,9 @@ const CartItem = ({ const updateItem = useUpdateItem(item) const removeItem = useRemoveItem() const [quantity, setQuantity] = useState(item.quantity) + const [removing, setRemoving] = useState(false) const updateQuantity = async (val: number) => { - const data = await updateItem({ quantity: val }) + await updateItem({ quantity: val }) } const handleQuantity = (e: ChangeEvent) => { const val = Number(e.target.value) @@ -47,6 +49,17 @@ const CartItem = ({ updateQuantity(val) } } + const handleRemove = async () => { + setRemoving(true) + + try { + // If this action succeeds then there's no need to do `setRemoving(true)` + // because the component will be removed from the view + await removeItem({ id: item.id }) + } catch (error) { + setRemoving(false) + } + } useEffect(() => { // Reset the quantity state if the item quantity changes @@ -56,7 +69,11 @@ const CartItem = ({ }, [item.quantity]) return ( -
  • +
  • {price} -