@shopgate/engage
Version:
Shopgate's ENGAGE library.
5 lines • 2.14 kB
JavaScript
import React,{useMemo}from'react';import PropTypes from'prop-types';import{I18n,SurroundPortals}from'@shopgate/engage/components';import{i18n,hasNewServices,isBeta}from'@shopgate/engage/core/helpers';import{useWidgetSettings}from'@shopgate/engage/core/hooks';import{PRODUCT_ORDER_QUANTITY}from'@shopgate/engage/product';import{formatFloat}from'@shopgate/engage/components/QuantityInput/helper';import withProductStock from"../../hocs/withProductStock";import withProduct from"../../hocs/withProduct";import{hint}from"./style";/**
* The Product Order Quantity Hint component.
* @return {JSX}
*/var OrderQuantityHint=function OrderQuantityHint(_ref){var stock=_ref.stock,product=_ref.product,className=_ref.className;var _ref2=product||{},hasCatchWeight=_ref2.hasCatchWeight,productUnit=_ref2.unit;var settings=useWidgetSettings('@shopgate/engage/product/OrderQuantityHint');var showContent=useMemo(function(){if(hasNewServices()){// During development of PWA 7 the component was shown by default
return true;}return isBeta()&&settings.show===true;},[settings.show]);var unit=useMemo(function(){if(hasCatchWeight){var key="formats.unitOfMeasurement.".concat(productUnit);var text=i18n.text(key);return text!==key?text:productUnit||'';}return'';},[hasCatchWeight,productUnit]);var maxDecimals=useMemo(function(){return hasCatchWeight&&productUnit?2:0;},[hasCatchWeight,productUnit]);return React.createElement("div",{className:className},React.createElement(SurroundPortals,{portalName:PRODUCT_ORDER_QUANTITY,portalProps:{stock:stock}},showContent&&stock&&!!stock.minOrderQuantity&&React.createElement("div",{className:hint},React.createElement(I18n.Text,{string:"product.minOrderQuantity",params:{quantity:formatFloat(stock.minOrderQuantity,maxDecimals),unit:unit}})),showContent&&stock&&!!stock.maxOrderQuantity&&React.createElement("div",{className:hint},React.createElement(I18n.Text,{string:"product.maxOrderQuantity",params:{quantity:formatFloat(stock.maxOrderQuantity,maxDecimals),unit:unit}}))));};OrderQuantityHint.defaultProps={className:null,stock:null,product:null};export default withProduct(withProductStock(OrderQuantityHint));