'use client'; import { MinusIcon, PlusIcon } from '@heroicons/react/24/outline'; import clsx from 'clsx'; import { CartItem } from 'lib/woocomerce/models/cart'; import { useCart } from './cart-context'; function SubmitButton({ type }: { type: 'plus' | 'minus' }) { return ( ); } export function EditItemQuantityButton({ item, type }: { item: CartItem; type: 'plus' | 'minus' }) { const { setNewCart } = useCart(); const payload = { key: item.key, quantity: type === 'plus' ? item.quantity + 1 : item.quantity - 1 }; return (
{ try { const cart = await ( await fetch('/api/cart', { method: 'PUT', body: JSON.stringify(payload) }) ).json(); setNewCart(cart); } catch (error) { console.error(error); } }} > ); }