UNPKG

@shopgate/engage

Version:
4 lines 1.5 kB
import React,{useMemo,useContext}from'react';import{Availability}from'@shopgate/engage/components';import{i18n,LoadingContext,useRoute}from'@shopgate/engage/core';import{AVAILABILITY_STATE_ALERT}from'@shopgate/engage/product';import{DIRECT_SHIP,ROPIS,BOPIS}from"../../constants";import{useFulfillmentSelectorState}from"./FulfillmentSelector.hooks";import{container}from"./FulfillmentSelectorImpossibleError.style";/** * Renders the "not possible" error for each item. * @returns {JSX} */export function FulfillmentSelectorImpossibleError(){var _useFulfillmentSelect=useFulfillmentSelectorState(),selection=_useFulfillmentSelect.selection,selectedLocation=_useFulfillmentSelect.selectedLocation;var _useRoute=useRoute(),pathname=_useRoute.pathname;var _useContext=useContext(LoadingContext),isLoading=_useContext.isLoading;var isDirectShip=useMemo(function(){return selection===DIRECT_SHIP;},[selection]);var isInStorePickup=useMemo(function(){return[ROPIS,BOPIS].includes(selection);},[selection]);if(!isDirectShip&&!isInStorePickup||isLoading(pathname)){return null;}var label=i18n.text('locations.fulfillment.error.reserve');if(isDirectShip){label=i18n.text('locations.fulfillment.error.direct_ship');}if(!isDirectShip&&!(selectedLocation===null||selectedLocation===void 0?void 0:selectedLocation.code)){label=i18n.text('locations.fulfillment.error.not_ready');}return React.createElement(Availability,{className:container,showWhenAvailable:true,text:label,state:AVAILABILITY_STATE_ALERT});}