UNPKG

@shopgate/engage

Version:
9 lines 2.5 kB
import React from'react';import{css}from'glamor';import{connect}from'react-redux';import PlaceholderLabel from'@shopgate/pwa-ui-shared/PlaceholderLabel';import PropTypes from'prop-types';import{getPreferredLocation,makeGetLocationInventory}from"../../selectors";import{I18n,SurroundPortals}from"../../../components";import{StockInfo}from"../StockInfo";import{PRODUCT_LOCATION_STOCK_INFO_LIST}from"../../constants/Portals";import{showInventoryInLists}from"../../helpers/showInventoryInLists";/** * Creates a mapper for redux. * @returns {Function} * */var makeMapStateToProps=function makeMapStateToProps(){var getInventory=makeGetLocationInventory(function(_,props){var _getPreferredLocation;return(_getPreferredLocation=getPreferredLocation(_,props))===null||_getPreferredLocation===void 0?void 0:_getPreferredLocation.code;},function(_,props){var _props$product;return props.productId||((_props$product=props.product)===null||_props$product===void 0?void 0:_props$product.id);});return function(state,props){return{inventory:getInventory(state,props),preferredLocation:getPreferredLocation(state,props),showStockInfo:showInventoryInLists(state)};};};var styles={wrapper:css({flexDirection:'row',alignItems:'flex-end',fontSize:'0.65rem'}),text:css({margin:'0 !important'}).toString(),location:css({marginLeft:'0 !important'})};/** * Renders visible stock information based on the given location. * @param {Object} props The component props. * @return {JSX} */var StockInfoLists=function StockInfoLists(_ref){var preferredLocation=_ref.preferredLocation,product=_ref.product,inventory=_ref.inventory,showStockInfo=_ref.showStockInfo;if(!showStockInfo||!preferredLocation){return null;}var portalProps={inventory:inventory,location:preferredLocation,product:product};/* eslint-disable jsx-a11y/aria-role */return React.createElement(SurroundPortals,{portalName:PRODUCT_LOCATION_STOCK_INFO_LIST,portalProps:portalProps},React.createElement("div",{className:styles.wrapper,role:"text"},React.createElement(PlaceholderLabel,{ready:!!inventory},React.createElement(StockInfo,{product:product,location:preferredLocation}),' ',React.createElement(I18n.Text,{string:"locations.stock_info.pick_up_at",params:{storeName:''},className:styles.text}),' ',React.createElement("span",{className:styles.location},preferredLocation.name))));/* eslint-enable jsx-a11y/aria-role */};StockInfoLists.defaultProps={inventory:null,preferredLocation:null};export default connect(makeMapStateToProps)(StockInfoLists);