1
0
mirror of https://github.com/vercel/commerce.git synced 2025-07-28 04:31:22 +00:00
Files
.cursor
.vscode
app
components
cart
actions.ts
add-to-cart.tsx
cart-context.tsx
delete-item-button.tsx
edit-item-quantity-button.tsx
modal.tsx
open-cart.tsx
grid
icons
layout
product
carousel.tsx
label.tsx
loading-dots.tsx
logo-square.tsx
opengraph-image.tsx
price.tsx
prose.tsx
welcome-toast.tsx
fonts
lib
.env.example
.gitignore
README.md
license.md
next.config.ts
package.json
pnpm-lock.yaml
postcss.config.mjs
tsconfig.json
commerce/components/cart/delete-item-button.tsx
Lee Robinson 7f8f9ff1a3 use cache
2025-02-09 11:38:22 -06:00

39 lines
1.0 KiB
TypeScript

'use client';
import { XMarkIcon } from '@heroicons/react/24/outline';
import { removeItem } from 'components/cart/actions';
import type { CartItem } from 'lib/shopify/types';
import { useActionState } from 'react';
export function DeleteItemButton({
item,
optimisticUpdate
}: {
item: CartItem;
optimisticUpdate: any;
}) {
const [message, formAction] = useActionState(removeItem, null);
const merchandiseId = item.merchandise.id;
const removeItemAction = formAction.bind(null, merchandiseId);
return (
<form
action={async () => {
optimisticUpdate(merchandiseId, 'delete');
removeItemAction();
}}
>
<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>
<p aria-live="polite" className="sr-only" role="status">
{message}
</p>
</form>
);
}