fix: use _id for MongoDB products in frontend
- SearchView now uses p._id || p.id for product navigation - ProductResults uses product._id || product.id for React key - Fixes 'undefined' error when clicking parapharmacy products
This commit is contained in:
@@ -39,7 +39,7 @@ function ProductResults({ products, onSelect }) {
|
|||||||
<div className="product-results">
|
<div className="product-results">
|
||||||
{products.map((product) => (
|
{products.map((product) => (
|
||||||
<ProductCard
|
<ProductCard
|
||||||
key={product.id}
|
key={product._id || product.id}
|
||||||
product={product}
|
product={product}
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -322,10 +322,11 @@ function SearchView({ currentUser, onLoginRequest, initialQuery = '', onNavigate
|
|||||||
<ProductResults
|
<ProductResults
|
||||||
products={products}
|
products={products}
|
||||||
onSelect={(p) => {
|
onSelect={(p) => {
|
||||||
|
const productId = p._id || p.id;
|
||||||
if (onNavigateToProduct) {
|
if (onNavigateToProduct) {
|
||||||
onNavigateToProduct(p.source, p.id);
|
onNavigateToProduct(p.source, productId);
|
||||||
} else {
|
} else {
|
||||||
window.location.href = `/product/${p.source}/${p.id}`;
|
window.location.href = `/product/${p.source}/${productId}`;
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user