"use client"; import Button from "@/components/atoms/buttons/Button"; import PaymentSummaryCard from "@/components/molecules/cards/PaymentSummaryCard"; import { useCart } from "@/lib/cart-context"; import { useManager } from "@/lib/manager-context"; import { MenuItemEntity } from "@/lib/types"; export const formatPrice = (value?: number) => (value ?? 0).toLocaleString("vi-VN", { style: "currency", currency: "VND" }); export default function PaymentPage() { const { items, totalPrice, eateryId, increaseQty, decreaseQty, removeFromCart, setQuantity, } = useCart(); const { products } = useManager(); const findProduct = (id: string): MenuItemEntity => products.find((i) => i.id == id) ?? ({ name: "Unknown product", description: "", price: 0, } as MenuItemEntity); return (

Payment

{items?.length === 0 ? (
Your cart is empty.
) : (
{items?.map( ({ productId: id, priceAtTimeOfAdding: price, quantity, }) => { const { name, description } = findProduct(id); return ( ); }, )}
Product name Price Description Quantity Delete
{name} {formatPrice(price)}

{description}

setQuantity(id, Number(e.target.value)) } className="h-8 w-16 rounded-lg border border-(--color-border) bg-transparent text-center" />
)}
); }