UNPKG

@shopgate/engage

Version:
4 lines 1.52 kB
import*as React from'react';import{SurroundPortals}from'@shopgate/engage/components';import{CART_PAYMENT_BAR_TOTALS_DISCOUNTS}from'@shopgate/pwa-common-commerce/cart';import CartTotalLine from'@shopgate/pwa-ui-shared/CartTotalLine';import{CartContext}from"../../cart.context";import{spacer}from"./PaymentBarContent.style";import connect from"./PaymentBarDiscounts.connector";/** * The Discounts component. * @returns {JSX} */function PaymentBarDiscounts(_ref){var discounts=_ref.discounts,showSeparator=_ref.showSeparator,className=_ref.className;var _React$useContext=React.useContext(CartContext),currency=_React$useContext.currency,isLoading=_React$useContext.isLoading,hasPromotionCoupons=_React$useContext.hasPromotionCoupons;if(!discounts){return null;}return React.createElement(SurroundPortals,{portalName:CART_PAYMENT_BAR_TOTALS_DISCOUNTS},discounts.map(function(_ref2){var label=_ref2.label,amount=_ref2.amount;return React.createElement(CartTotalLine,{key:"discount-".concat(label,"-").concat(amount),type:"discount",isDisabled:isLoading,className:className},React.createElement(CartTotalLine.Label,{label:label?'cart.discount_with_label':'cart.discount',labelParams:{label:label},showSeparator:showSeparator}),React.createElement(CartTotalLine.Amount,{amount:-amount,currency:currency}),hasPromotionCoupons&&React.createElement(CartTotalLine.Spacer,{className:spacer}));}));}PaymentBarDiscounts.defaultProps={discounts:null,className:null,showSeparator:true};export default connect(PaymentBarDiscounts);