"use client"; import { useState } from "react"; import { useAuth } from "@/context/AuthContext"; import { useCart } from "@/context/CartContext"; export default function ProductProfile({ prodId, prodName, categoryName, prodDesc, prodPrice, imageUrl }) { const { user } = useAuth(); const { addItem, selectedStoreId } = useCart(); const [quantity, setQuantity] = useState(1); const [adding, setAdding] = useState(false); const [feedback, setFeedback] = useState(null); // { type: "success"|"error", message } function changeQty(delta) { setQuantity((q) => Math.max(1, q + delta)); } async function handleAddToCart() { setAdding(true); setFeedback(null); try { await addItem(prodId, quantity); setFeedback({ type: "success", message: `${quantity} × ${prodName} added to cart!` }); setQuantity(1); } catch (err) { setFeedback({ type: "error", message: err.message ?? "Failed to add to cart." }); } finally { setAdding(false); } } return (
Log in to purchase this item.
) : !selectedStoreId ? (Select a store from the navigation bar to add items to your cart.
) : ( <>{feedback.message}
)} > )}