import CloseIcon from 'components/icons/close'; import LoadingDots from 'components/loading-dots'; import { useRouter } from 'next/navigation'; import { startTransition, useState } from 'react'; import type { CartItem } from 'lib/shopify/types'; export default function DeleteItemButton({ item }: { item: CartItem }) { const router = useRouter(); const [removing, setRemoving] = useState(false); async function handleRemove() { setRemoving(true); const response = await fetch(`/api/cart`, { method: 'DELETE', body: JSON.stringify({ lineId: item.id }) }); const data = await response.json(); if (data.error) { alert(data.error); return; } setRemoving(false); startTransition(() => { router.refresh(); }); } return ( ); }