UNPKG

@shopgate/engage

Version:
52 lines (51 loc) 1.7 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} */ import { jsx as _jsx } from "react/jsx-runtime"; const CartItemsSubstitution = ({ cartItems, updateProductsInCart, className, wrapCard }) => { const allAllowed = useMemo(() => cartItems.every(item => item.substitutionAllowed), [cartItems]); const handleChange = useCallback(() => updateProductsInCart(cartItems.map(item => ({ cartItemId: item.id, substitutionAllowed: !allAllowed }))), [allAllowed, cartItems, updateProductsInCart]); if (wrapCard) { return /*#__PURE__*/_jsx(SubstitutionWrapper, { children: /*#__PURE__*/_jsx(CardList.Item, { className: className, children: /*#__PURE__*/_jsx(Substitution, { id: "substitution-all", label: i18n.text('cart.allow_substitution_all'), checked: allAllowed, onChange: handleChange }) }) }); } return /*#__PURE__*/_jsx(SubstitutionWrapper, { children: /*#__PURE__*/_jsx(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);