UNPKG

@shopgate/engage

Version:
77 lines (75 loc) 2.38 kB
import React from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { i18n } from '@shopgate/engage/core/helpers'; import { ProductListTypeProvider, ProductProvider } from '@shopgate/engage/product/providers'; import { RippleButton } from '@shopgate/engage/components'; import { getUseGetFavoriteIdsPipeline } from '@shopgate/engage/favorites'; import ListItemWrapper from "./ListItemWrapper"; import styles from "./styles"; /** * @param {Object} state State * @param {Object} props Props * @returns {Object} */ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; const mapStateToProps = (state, props) => ({ useGetFavoriteIdsPipeline: getUseGetFavoriteIdsPipeline(state, props) }); /** * @param {Object} props The component props * @returns {JSX.Element} */ const ListContent = ({ listId, items, removeItem, addToCart, useGetFavoriteIdsPipeline, showLoadMoreButton, onLoadMore }) => /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/_jsx("div", { className: styles.divider }), items.length === 0 ? /*#__PURE__*/_jsx("span", { children: i18n.text('favorites.empty') }) : null, /*#__PURE__*/_jsxs(ProductListTypeProvider, { type: "favoritesList", children: [useGetFavoriteIdsPipeline ? items.map(({ productId }, index) => /*#__PURE__*/_jsx(ProductProvider, { productId: productId, children: ({ product }) => product ? /*#__PURE__*/_jsx(ListItemWrapper, { listId: listId, product: product, items: items, addToCart: addToCart, removeItem: removeItem, index: index }, product.id) : null }, productId)) : null, !useGetFavoriteIdsPipeline && items.filter(({ product }) => product).map(({ product, notes, quantity }, index) => /*#__PURE__*/_jsx(ListItemWrapper, { listId: listId, product: product, notes: notes, quantity: quantity, items: items, addToCart: addToCart, removeItem: removeItem, index: index }, product.id))] }), showLoadMoreButton && /*#__PURE__*/_jsx(RippleButton, { type: "primary", className: styles.loadMoreButton, onClick: onLoadMore, children: i18n.text('favorites.load_more_button') })] }); export default connect(mapStateToProps)(ListContent);