Skip to content

Commit

Permalink
Update AddToCart.component.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
w3bdesign committed Oct 23, 2024
1 parent 368ac7a commit 570271d
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/components/Product/AddToCart.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const AddToCart = ({
variationId,
fullWidth = false,
}: IProductRootObject) => {
const { setCart, cart } = useContext(CartContext);
const { setCart, isLoading: isCartLoading } = useContext(CartContext);
const [requestError, setRequestError] = useState<boolean>(false);

const productId = product?.databaseId ? product?.databaseId : variationId;
Expand Down Expand Up @@ -141,10 +141,6 @@ const AddToCart = ({
});

const handleAddToCart = () => {
if (!cart) {
console.log('Cart is not yet initialized. Please wait.');
return;
}
addToCart();
// Refetch cart after 2 seconds
setTimeout(() => {
Expand All @@ -156,10 +152,10 @@ const AddToCart = ({
<>
<Button
handleButtonClick={() => handleAddToCart()}
buttonDisabled={addToCartLoading || requestError || !cart}
buttonDisabled={addToCartLoading || requestError || isCartLoading}
fullWidth={fullWidth}
>
{!cart ? 'Loading...' : 'KJØP'}
{isCartLoading ? 'Loading...' : 'KJØP'}
</Button>
</>
);
Expand Down

0 comments on commit 570271d

Please sign in to comment.