mirror of
https://github.com/vercel/commerce.git
synced 2025-06-28 01:11:24 +00:00
33 lines
891 B
TypeScript
33 lines
891 B
TypeScript
'use client';
|
|
|
|
import { XMarkIcon } from '@heroicons/react/24/outline';
|
|
import { CartItem } from 'lib/woocomerce/models/cart';
|
|
import { useCart } from './cart-context';
|
|
|
|
export function DeleteItemButton({ item }: { item: CartItem }) {
|
|
const { setNewCart } = useCart();
|
|
|
|
return (
|
|
<form
|
|
action={async () => {
|
|
try {
|
|
const cart = await (
|
|
await fetch('/api/cart', { method: 'DELETE', body: JSON.stringify({ key: item.key }) })
|
|
).json();
|
|
setNewCart(cart);
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
}}
|
|
>
|
|
<button
|
|
type="submit"
|
|
aria-label="Remove cart item"
|
|
className="flex h-[24px] w-[24px] items-center justify-center rounded-full bg-neutral-500"
|
|
>
|
|
<XMarkIcon className="mx-[1px] h-4 w-4 text-white dark:text-black" />
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|