diff --git a/frontend-prep/src/components/ProductCard.tsx b/frontend-prep/src/components/ProductCard.tsx index 707c5efc..12fdbdd8 100644 --- a/frontend-prep/src/components/ProductCard.tsx +++ b/frontend-prep/src/components/ProductCard.tsx @@ -57,7 +57,8 @@ function ProductCard({ null, ); const [showSuccess, setShowSuccess] = useState(false); - const [showVideo, setShowVideo] = useState(false); // ✨ État pour afficher/masquer la vidéo + const [showVideo, setShowVideo] = useState(false); + const [stockWarning, setStockWarning] = useState<{ wanted: number; available: number } | null>(null); const isOutOfStock = stock === 0; const isComingSoon = coming_soon === true; @@ -100,16 +101,13 @@ function ProductCard({ const selectedGrams = Number(e.target.value); setSelectedQuantity(selectedGrams); + if (stock > 0 && selectedGrams > stock) { + setStockWarning({ wanted: selectedGrams, available: stock }); + return; + } + const priceOption = prices?.find((p) => p.quantity === selectedGrams); if (priceOption) { - console.log("💾 [ProductCard] Ajout au panier:", { - id, - name, - category: normalizedCategory, - quantity: selectedGrams, - price: priceOption.price, - }); - addToCart({ product_id: id, name_product: name, @@ -237,6 +235,49 @@ function ProductCard({ )} + {/* Modal stock insuffisant */} + {stockWarning && + createPortal( +
setStockWarning(null)}> +
e.stopPropagation()} + > + +
⚠️
+

+ Stock insuffisant +

+

+ Vous avez sélectionné {stockWarning.wanted}g mais il ne reste que{" "} + {stockWarning.available}g disponible pour {name}. +

+ +
+
, + document.body, + )} + {/* ✨ Modal vidéo — rendu via Portal pour éviter le clipping du transform:scale sur .product-card */} {showVideo && videoUrl && diff --git a/frontend-prep/src/pages/User/Accueil.tsx b/frontend-prep/src/pages/User/Accueil.tsx index d3ac7734..bfba9179 100644 --- a/frontend-prep/src/pages/User/Accueil.tsx +++ b/frontend-prep/src/pages/User/Accueil.tsx @@ -27,7 +27,13 @@ function UserAccueil() { const [error, setError] = useState(null); useEffect(() => { - getCategories().then(setCategories); + getCategories().then((cats) => { + const sorted = [...cats].sort((a, b) => { + if (a.is_coming_soon === b.is_coming_soon) return 0; + return a.is_coming_soon ? 1 : -1; + }); + setCategories(sorted); + }); }, []); useEffect(() => {