@shopgate/engage
Version:
Shopgate's ENGAGE library.
3 lines • 3 kB
JavaScript
function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true});}else{obj[key]=value;}return obj;}import React,{useContext,Fragment}from'react';import PropTypes from'prop-types';import{css}from'glamor';import classNames from'classnames';import CartTotalLine from'@shopgate/pwa-ui-shared/CartTotalLine';import{i18n}from'@shopgate/engage/core';import{CrossIcon}from'@shopgate/engage/components';import{responsiveMediaQuery}from'@shopgate/engage/styles';import PaymentBarPromotionCouponMessages from"./PaymentBarPromotionCouponMessages";import{CartContext}from"../../cart.context";import PaymentBarPromotionalText from"./PaymentBarPromotionalText";import{spacer}from"./PaymentBarContent.style";import connect from"./PaymentBarPromotionCoupons.connector";var styles={icon:css(_defineProperty({backgroundColor:'#898989',color:'#fff',borderRadius:32,padding:4,cursor:'pointer',fontSize:'0.75rem',display:'inline-flex'},responsiveMediaQuery('<=xs',{appAlways:true}),{padding:3})).toString(),withMessages:css({paddingBottom:'0px !important'}).toString()};/**
* @returns {JSX}
*/var PaymentBarPromotionCoupons=function PaymentBarPromotionCoupons(_ref){var coupons=_ref.coupons,className=_ref.className,deleteCoupon=_ref.deleteCoupon,showSeparator=_ref.showSeparator;var _useContext=useContext(CartContext),isLoading=_useContext.isLoading,currency=_useContext.currency;return coupons.map(function(coupon){var code=coupon.code,promotion=coupon.promotion,messages=coupon.messages;var _ref2=promotion||{},_ref2$discount=_ref2.discount,discount=_ref2$discount===void 0?{}:_ref2$discount,promotionalText=_ref2.promotionalText;var amount=discount.absoluteAmount;var hasError=false;if(Array.isArray(messages)&&messages.length){hasError=!!messages.find(function(_ref3){var type=_ref3.type;return type==='error';});}return React.createElement(Fragment,{key:"promotion-coupon-".concat(code,"-").concat(amount)},React.createElement(CartTotalLine,{isDisabled:isLoading,className:classNames(className,_defineProperty({},styles.withMessages,!!messages.length))},React.createElement(CartTotalLine.Label,{label:i18n.text('cart.coupon_label',{label:code}),showSeparator:showSeparator,suffix:!hasError?React.createElement(PaymentBarPromotionalText,{text:promotionalText}):null}),amount&&React.createElement(CartTotalLine.Amount,{amount:amount,currency:currency}),React.createElement(CartTotalLine.Spacer,{className:spacer},React.createElement("div",{className:styles.icon,onClick:function onClick(){deleteCoupon(code);},onKeyDown:function onKeyDown(){deleteCoupon(code);},role:"button",tabIndex:0},React.createElement(CrossIcon,null)))),React.createElement(PaymentBarPromotionCouponMessages,{messages:messages}),hasError&&React.createElement(PaymentBarPromotionalText,{text:promotionalText,renderIcon:false}));});};PaymentBarPromotionCoupons.defaultProps={className:null,showSeparator:true};export default connect(PaymentBarPromotionCoupons);