import { Card } from "react-bootstrap"; import { useState, useEffect } from "react"; function renderStatus(statusCode) { if (statusCode !== undefined) { switch (statusCode) { case 0: return ( Disponible ); case 1: return ( En commande ); case 2: return ( Indisponible ); case 3: return ( Liquidation ); case 4: return ( Promotion ); case 5: return ( Discontinué ); default: return ( <>> ); } } } function renderPrice(price, newPrice, status) { if (price !== undefined) { if (status !== 3 && status !== 4) { return ( {price.toFixed(2).toString().replace(".", ",")} $ CA ); } else { return ( {price.toFixed(2).toString().replace(".", ",")} $ CA {newPrice.toFixed(2).toString().replace(".", ",")} $ CA ); } } } const Item = ({ productId, name, price, newPrice, status }) => { const [imageSrc, setImageSrc] = useState(null); useEffect(() => { fetch(`https://localhost:7292/api/Image?id=${productId}&thumbnail=true`) .then(response => response.blob()) .then(blob => { const imageUrl = URL.createObjectURL(blob); setImageSrc(imageUrl); }) }, []); if (name !== undefined) { return ( {name} {renderStatus(status)} {renderPrice(price, newPrice, status)} ); } else { return (<>>); } } export default Item;