UNPKG

@shopgate/engage

Version:
62 lines (58 loc) 1.61 kB
/* eslint-disable react/prop-types */ import React from 'react'; import TimeBoundary from "../../components/TimeBoundary"; import { useWidgetSettings } from "../../core"; /** * @param {Function|React.Component} PriceComponent price component with product price shape * @returns {Function} */ import { jsx as _jsx } from "react/jsx-runtime"; const withMapPricing = PriceComponent => props => { const settings = useWidgetSettings('@shopgate/engage/product/MapPrice'); if (!settings.show) { return /*#__PURE__*/_jsx(PriceComponent, { ...props }); } // price is null OR no map pricing if (!props.price || !props.price.mapPricing) { return /*#__PURE__*/_jsx(PriceComponent, { ...props }); } // Same logic as in selector const mapPrice = [].concat(props.price.mapPricing)[0]; if (!mapPrice) { return /*#__PURE__*/_jsx(PriceComponent, { ...props }); } // Show original when map is equal or less if (props.price.unitPrice >= mapPrice.price) { return /*#__PURE__*/_jsx(PriceComponent, { ...props }); } return /*#__PURE__*/_jsx(TimeBoundary, { start: new Date(mapPrice.startDate), end: new Date(mapPrice.endDate), children: ({ between }) => { if (!between) { return /*#__PURE__*/_jsx(PriceComponent, { ...props }); } return /*#__PURE__*/_jsx(PriceComponent, { ...props, price: { ...props.price, unitPriceStriked: mapPrice.price } }); } }); }; export default withMapPricing; /* eslint-enable react/prop-types */