diff --git a/frontend/src/pages/Products/Products.js b/frontend/src/pages/Products/Products.js index 8c36283..13dbbe9 100644 --- a/frontend/src/pages/Products/Products.js +++ b/frontend/src/pages/Products/Products.js @@ -136,7 +136,35 @@ const Products = () => { } }; - const ProductCard = ({ product, isUserProduct = false }) => ( + const handleAddToMyProducts = async (sharedProduct) => { + try { + // Create a custom product based on the shared product + const productData = { + productId: sharedProduct.id, // Link to the shared product + customName: sharedProduct.name, // Use the shared product's name as default + customBrand: sharedProduct.brand, + categoryId: null, // Will use the shared product's category + customProductType: sharedProduct.productType, + customActiveIngredients: sharedProduct.activeIngredients, + customDescription: sharedProduct.description, + // Set default rate if available + customRateAmount: sharedProduct.rates?.[0]?.rateAmount || '', + customRateUnit: sharedProduct.rates?.[0]?.rateUnit || (sharedProduct.productType === 'granular' ? 'lbs/1000 sq ft' : 'oz/1000 sq ft'), + notes: `Added from shared product: ${sharedProduct.name}` + }; + + const response = await productsAPI.createUserProduct(productData); + toast.success(`"${sharedProduct.name}" added to your products!`); + + // Refresh the data to show the new custom product + fetchData(); + } catch (error) { + console.error('Failed to add product to my products:', error); + toast.error('Failed to add product to your collection'); + } + }; + + const ProductCard = ({ product, isUserProduct = false, onAddToMyProducts }) => (