@shopgate/engage
Version:
Shopgate's ENGAGE library.
5 lines • 1.45 kB
JavaScript
import React,{useCallback,useContext,useMemo}from'react';import{RippleButton}from'@shopgate/engage/components';import{StoreContext}from"./Store.context";import{i18n}from"../../../core";import{StoreFinderContext}from"../../locations.context";import{selectLocationButton,selectLocationButtonWrapper}from"../StoreList/Store.style";/**
* The StoreFinderSelectLocationButton component.
* Renders if route query.selectLocation param is passed
* @returns {JSX.Element}
*/export var StoreFinderSelectLocationButton=function StoreFinderSelectLocationButton(){var store=useContext(StoreContext);var _useContext=useContext(StoreFinderContext),selectLocation=_useContext.selectLocation,isLoading=_useContext.isLoading,selectedLocation=_useContext.selectedLocation;var handleClick=useCallback(function(e){e.stopPropagation();selectLocation(store);},[selectLocation,store]);var isSelected=useMemo(function(){return(selectedLocation===null||selectedLocation===void 0?void 0:selectedLocation.code)===(store===null||store===void 0?void 0:store.code);},[selectedLocation,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)||isSelected},i18n.text((store===null||store===void 0?void 0:store.isComingSoon)?'location.comingSoon':'locations.select_location')));};