@shopgate/engage
Version:
Shopgate's ENGAGE library.
10 lines • 1.94 kB
JavaScript
import React from'react';import PropTypes from'prop-types';import{connect}from'react-redux';import{getFavoritesListState,getFavoritesLists}from'@shopgate/pwa-common-commerce/favorites/selectors';import{i18n}from'@shopgate/engage/core';import{SheetList,SheetDrawer}from'@shopgate/engage/components';import{closeFavoritesListChooser}from'@shopgate/pwa-common-commerce/favorites/action-creators';import{toggleFavorite}from'@shopgate/pwa-common-commerce/favorites/actions/toggleFavorites';import ListChooserItem from"./ListChooserItem";/**
* @param {Object} state State.
* @returns {Object}
*/var mapStateToProps=function mapStateToProps(state){return{settings:getFavoritesListState(state).chooser,lists:getFavoritesLists(state)};};/**
* @param {Object} dispatch Dispatch.
* @returns {Object}
*/var mapDispatchToProps=function mapDispatchToProps(dispatch){return{close:function close(){return dispatch(closeFavoritesListChooser());},toggle:function toggle(){return dispatch(toggleFavorite.apply(void 0,arguments));}};};/**
* @param {Object} props Props.
* @returns {JSX.Element}
*/var ListChooser=function ListChooser(_ref){var settings=_ref.settings,lists=_ref.lists,close=_ref.close,toggle=_ref.toggle;var isVisible=!!settings;var productId=settings===null||settings===void 0?void 0:settings.productId;var withRelatives=settings===null||settings===void 0?void 0:settings.withRelatives;return React.createElement(SheetDrawer,{isOpen:isVisible,title:i18n.text('favorites.list_chooser.title'),onDidClose:close},React.createElement(SheetList,null,lists.map(function(list){return React.createElement(SheetList.Item,{key:list.id,title:list.name,onClick:function onClick(){close();toggle(productId,list.id,withRelatives);},rightComponent:React.createElement(ListChooserItem,{listId:list.id,productId:productId})});})));};ListChooser.defaultProps={settings:null,lists:[]};export default connect(mapStateToProps,mapDispatchToProps)(ListChooser);