UNPKG

@shopgate/engage

Version:
5 lines 1.53 kB
import React,{useMemo,useCallback}from'react';import PropTypes from'prop-types';import{i18n}from'@shopgate/engage/core';import{CardList}from'@shopgate/engage/components';import Substitution,{SubstitutionWrapper}from"../Substitution";import connect from"./CartItemsSubscription.connector";/** * Renders the cart reservation card label. * @param {Object} props The component props. * @returns {JSX} */var CartItemsSubstitution=function CartItemsSubstitution(_ref){var cartItems=_ref.cartItems,updateProductsInCart=_ref.updateProductsInCart,className=_ref.className,wrapCard=_ref.wrapCard;var allAllowed=useMemo(function(){return cartItems.every(function(item){return item.substitutionAllowed;});},[cartItems]);var handleChange=useCallback(function(){return updateProductsInCart(cartItems.map(function(item){return{cartItemId:item.id,substitutionAllowed:!allAllowed};}));},[allAllowed,cartItems,updateProductsInCart]);if(wrapCard){return React.createElement(SubstitutionWrapper,null,React.createElement(CardList.Item,{className:className},React.createElement(Substitution,{id:"substitution-all",label:i18n.text('cart.allow_substitution_all'),checked:allAllowed,onChange:handleChange})));}return React.createElement(SubstitutionWrapper,null,React.createElement(Substitution,{className:className,id:"substitution-all",label:i18n.text('cart.allow_substitution_all'),checked:allAllowed,onChange:handleChange}));};CartItemsSubstitution.defaultProps={className:undefined,wrapCard:false};export default connect(CartItemsSubstitution);