UNPKG

@shopgate/engage

Version:
4 lines 2.08 kB
import React,{useContext,useCallback}from'react';import{RippleButton}from'@shopgate/engage/components';import PropTypes from'prop-types';import{isProductAvailable}from"../../helpers";import{StoreContext}from"./Store.context";import{i18n,useWidgetSettings}from"../../../core";import{FulfillmentContext}from"../../locations.context";import{selectLocationButton,selectLocationButtonWrapper}from"./Store.style";import connect from"./StoreListSearch.connector";/** * The StoreSelectLocationButton component. * @returns {JSX.Element} */var StoreSelectLocationButton=function StoreSelectLocationButton(_ref){var setPostalCode=_ref.setPostalCode;var store=useContext(StoreContext);var _ref2=useWidgetSettings('@shopgate/engage/locations')||{},_ref2$setUserSearchZi=_ref2.setUserSearchZipLocationFromSelection,setUserSearchZipLocationFromSelection=_ref2$setUserSearchZi===void 0?true:_ref2$setUserSearchZi;var _useContext=useContext(FulfillmentContext),selectLocation=_useContext.selectLocation,noInventory=_useContext.noInventory,isLoading=_useContext.isLoading,product=_useContext.product;var isAvailable=isProductAvailable(store,store===null||store===void 0?void 0:store.inventory);var handleClick=useCallback(function(e){e.stopPropagation();if(noInventory||isAvailable){if(setUserSearchZipLocationFromSelection){setPostalCode(store.address.postalCode,product===null||product===void 0?void 0:product.id);}selectLocation(store);}},[isAvailable,noInventory,product,selectLocation,setPostalCode,setUserSearchZipLocationFromSelection,store]);return React.createElement("div",{className:selectLocationButtonWrapper},React.createElement(RippleButton,{onClick:handleClick,className:selectLocationButton.toString(),disabled:isLoading||(store===null||store===void 0?void 0:store.isComingSoon)||!noInventory&&!isAvailable},i18n.text((store===null||store===void 0?void 0:store.isComingSoon)?'location.comingSoon':'locations.select_location')));};var connectedStoreSelectLocationButton=connect(StoreSelectLocationButton);export{connectedStoreSelectLocationButton as StoreSelectLocationButton};