@shopgate/engage
Version:
Shopgate's ENGAGE library.
66 lines (63 loc) • 2 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}
*/
import { jsx as _jsx } from "react/jsx-runtime";
const mapStateToProps = state => ({
settings: getFavoritesListState(state).chooser,
lists: getFavoritesLists(state)
});
/**
* @param {Object} dispatch Dispatch.
* @returns {Object}
*/
const mapDispatchToProps = dispatch => ({
close: () => dispatch(closeFavoritesListChooser()),
toggle: (...params) => dispatch(toggleFavorite.apply(void 0, params))
});
/**
* @param {Object} props Props.
* @returns {JSX.Element}
*/
const ListChooser = ({
settings,
lists,
close,
toggle
}) => {
const isVisible = !!settings;
const productId = settings?.productId;
const withRelatives = settings?.withRelatives;
return /*#__PURE__*/_jsx(SheetDrawer, {
isOpen: isVisible,
title: i18n.text('favorites.list_chooser.title'),
onDidClose: close,
children: /*#__PURE__*/_jsx(SheetList, {
children: lists.map(list => /*#__PURE__*/_jsx(SheetList.Item, {
title: list.name,
onClick: () => {
close();
toggle(productId, list.id, withRelatives);
},
rightComponent: /*#__PURE__*/_jsx(ListChooserItem, {
listId: list.id,
productId: productId
})
}, list.id))
})
});
};
ListChooser.defaultProps = {
settings: null,
lists: []
};
export default connect(mapStateToProps, mapDispatchToProps)(ListChooser);