"use client" import Image from "next/image" import { updateLineItem, deleteLineItem } from "@lib/data/cart" import { notifyCartUpdated } from "@lib/util/cart-events" import { convertToLocale } from "@lib/util/money" import { getProductCardImage } from "@lib/util/sale-scenario" import { HttpTypes } from "@medusajs/types" import ErrorMessage from "@modules/checkout/components/error-message" import LineItemOptions from "@modules/common/components/line-item-options" import LocalizedClientLink from "@modules/common/components/localized-client-link" import { useState } from "react" import { Loader2, Minus, Plus } from "lucide-react" import { cn } from "@/lib/utils" type ItemProps = { item: HttpTypes.StoreCartLineItem /** full: cart page with quantity controls; preview: checkout summary */ type?: "full" | "preview" currencyCode: string } const MAX_QUANTITY = 99 /** Cart line as a list row (cart page and checkout summary) */ const Item = ({ item, type = "full", currencyCode }: ItemProps) => { const [updating, setUpdating] = useState(false) const [removing, setRemoving] = useState(false) const [error, setError] = useState(null) const isFull = type === "full" const money = (amount?: number | null) => convertToLocale({ amount: amount ?? 0, currency_code: currencyCode }) const changeQuantity = async (quantity: number) => { if (quantity < 1 || quantity > MAX_QUANTITY) return setError(null) setUpdating(true) await updateLineItem({ lineId: item.id, quantity }) .then(() => notifyCartUpdated()) .catch((err) => setError(err.message)) .finally(() => setUpdating(false)) } const remove = async () => { setRemoving(true) await deleteLineItem(item.id) .then(() => notifyCartUpdated()) .catch((err) => { setError(err.message) setRemoving(false) }) } return (
  • {item.product_title
    {item.product_title}

    {money(item.total)}

    {(isFull ? item.quantity > 1 : true) && (

    {item.quantity} × {money(item.unit_price)}

    )}
    {isFull && (
    {updating ? : item.quantity}
    )}
  • ) } export default Item