package react.store; import react.ReactComponent; import react.ReactMacro.jsx; import Common; typedef CartProps = { var order:OrderSimple; var addToCart:ProductInfo -> Int -> Void; var removeFromCart:ProductInfo -> ?Int -> Void; var submitOrder:OrderSimple -> Void; }; class Cart extends react.ReactComponentOfProps { function addToCart(product:ProductInfo, quantity:Int):Void { props.addToCart(product, quantity); } function removeFromCart(product:ProductInfo, quantity:Int):Void { props.removeFromCart(product, quantity); } function removeAllFromCart(product:ProductInfo):Void { props.removeFromCart(product); } function submitOrder():Void { props.submitOrder(props.order); } override public function render(){ return jsx('

Ma Commande

${renderProducts()} ${renderFooter()}
'); } function renderProducts() { var productsToOrder = props.order.products.map(function(product:ProductWithQuantity) { var quantity = product.quantity; var product = product.product; return jsx('
${product.name}
$quantity
+
-
x
'); }); return jsx('
${productsToOrder}
'); } function renderFooter() { var buttonClasses = ["order-button"]; var submit = submitOrder; if (props.order.products.length == 0) { buttonClasses.push("order-button--disabled"); submit = null; } return jsx('
Total
${props.order.total} €
Commander
'); } }