MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / ProductPage

Function ProductPage

apps/testbed/src/pages/Product.tsx:11–61  ·  view source on GitHub ↗
({ products, onAddToCart }: Props)

Source from the content-addressed store, hash-verified

9};
10
11export function ProductPage({ products, onAddToCart }: Props) {
12 const { id } = useParams<{ id: string }>();
13 const product = products.find((p) => p.id === id);
14
15 useEffect(() => {
16 if (product) {
17 op.track('product_viewed', {
18 product_id: product.id,
19 product_name: product.name,
20 price: product.price,
21 category: product.category,
22 });
23 }
24 }, [product]);
25
26 if (!product) {
27 return (
28 <div>
29 <div className="page-title">Product not found</div>
30 <Link to="/"><button type="button">← Back to shop</button></Link>
31 </div>
32 );
33 }
34
35 return (
36 <div>
37 <div style={{ marginBottom: 16 }}>
38 <Link to="/">← Back to shop</Link>
39 </div>
40 <div className="product-detail">
41 <div className="product-detail-img">[img]</div>
42 <div className="product-detail-info">
43 <div className="product-card-category">{product.category}</div>
44 <div className="product-detail-name">{product.name}</div>
45 <div className="product-detail-price">${product.price}</div>
46 <p className="product-detail-desc">
47 A high quality {product.name.toLowerCase()} for testing purposes.
48 Lorem ipsum dolor sit amet consectetur adipiscing elit.
49 </p>
50 <button
51 type="button"
52 className="primary"
53 onClick={() => onAddToCart(product)}
54 >
55 Add to cart
56 </button>
57 </div>
58 </div>
59 </div>
60 );
61}

Callers

nothing calls this directly

Calls 1

trackMethod · 0.45

Tested by

no test coverage detected