UNPKG

@shopgate/engage

Version:
4 lines 2.22 kB
import React,{Fragment}from'react';import PropTypes from'prop-types';import classNames from'classnames';import{css}from'glamor';import{isBeta,useWidgetSettings,useWidgetStyles}from'@shopgate/engage/core';import{I18n,TimeBoundary,SurroundPortals}from'@shopgate/engage/components';import{PRODUCT_EFFECTIVITY_DATES}from'@shopgate/pwa-common-commerce/product/constants/Portals';import{showExpiringLabel,showScheduledLabel}from"./helpers";import{hint,notAvailable}from"./style";import connect from"./connector";/** * The Product Effectivity Dates component. * @return {JSX} */var EffectivityDates=function EffectivityDates(_ref){var dates=_ref.dates,children=_ref.children,productNotAvailable=_ref.productNotAvailable,productId=_ref.productId;if(!isBeta()||!dates){return children;}var settings=useWidgetSettings('@shopgate/engage/product/EffectivityDates');var styles=useWidgetStyles('@shopgate/engage/product/EffectivityDates');var startDate=dates.startDate?new Date(dates.startDate):null;var endDate=dates.endDate?new Date(dates.endDate):null;var hintAddClass=styles&&styles.hint?css(styles.hint).toString():null;return React.createElement(SurroundPortals,{portalName:PRODUCT_EFFECTIVITY_DATES,portalProps:{dates:dates,productNotAvailable:productNotAvailable,productId:productId}},React.createElement(TimeBoundary,{start:startDate,end:endDate},function(_ref2){var before=_ref2.before,between=_ref2.between,after=_ref2.after;if(before){return showScheduledLabel(startDate,settings)?React.createElement(I18n.Text,{string:"product.available.at",params:{startDate:startDate},className:classNames(hint,hintAddClass)}):children;}if(between){return React.createElement(Fragment,null,children,showExpiringLabel(endDate,settings)&&React.createElement(I18n.Text,{string:"product.available.until",params:{endDate:endDate},className:classNames(hint,hintAddClass)}));}if(after){productNotAvailable();return showExpiringLabel(endDate,settings)?React.createElement(I18n.Text,{string:"product.available.not",className:classNames(hint,hintAddClass,notAvailable)}):children;}return children;}));};EffectivityDates.defaultProps={children:null,dates:{startDate:null,endDate:null},productId:null};export default connect(EffectivityDates);