@commercelayer/react-components 3.14.2-beta.1 → 3.15.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/lib/components/AddToCartButton.js +1 -1
  2. package/lib/components/Address.js +1 -1
  3. package/lib/components/AddressCountrySelector.js +1 -1
  4. package/lib/components/AddressField.js +1 -1
  5. package/lib/components/AddressInput.js +1 -1
  6. package/lib/components/AddressStateSelector.js +1 -1
  7. package/lib/components/AddressesContainer.js +1 -1
  8. package/lib/components/AdjustmentAmount.js +1 -1
  9. package/lib/components/AdyenPayment.d.ts +34 -4
  10. package/lib/components/AdyenPayment.js +1 -1
  11. package/lib/components/AvailabilityContainer.js +1 -1
  12. package/lib/components/AvailabilityTemplate.js +1 -1
  13. package/lib/components/BillingAddressContainer.js +1 -1
  14. package/lib/components/BillingAddressForm.js +1 -1
  15. package/lib/components/BraintreePayment.js +1 -1
  16. package/lib/components/CartLink.js +1 -1
  17. package/lib/components/CheckoutComPayment.js +1 -1
  18. package/lib/components/CheckoutLink.js +1 -1
  19. package/lib/components/CommerceLayer.js +1 -1
  20. package/lib/components/CustomerContainer.js +1 -1
  21. package/lib/components/CustomerInput.js +1 -1
  22. package/lib/components/DeliveryLeadTime.js +1 -1
  23. package/lib/components/DiscountAmount.js +1 -1
  24. package/lib/components/Errors.js +1 -1
  25. package/lib/components/ExternalFunction.js +1 -1
  26. package/lib/components/GiftCard.js +1 -1
  27. package/lib/components/GiftCardAmount.js +1 -1
  28. package/lib/components/GiftCardContainer.js +1 -1
  29. package/lib/components/GiftCardCurrencySelector.js +1 -1
  30. package/lib/components/GiftCardInput.js +1 -1
  31. package/lib/components/GiftCardOrCouponCode.js +1 -1
  32. package/lib/components/GiftCardOrCouponForm.js +1 -1
  33. package/lib/components/GiftCardOrCouponInput.js +1 -1
  34. package/lib/components/GiftCardOrCouponRemoveButton.js +1 -1
  35. package/lib/components/GiftCardOrCouponSubmit.js +1 -1
  36. package/lib/components/ItemContainer.js +1 -1
  37. package/lib/components/KlarnaPayment.js +1 -1
  38. package/lib/components/LineItem.js +1 -1
  39. package/lib/components/LineItemAmount.js +1 -1
  40. package/lib/components/LineItemCode.js +1 -1
  41. package/lib/components/LineItemImage.js +1 -1
  42. package/lib/components/LineItemName.js +1 -1
  43. package/lib/components/LineItemOption.js +1 -1
  44. package/lib/components/LineItemOptions.js +1 -1
  45. package/lib/components/LineItemQuantity.js +1 -1
  46. package/lib/components/LineItemRemoveLink.js +1 -1
  47. package/lib/components/LineItemsContainer.js +1 -1
  48. package/lib/components/LineItemsCount.js +1 -1
  49. package/lib/components/LineItemsEmpty.js +1 -1
  50. package/lib/components/MetadataInput.js +1 -1
  51. package/lib/components/OrderContainer.js +1 -1
  52. package/lib/components/OrderNumber.js +1 -1
  53. package/lib/components/OrderStorage.js +1 -1
  54. package/lib/components/PaymentGateway.js +1 -1
  55. package/lib/components/PaymentMethod.d.ts +6 -1
  56. package/lib/components/PaymentMethod.js +1 -1
  57. package/lib/components/PaymentMethodAmount.js +1 -1
  58. package/lib/components/PaymentMethodName.js +1 -1
  59. package/lib/components/PaymentMethodPrice.js +1 -1
  60. package/lib/components/PaymentMethodRadioButton.js +1 -1
  61. package/lib/components/PaymentMethodsContainer.js +1 -1
  62. package/lib/components/PaymentSource.js +1 -1
  63. package/lib/components/PaymentSourceBrandIcon.js +1 -1
  64. package/lib/components/PaymentSourceBrandName.js +1 -1
  65. package/lib/components/PaymentSourceDetail.js +1 -1
  66. package/lib/components/PaymentSourceEditButton.js +1 -1
  67. package/lib/components/PaypalPayment.js +1 -1
  68. package/lib/components/PlaceOrderButton.js +1 -1
  69. package/lib/components/PlaceOrderContainer.js +1 -1
  70. package/lib/components/Price.js +1 -1
  71. package/lib/components/PricesContainer.js +1 -1
  72. package/lib/components/PrivacyAndTermsCheckbox.js +1 -1
  73. package/lib/components/QuantitySelector.js +1 -1
  74. package/lib/components/SaveAddressesButton.js +1 -1
  75. package/lib/components/SaveCustomerButton.js +1 -1
  76. package/lib/components/Shipment.js +1 -1
  77. package/lib/components/ShipmentField.js +1 -1
  78. package/lib/components/ShipmentsContainer.js +1 -1
  79. package/lib/components/ShippingAddressContainer.js +1 -1
  80. package/lib/components/ShippingAddressForm.js +1 -1
  81. package/lib/components/ShippingAmount.js +1 -1
  82. package/lib/components/ShippingMethod.js +1 -1
  83. package/lib/components/ShippingMethodName.js +1 -1
  84. package/lib/components/ShippingMethodPrice.js +1 -1
  85. package/lib/components/ShippingMethodRadioButton.js +1 -1
  86. package/lib/components/SkuField.js +1 -1
  87. package/lib/components/SkuListsContainer.js +1 -1
  88. package/lib/components/SkuOption.js +1 -1
  89. package/lib/components/SkuOptionInput.js +1 -1
  90. package/lib/components/SkuOptionsContainer.js +1 -1
  91. package/lib/components/Skus.js +1 -1
  92. package/lib/components/SkusContainer.js +1 -1
  93. package/lib/components/StockTransfer.js +1 -1
  94. package/lib/components/StockTransferField.js +1 -1
  95. package/lib/components/StripePayment.js +1 -1
  96. package/lib/components/SubTotalAmount.js +1 -1
  97. package/lib/components/SubmitButton.js +1 -1
  98. package/lib/components/TaxesAmount.js +1 -1
  99. package/lib/components/TotalAmount.js +1 -1
  100. package/lib/components/VariantSelector.js +1 -1
  101. package/lib/components/VariantsContainer.js +1 -1
  102. package/lib/components/WireTransferPayment.d.ts +3 -1
  103. package/lib/components/WireTransferPayment.js +1 -1
  104. package/lib/components/gateways/AdyenGateway.js +1 -1
  105. package/lib/components/gateways/BraintreeGateway.js +1 -1
  106. package/lib/components/gateways/CheckoutComGateway.js +1 -1
  107. package/lib/components/gateways/KlarnaGateway.js +1 -1
  108. package/lib/components/gateways/PaypalGateway.js +1 -1
  109. package/lib/components/gateways/StripeGateway.js +1 -1
  110. package/lib/components/gateways/WireTransferGateway.js +1 -1
  111. package/lib/components/utils/AddressCardsTemplate.js +1 -1
  112. package/lib/components/utils/BaseField.js +1 -1
  113. package/lib/components/utils/BaseInput.js +1 -1
  114. package/lib/components/utils/BaseOrderPrice.js +1 -1
  115. package/lib/components/utils/BaseSelect.js +1 -1
  116. package/lib/components/utils/GenericFieldComponent.js +1 -1
  117. package/lib/components/utils/Parent.js +1 -1
  118. package/lib/components/utils/PaymentCardsTemplate.js +1 -1
  119. package/lib/components/utils/PriceTemplate.js +1 -1
  120. package/lib/components/utils/VariantTemplate.js +1 -1
  121. package/lib/components/utils/getAllErrors.js +1 -1
  122. package/lib/config/components.js +1 -1
  123. package/lib/context/BillingAddressFormContext.d.ts +2 -2
  124. package/lib/context/CouponAndGiftCardFormContext.d.ts +2 -2
  125. package/lib/context/PlaceOrderContext.d.ts +2 -1
  126. package/lib/reducers/AddressReducer.js +1 -1
  127. package/lib/reducers/AvailabilityReducer.js +1 -1
  128. package/lib/reducers/BillingAddressReducer.js +1 -1
  129. package/lib/reducers/CustomerReducer.js +1 -1
  130. package/lib/reducers/GiftCardReducer.js +1 -1
  131. package/lib/reducers/LineItemReducer.js +1 -1
  132. package/lib/reducers/OrderReducer.d.ts +1 -1
  133. package/lib/reducers/OrderReducer.js +1 -1
  134. package/lib/reducers/PaymentMethodReducer.d.ts +1 -0
  135. package/lib/reducers/PaymentMethodReducer.js +1 -1
  136. package/lib/reducers/PlaceOrderReducer.d.ts +7 -4
  137. package/lib/reducers/PlaceOrderReducer.js +1 -1
  138. package/lib/reducers/PriceReducer.js +1 -1
  139. package/lib/reducers/ShippingAddressReducer.js +1 -1
  140. package/lib/reducers/SkuReducer.js +1 -1
  141. package/lib/reducers/VariantReducer.js +1 -1
  142. package/lib/typings/index.js +1 -1
  143. package/lib/utils/addressesManager.js +1 -1
  144. package/lib/utils/baseReducer.js +1 -1
  145. package/lib/utils/checkIncludeResource.js +1 -1
  146. package/lib/utils/childrenTypes.js +1 -1
  147. package/lib/utils/getCardDetails.js +1 -1
  148. package/lib/utils/getErrors.js +1 -1
  149. package/lib/utils/getLineItemsCount.js +1 -1
  150. package/lib/utils/getPrices.js +1 -1
  151. package/lib/utils/getSdk.js +1 -1
  152. package/lib/utils/getSkus.js +1 -1
  153. package/lib/utils/promisify.js +1 -1
  154. package/lib/utils/shipments.js +1 -1
  155. package/lib/utils/validateFormFields.js +1 -1
  156. package/package.json +43 -43
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import SkuListsContext from"../context/SkuListsContext";import ExternalFunctionContext from"../context/ExternalFunctionContext";import isFunction from"lodash/isFunction";import SkuChildrenContext from"../context/SkuChildrenContext";import getCartLink from"../utils/getCartLink";import CommerceLayerContext from"../context/CommerceLayerContext";export default function AddToCartButton(props){var _a,_b,_c;const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl}=props,p=__rest(props,["label","children","skuCode","bundleCode","disabled","skuListId","lineItem","buyNowMode","checkoutUrl","redirectToHostedCart","hostedCartUrl"]),{accessToken,endpoint}=useContext(CommerceLayerContext),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),[slug]=endpoint.split(".commercelayer"),sCode=!isEmpty(items)&&skuCode?(_a=items[skuCode])===null||_a===void 0?void 0:_a.code:(sku==null?void 0:sku.code)||skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=(_c=(_b=item[sCode])===null||_b===void 0?void 0:_b.inventory)===null||_c===void 0?void 0:_c.quantity,handleClick=async()=>{var _a2,_b2;const qty=quantity[sCode],opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity[skuListId]||1;if(has(skuLists,skuListId)){const lineItems2=skuLists&&skuLists[skuListId].map(skuCode2=>({skuCode:skuCode2,quantity:slQty,_update_quantity:1}));return callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems:lineItems2}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}}if(!url&&addToCart){const res=await addToCart({bundleCode,skuCode:sCode,skuId:(_a2=item[sCode])===null||_a2===void 0?void 0:_a2.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart){const orderId2=res.orderId;hostedCartUrl?location.href=`https://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getCartLink({orderId:orderId2,slug,accessToken}))}return res}else if(url)return callExternalFunction({url,data:{bundleCode,skuCode:sCode,skuId:(_b2=item[sCode])===null||_b2===void 0?void 0:_b2.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},autoDisabled=!isEmpty(skuLists)||skuListId?!1:disabled||!prices[sCode]||!sCode||availabilityQuantity===0,parentProps=Object.assign({handleClick,disabled:disabled||autoDisabled,label},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({},p,{disabled:autoDisabled,onClick:handleClick},{children:isFunction(label)?label():label}))}
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import SkuListsContext from"../context/SkuListsContext";import ExternalFunctionContext from"../context/ExternalFunctionContext";import isFunction from"lodash/isFunction";import SkuChildrenContext from"../context/SkuChildrenContext";import getCartLink from"../utils/getCartLink";import CommerceLayerContext from"../context/CommerceLayerContext";export default function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,...p}=props,{accessToken,endpoint}=useContext(CommerceLayerContext),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),[slug]=endpoint.split(".commercelayer"),sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:sku?.code||skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=item[sCode]?.inventory?.quantity,handleClick=async()=>{const qty=quantity[sCode],opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity[skuListId]||1;if(has(skuLists,skuListId)){const lineItems2=skuLists&&skuLists[skuListId].map(skuCode2=>({skuCode:skuCode2,quantity:slQty,_update_quantity:1}));return callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems:lineItems2}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}}if(!url&&addToCart){const res=await addToCart({bundleCode,skuCode:sCode,skuId:item[sCode]?.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart){const orderId2=res.orderId;hostedCartUrl?location.href=`https://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getCartLink({orderId:orderId2,slug,accessToken}))}return res}else if(url)return callExternalFunction({url,data:{bundleCode,skuCode:sCode,skuId:item[sCode]?.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},autoDisabled=!isEmpty(skuLists)||skuListId?!1:disabled||!prices[sCode]||!sCode||availabilityQuantity===0,parentProps={handleClick,disabled:disabled||autoDisabled,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,disabled:autoDisabled,onClick:handleClick,children:isFunction(label)?label():label})}
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import BillingAddressContext from"../context/BillingAddressContext";import ShippingAddressContext from"../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../context/AddressContext";import OrderContext from"../context/OrderContext";import AddressCardsTemplate from"./utils/AddressCardsTemplate";const propTypes=components.Address.propTypes,Address=props=>{const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1}=props,p=__rest(props,["children","className","selectedClassName","disabledClassName","onSelect","addresses","deselect"]),{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.map((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>{setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")})()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order==null?void 0:order.shipping_country_code_lock,components2=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,customerAddressId=(address==null?void 0:address.reference)||"",finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,Object.assign({value:addressProps},{children:_jsx("div",Object.assign({className:finalClassName,onClick:()=>handleSelect(k,address.id,customerAddressId,disabled,address),"data-disabled":disabled},p,{children}))}),k)}),parentProps=Object.assign({customerAddresses:items,selected,handleSelect,countryLock},props);return typeof children=="function"?_jsx(AddressCardsTemplate,Object.assign({},parentProps,{children})):_jsx(Fragment,{children:components2})};Address.propTypes=propTypes;export default Address;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import BillingAddressContext from"../context/BillingAddressContext";import ShippingAddressContext from"../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../context/AddressContext";import OrderContext from"../context/OrderContext";import AddressCardsTemplate from"./utils/AddressCardsTemplate";const propTypes=components.Address.propTypes,Address=props=>{const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1,...p}=props,{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.map((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>{setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")})()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order?.shipping_country_code_lock,components2=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,customerAddressId=address?.reference||"",finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,{value:addressProps,children:_jsx("div",{className:finalClassName,onClick:()=>handleSelect(k,address.id,customerAddressId,disabled,address),"data-disabled":disabled,...p,children})},k)}),parentProps={customerAddresses:items,selected,handleSelect,countryLock,...props};return typeof children=="function"?_jsx(AddressCardsTemplate,{...parentProps,children}):_jsx(Fragment,{children:components2})};Address.propTypes=propTypes;export default Address;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getCountries}from"../utils/countryStateCity";const propTypes=components.AddressCountrySelector.propTypes,defaultProps=components.AddressCountrySelector.defaultProps,displayName=components.AddressCountrySelector.displayName,AddressCountrySelector=props=>{const{required=!0,value,name,className}=props,p=__rest(props,["required","value","name","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseSelect,Object.assign({className:classNameComputed,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),required,options:getCountries(),name,value},p))};AddressCountrySelector.propTypes=propTypes,AddressCountrySelector.defaultProps=defaultProps,AddressCountrySelector.displayName=displayName;export default AddressCountrySelector;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getCountries}from"../utils/countryStateCity";const propTypes=components.AddressCountrySelector.propTypes,defaultProps=components.AddressCountrySelector.defaultProps,displayName=components.AddressCountrySelector.displayName,AddressCountrySelector=props=>{const{required=!0,value,name,className,...p}=props,billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>(value&&billingAddress?.setValue&&billingAddress.setValue(name,value),value&&shippingAddress?.setValue&&shippingAddress.setValue(name,value),!isEmpty(billingAddress.errors)&&billingAddress?.errors?.[name]?.error&&setHasError(!0),isEmpty(billingAddress?.errors?.[name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&shippingAddress?.errors?.[name]?.error&&setHasError(!0),isEmpty(shippingAddress?.errors?.[name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}),[value,billingAddress?.errors,shippingAddress?.errors]);const errorClassName=billingAddress?.errorClassName||shippingAddress?.errorClassName,classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseSelect,{className:classNameComputed,ref:billingAddress?.validation||shippingAddress?.validation,required,options:getCountries(),name,value,...p})};AddressCountrySelector.propTypes=propTypes,AddressCountrySelector.defaultProps=defaultProps,AddressCountrySelector.displayName=displayName;export default AddressCountrySelector;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import get from"lodash/get";const propTypes=components.AddressField.propTypes,displayName=components.AddressField.displayName,AddressField=props=>{const{name}=props,{address}=useContext(AddressChildrenContext),text=get(address,name),parentProps=Object.assign({address},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("p",Object.assign({},props,{children:text}))};AddressField.propTypes=propTypes,AddressField.displayName=displayName;export default AddressField;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import get from"lodash/get";const propTypes=components.AddressField.propTypes,displayName=components.AddressField.displayName,AddressField=props=>{const{name}=props,{address}=useContext(AddressChildrenContext),text=get(address,name),parentProps={address,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("p",{...props,children:text})};AddressField.propTypes=propTypes,AddressField.displayName=displayName;export default AddressField;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.AddressInput.propTypes,displayName=components.AddressInput.displayName,AddressInput=props=>{const{placeholder="",required,value,className}=props,p=__rest(props,["placeholder","required","value","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(p.name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(p.name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[p.name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),!isEmpty(billingAddress)&&isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[p.name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[p.name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),!isEmpty(shippingAddress)&&isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const mandatoryField=(billingAddress==null?void 0:billingAddress.isBusiness)?businessMandatoryField(p.name,billingAddress.isBusiness):businessMandatoryField(p.name,shippingAddress.isBusiness),reqField=required!==void 0?required:mandatoryField,errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return p.name==="billing_address_billing_info"&&!billingAddress.requiresBillingInfo?null:_jsx(BaseInput,Object.assign({ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required:reqField,placeholder,defaultValue:value},p))};AddressInput.propTypes=propTypes,AddressInput.displayName=displayName;export default AddressInput;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.AddressInput.propTypes,displayName=components.AddressInput.displayName,AddressInput=props=>{const{placeholder="",required,value,className,...p}=props,billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>(value&&billingAddress?.setValue&&billingAddress.setValue(p.name,value),value&&shippingAddress?.setValue&&shippingAddress.setValue(p.name,value),!isEmpty(billingAddress.errors)&&billingAddress?.errors?.[p.name]?.error&&setHasError(!0),!isEmpty(billingAddress)&&isEmpty(billingAddress?.errors?.[p.name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&shippingAddress?.errors?.[p.name]?.error&&setHasError(!0),!isEmpty(shippingAddress)&&isEmpty(shippingAddress?.errors?.[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}),[value,billingAddress?.errors,shippingAddress?.errors]);const mandatoryField=billingAddress?.isBusiness?businessMandatoryField(p.name,billingAddress.isBusiness):businessMandatoryField(p.name,shippingAddress.isBusiness),reqField=required!==void 0?required:mandatoryField,errorClassName=billingAddress?.errorClassName||shippingAddress?.errorClassName,classNameComputed=`${className} ${hasError?errorClassName:""}`;return p.name==="billing_address_billing_info"&&!billingAddress.requiresBillingInfo?null:_jsx(BaseInput,{ref:billingAddress?.validation||shippingAddress?.validation,className:classNameComputed,required:reqField,placeholder,defaultValue:value,...p})};AddressInput.propTypes=propTypes,AddressInput.displayName=displayName;export default AddressInput;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getStateOfCountry,isValidState}from"../utils/countryStateCity";import isEmptyStates from"../utils/isEmptyStates";import AddressesContext from"../context/AddressContext";import BaseInput from"./utils/BaseInput";const propTypes=components.AddressStateSelector.propTypes,defaultProps=components.AddressStateSelector.defaultProps,displayName=components.AddressStateSelector.displayName,AddressStateSelector=props=>{var _a;const{required=!0,value,name,className,inputClassName,selectClassName}=props,p=__rest(props,["required","value","name","className","inputClassName","selectClassName"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),{errors:addressErrors}=useContext(AddressesContext),[hasError,setHasError]=useState(!1),[countryCode,setCountryCode]=useState(""),[val,setVal]=useState(value||"");useEffect(()=>{var _a2,_b,_c,_d,_e,_f,_g,_h,_j;const billingCountryCode=((_b=(_a2=billingAddress==null?void 0:billingAddress.values)===null||_a2===void 0?void 0:_a2.billing_address_country_code)===null||_b===void 0?void 0:_b.value)||((_c=billingAddress==null?void 0:billingAddress.values)===null||_c===void 0?void 0:_c.country_code);!isEmpty(billingCountryCode)&&billingCountryCode!==countryCode&&setCountryCode(billingCountryCode);const shippingCountryCode=(_e=(_d=shippingAddress==null?void 0:shippingAddress.values)===null||_d===void 0?void 0:_d.shipping_address_country_code)===null||_e===void 0?void 0:_e.value;if(!isEmpty(shippingCountryCode)&&shippingCountryCode!==countryCode&&setCountryCode(shippingCountryCode),[!isEmpty(billingAddress),billingCountryCode,countryCode!==billingCountryCode].every(Boolean)&&!isValidState(val,billingCountryCode)&&!isEmptyStates(billingCountryCode)&&(billingAddress.resetField&&billingAddress.resetField(name),setVal("")),[!isEmpty(shippingAddress),shippingCountryCode,countryCode!==shippingCountryCode].every(Boolean)&&!isValidState(val,shippingCountryCode)&&!isEmptyStates(shippingCountryCode)&&(shippingAddress.resetField&&shippingAddress.resetField(name),setVal("")),!isEmpty(billingAddress)){const fieldError=(_g=(_f=billingAddress==null?void 0:billingAddress.errors)===null||_f===void 0?void 0:_f[name])===null||_g===void 0?void 0:_g.error;setHasError(!!fieldError)}if(!isEmpty(shippingAddress)){const fieldError=(_j=(_h=shippingAddress==null?void 0:shippingAddress.errors)===null||_h===void 0?void 0:_h[name])===null||_j===void 0?void 0:_j.error;setHasError(!!fieldError)}return()=>{setHasError(!1)}},[value,billingAddress,shippingAddress,addressErrors]);const errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=isEmptyStates(countryCode)?`${className} ${inputClassName} ${hasError?errorClassName:""}`:`${className} ${selectClassName} ${hasError?errorClassName:""}`;return isEmptyStates(countryCode)?_jsx(BaseInput,Object.assign({},p,{name,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required,placeholder:((_a=p.placeholder)===null||_a===void 0?void 0:_a.label)||"",defaultValue:val,type:"text"})):_jsx(BaseSelect,Object.assign({},p,{className:classNameComputed,ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),required,options:getStateOfCountry(countryCode),name,value:val}))};AddressStateSelector.propTypes=propTypes,AddressStateSelector.defaultProps=defaultProps,AddressStateSelector.displayName=displayName;export default AddressStateSelector;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseSelect from"./utils/BaseSelect";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{getStateOfCountry,isValidState}from"../utils/countryStateCity";import isEmptyStates from"../utils/isEmptyStates";import AddressesContext from"../context/AddressContext";import BaseInput from"./utils/BaseInput";const propTypes=components.AddressStateSelector.propTypes,defaultProps=components.AddressStateSelector.defaultProps,displayName=components.AddressStateSelector.displayName,AddressStateSelector=props=>{const{required=!0,value,name,className,inputClassName,selectClassName,...p}=props,billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),{errors:addressErrors}=useContext(AddressesContext),[hasError,setHasError]=useState(!1),[countryCode,setCountryCode]=useState(""),[val,setVal]=useState(value||"");useEffect(()=>{const billingCountryCode=billingAddress?.values?.billing_address_country_code?.value||billingAddress?.values?.country_code;!isEmpty(billingCountryCode)&&billingCountryCode!==countryCode&&setCountryCode(billingCountryCode);const shippingCountryCode=shippingAddress?.values?.shipping_address_country_code?.value;if(!isEmpty(shippingCountryCode)&&shippingCountryCode!==countryCode&&setCountryCode(shippingCountryCode),[!isEmpty(billingAddress),billingCountryCode,countryCode!==billingCountryCode].every(Boolean)&&!isValidState(val,billingCountryCode)&&!isEmptyStates(billingCountryCode)&&(billingAddress.resetField&&billingAddress.resetField(name),setVal("")),[!isEmpty(shippingAddress),shippingCountryCode,countryCode!==shippingCountryCode].every(Boolean)&&!isValidState(val,shippingCountryCode)&&!isEmptyStates(shippingCountryCode)&&(shippingAddress.resetField&&shippingAddress.resetField(name),setVal("")),!isEmpty(billingAddress)){const fieldError=billingAddress?.errors?.[name]?.error;setHasError(!!fieldError)}if(!isEmpty(shippingAddress)){const fieldError=shippingAddress?.errors?.[name]?.error;setHasError(!!fieldError)}return()=>{setHasError(!1)}},[value,billingAddress,shippingAddress,addressErrors]);const errorClassName=billingAddress?.errorClassName||shippingAddress?.errorClassName,classNameComputed=isEmptyStates(countryCode)?`${className} ${inputClassName} ${hasError?errorClassName:""}`:`${className} ${selectClassName} ${hasError?errorClassName:""}`;return isEmptyStates(countryCode)?_jsx(BaseInput,{...p,name,ref:billingAddress?.validation||shippingAddress?.validation,className:classNameComputed,required,placeholder:p.placeholder?.label||"",defaultValue:val,type:"text"}):_jsx(BaseSelect,{...p,className:classNameComputed,ref:billingAddress?.validation||shippingAddress?.validation,required,options:getStateOfCountry(countryCode),name,value:val})};AddressStateSelector.propTypes=propTypes,AddressStateSelector.defaultProps=defaultProps,AddressStateSelector.displayName=displayName;export default AddressStateSelector;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext,{defaultAddressContext}from"../context/AddressContext";import{useContext,useEffect,useReducer}from"react";import addressReducer,{addressInitialState,setAddressErrors,setCloneAddress}from"../reducers/AddressReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import{saveAddresses}from"../reducers/AddressReducer";import components from"../config/components";const propTypes=components.AddressesContainer.propTypes,displayName=components.AddressesContainer.displayName,AddressesContainer=props=>{const{children,shipToDifferentAddress=!1,isBusiness}=props,[state,dispatch]=useReducer(addressReducer,addressInitialState),{order,orderId,updateOrder}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>(dispatch({type:"setShipToDifferentAddress",payload:{shipToDifferentAddress,isBusiness}}),()=>{dispatch({type:"cleanup",payload:{}})}),[shipToDifferentAddress,isBusiness]);const contextValue=Object.assign(Object.assign({},state),{setAddressErrors:(errors,resource)=>setAddressErrors({errors,resource,dispatch,currentErrors:state.errors}),setAddress:params=>defaultAddressContext.setAddress(Object.assign(Object.assign({},params),{dispatch})),saveAddresses:async()=>await saveAddresses({config,dispatch,updateOrder,order,orderId,state}),setCloneAddress:(id,resource)=>setCloneAddress(id,resource,dispatch)});return _jsx(AddressesContext.Provider,Object.assign({value:contextValue},{children}))};AddressesContainer.propTypes=propTypes,AddressesContainer.displayName=displayName;export default AddressesContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext,{defaultAddressContext}from"../context/AddressContext";import{useContext,useEffect,useReducer}from"react";import addressReducer,{addressInitialState,setAddressErrors,setCloneAddress}from"../reducers/AddressReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import{saveAddresses}from"../reducers/AddressReducer";import components from"../config/components";const propTypes=components.AddressesContainer.propTypes,displayName=components.AddressesContainer.displayName,AddressesContainer=props=>{const{children,shipToDifferentAddress=!1,isBusiness}=props,[state,dispatch]=useReducer(addressReducer,addressInitialState),{order,orderId,updateOrder}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>(dispatch({type:"setShipToDifferentAddress",payload:{shipToDifferentAddress,isBusiness}}),()=>{dispatch({type:"cleanup",payload:{}})}),[shipToDifferentAddress,isBusiness]);const contextValue={...state,setAddressErrors:(errors,resource)=>setAddressErrors({errors,resource,dispatch,currentErrors:state.errors}),setAddress:params=>defaultAddressContext.setAddress({...params,dispatch}),saveAddresses:async()=>await saveAddresses({config,dispatch,updateOrder,order,orderId,state}),setCloneAddress:(id,resource)=>setCloneAddress(id,resource,dispatch)};return _jsx(AddressesContext.Provider,{value:contextValue,children})};AddressesContainer.propTypes=propTypes,AddressesContainer.displayName=displayName;export default AddressesContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.AdjustmentAmount.propTypes,defaultProps=components.AdjustmentAmount.defaultProps,displayName=components.AdjustmentAmount.displayName,AdjustmentAmount=props=>_jsx(BaseOrderPrice,Object.assign({base:"amount",type:"adjustment"},props));AdjustmentAmount.propTypes=propTypes,AdjustmentAmount.defaultProps=defaultProps,AdjustmentAmount.displayName=displayName;export default AdjustmentAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.AdjustmentAmount.propTypes,defaultProps=components.AdjustmentAmount.defaultProps,displayName=components.AdjustmentAmount.displayName,AdjustmentAmount=props=>_jsx(BaseOrderPrice,{base:"amount",type:"adjustment",...props});AdjustmentAmount.propTypes=propTypes,AdjustmentAmount.defaultProps=defaultProps,AdjustmentAmount.displayName=displayName;export default AdjustmentAmount;
@@ -1,4 +1,4 @@
1
- import { CSSProperties, FunctionComponent } from 'react';
1
+ import { CSSProperties } from 'react';
2
2
  import { PaymentSourceProps } from './PaymentSource';
3
3
  declare type Styles = Partial<{
4
4
  base: CSSProperties;
@@ -6,20 +6,50 @@ declare type Styles = Partial<{
6
6
  placeholder: CSSProperties;
7
7
  validated: CSSProperties;
8
8
  }>;
9
+ declare type PaypalStyle = Partial<{
10
+ /**
11
+ * @see {@link https://developer.paypal.com/docs/checkout/integration-features/customize-button/#color}
12
+ */
13
+ color: 'gold' | 'blue' | 'silver' | 'white' | 'black';
14
+ /**
15
+ * @see {@link https://developer.paypal.com/docs/checkout/integration-features/customize-button/#shape}
16
+ */
17
+ shape: 'rect' | 'pill';
18
+ /**
19
+ * @see {@link https://developer.paypal.com/docs/checkout/integration-features/customize-button/#height}
20
+ */
21
+ height: string | number;
22
+ /**
23
+ * @see {@link https://developer.paypal.com/docs/checkout/integration-features/customize-button/#label}
24
+ */
25
+ label: 'paypal' | 'checkout' | 'buynow' | 'pay';
26
+ /**
27
+ * @see {@link https://developer.paypal.com/docs/checkout/integration-features/customize-button/#tagline}
28
+ */
29
+ tagline: boolean;
30
+ /**
31
+ * @see {@link https://developer.paypal.com/docs/checkout/integration-features/customize-button/#layout}
32
+ */
33
+ layout: 'vertical' | 'horizontal';
34
+ }>;
35
+ interface PaymentMethodsStyle {
36
+ card?: Styles;
37
+ paypal?: PaypalStyle;
38
+ }
9
39
  export declare type AdyenPaymentConfig = {
10
40
  cardContainerClassName?: string;
11
41
  threeDSecureContainerClassName?: string;
12
42
  placeOrderCallback?: (response: {
13
43
  placed: boolean;
14
44
  }) => void;
15
- styles?: Styles;
45
+ styles?: PaymentMethodsStyle;
16
46
  };
17
- declare type AdyenPaymentProps = {
47
+ declare type Props = {
18
48
  clientKey?: string;
19
49
  config?: AdyenPaymentConfig;
20
50
  templateCustomerSaveToWallet?: PaymentSourceProps['templateCustomerSaveToWallet'];
21
51
  locale?: string;
22
52
  environment?: string;
23
53
  };
24
- declare const AdyenPayment: FunctionComponent<AdyenPaymentProps>;
54
+ export declare function AdyenPayment({ clientKey, config, templateCustomerSaveToWallet, environment, locale, }: Props): JSX.Element | null;
25
55
  export default AdyenPayment;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import{setCustomerOrderParam}from"../utils/localStorage";import Parent from"./utils/Parent";import getBrowserInfo from"../utils/browserInfo";import PlaceOrderContext from"../context/PlaceOrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={},AdyenPayment=({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"})=>{const{cardContainerClassName,threeDSecureContainerClassName,placeOrderCallback,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState({}),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{setPlaceOrder}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,checkout2)=>{var _a,_b,_c,_d,_e,_f,_g;const savePaymentSourceToCustomerWallet=(_b=(_a=e==null?void 0:e.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet);const attributes={_authorize:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_c=pSource==null?void 0:pSource.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource==null?void 0:pSource.payment_response)===null||_d===void 0?void 0:_d.resultCode;if(adyenAction&&["IdentifyShopper","RedirectShopper"].includes(resultCode))checkout2.createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action");else if(["Authorised","Pending","Received"].includes(resultCode)){const brand=(_f=(_e=pSource==null?void 0:pSource.payment_request_data)===null||_e===void 0?void 0:_e.payment_method)===null||_f===void 0?void 0:_f.brand;if(brand){const attributes2={metadata:{card:{brand}}};await setPaymentSource({paymentSourceId:pSource==null?void 0:pSource.id,paymentResource:"adyen_payments",attributes:attributes2})}return!0}const message=(_g=pSource==null?void 0:pSource.payment_response)===null||_g===void 0?void 0:_g.refusalReason;return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}},handleChange=async(state,_component,config2,paySource)=>{if(state.isValid){if(ref.current){const adyenCheckout=await require("@adyen/adyen-web")(config2);ref.current.onsubmit=()=>handleSubmit(ref.current,adyenCheckout),setPaymentRef({ref})}const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)}};paySource&&await setPaymentSource({paymentSourceId:paySource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,_component,config2)=>{var _a,_b;const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_a=pSource==null?void 0:pSource.payment_response)===null||_a===void 0?void 0:_a.action,resultCode=(_b=pSource==null?void 0:pSource.payment_response)===null||_b===void 0?void 0:_b.resultCode,AdyenCheckout=require("@adyen/adyen-web");if(adyenAction&&(await AdyenCheckout(config2)).createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action"),["Authorised","Pending","Received"].includes(resultCode)){const{placed}=setPlaceOrder&&await setPlaceOrder({paymentSource:pSource})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}}catch(error){console.error("Adyen additional details error:",error)}};return useEffect(()=>{const paymentMethodsResponse=isEmpty(paymentSource==null?void 0:paymentSource.payment_methods)?{}:paymentSource==null?void 0:paymentSource.payment_methods;isEmpty(paymentMethodsResponse)&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,paymentMethodsResponse};return options.onChange=(s,c)=>handleChange(s,c,options,paymentSource),options.onAdditionalDetails=(s,c)=>handleOnAdditionalDetails(s,c,options),!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&!isEmpty(window)&&require("@adyen/adyen-web")(options).then(adyenCheckout=>{adyenCheckout.create("card",{styles}).mount("#adyen-card")&&(setCheckout(adyenCheckout),setLoadAdyen(!0))}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",Object.assign({ref,onSubmit:e=>handleSubmit(e,checkout)},{children:[_jsx("div",{className:cardContainerClassName,id:"adyen-card"}),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet})),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]}))};export default AdyenPayment;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import{setCustomerOrderParam}from"../utils/localStorage";import Parent from"./utils/Parent";import getBrowserInfo from"../utils/browserInfo";import PlaceOrderContext from"../context/PlaceOrderContext";import OrderContext from"../context/OrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};export function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState(null),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{placeOrderButtonRef}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component&&component.submit&&component.submit(),!1},handleChange=async(state,checkout2)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=()=>handleSubmit(ref.current,checkout2),setPaymentRef({ref}));const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}};paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,component)=>{const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=pSource?.payment_response?.action,resultCode=pSource?.payment_response?.resultCode;if(adyenAction&&component)return component.handleAction(adyenAction),!1;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=pSource?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return console.error("Adyen additional details error:",error),!1}},onSubmit=async(state,component)=>{if((await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"}))?.payment_response?.resultCode==="Authorised")return!0;const attributes={payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:window.location.href},_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=res?.payment_response?.action;if(component&&action)return component.handleAction(action),!1;const resultCode=res?.payment_response?.resultCode;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=res?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}if(res?.payment_response?.errorType)if(res?.payment_response?.errorCode==="14_006")onSubmit(state,component);else{const message=res?.payment_response?.message;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}};return useEffect(()=>{const paymentMethodsResponse=paymentSource?.payment_methods?.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],[firstPaymentMethod]=paymentMethodsResponse,isOnlyCard=paymentMethodsResponse?.length===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse:{paymentMethods:paymentMethodsResponse},showPayButton:!1,paymentMethodsConfiguration:{threeDS2:threeDSConfiguration,paypal:{showPayButton:!0,style:styles?.paypal},card:{styles:styles?.card,holderNameRequired:!1}},onAdditionalDetails:handleOnAdditionalDetails,onChange:handleChange,onSubmit};return!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&import("@adyen/adyen-web").then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=()=>handleSubmit(ref.current,component2):ref.current.onsubmit=null,setPaymentRef({ref}))}}).mount("#adyen-dropin");component&&(setCheckout(component),setLoadAdyen(!0))})}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",{ref,onSubmit:e=>handleSubmit(e,checkout),children:[_jsx("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}export default AdyenPayment;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability,getAvailabilityByIds}from"../reducers/AvailabilityReducer";import AvailabilityContext from"../context/AvailabilityContext";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import components from"../config/components";import CommerceLayerContext from"../context/CommerceLayerContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import SkuChildrenContext from"../context/SkuChildrenContext";import SkuContext from"../context/SkuContext";import isEqual from"lodash/isEqual";const propTypes=components.AvailabilityContainer.propTypes,displayName=components.AvailabilityContainer.displayName,AvailabilityContainer=props=>{const{children,skuCode}=props,{item,skuCode:itemSkuCode,setItem}=useContext(ItemContext),{lineItem}=useContext(LineItemChildrenContext),{sku}=useContext(SkuChildrenContext),{skus}=useContext(SkuContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||getCurrentItemKey(item)||itemSkuCode||(lineItem==null?void 0:lineItem.sku_code)||(sku==null?void 0:sku.code);return useEffect(()=>{var _a,_b,_c,_d,_e,_f,_g;if(sCode&&!skus){const available=(_b=(_a=item[sCode])===null||_a===void 0?void 0:_a.inventory)===null||_b===void 0?void 0:_b.available,quantity=(_d=(_c=item[sCode])===null||_c===void 0?void 0:_c.inventory)===null||_d===void 0?void 0:_d.quantity,[level]=((_f=(_e=item[sCode])===null||_e===void 0?void 0:_e.inventory)===null||_f===void 0?void 0:_f.levels)||[{quantity:null,delivery_lead_times:[]}];if(level!==void 0&&((_g=level==null?void 0:level.delivery_lead_times)===null||_g===void 0?void 0:_g.length)>0){const[delivery]=level.delivery_lead_times;dispatch({type:"setAvailability",payload:Object.assign(Object.assign({},delivery),{quantity:level==null?void 0:level.quantity})})}else config.accessToken&&!(item==null?void 0:item[sCode])?getAvailability({skuCode:sCode,config,dispatch,setItem,item}):available||dispatch({type:"setAvailability",payload:{quantity}})}else if(skus&&config.accessToken){const itemKeys=Object.keys(item).sort(),skuCodes=skus.map(s=>s==null?void 0:s.code).sort();if(!isEqual(skuCodes,itemKeys)){const skusIds=skus.map(s=>s.id);getAvailabilityByIds({skusIds,config,dispatch,setItem})}}return()=>{dispatch({type:"setAvailability",payload:{}})}},[config.accessToken,item,sCode,skus]),_jsx(AvailabilityContext.Provider,Object.assign({value:Object.assign({},state)},{children}))};AvailabilityContainer.propTypes=propTypes,AvailabilityContainer.displayName=displayName;export default AvailabilityContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability,getAvailabilityByIds}from"../reducers/AvailabilityReducer";import AvailabilityContext from"../context/AvailabilityContext";import ItemContext from"../context/ItemContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import components from"../config/components";import CommerceLayerContext from"../context/CommerceLayerContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import SkuChildrenContext from"../context/SkuChildrenContext";import SkuContext from"../context/SkuContext";import isEqual from"lodash/isEqual";const propTypes=components.AvailabilityContainer.propTypes,displayName=components.AvailabilityContainer.displayName,AvailabilityContainer=props=>{const{children,skuCode}=props,{item,skuCode:itemSkuCode,setItem}=useContext(ItemContext),{lineItem}=useContext(LineItemChildrenContext),{sku}=useContext(SkuChildrenContext),{skus}=useContext(SkuContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||getCurrentItemKey(item)||itemSkuCode||lineItem?.sku_code||sku?.code;return useEffect(()=>{if(sCode&&!skus){const available=item[sCode]?.inventory?.available,quantity=item[sCode]?.inventory?.quantity,[level]=item[sCode]?.inventory?.levels||[{quantity:null,delivery_lead_times:[]}];if(level!==void 0&&level?.delivery_lead_times?.length>0){const[delivery]=level.delivery_lead_times;dispatch({type:"setAvailability",payload:{...delivery,quantity:level?.quantity}})}else config.accessToken&&!item?.[sCode]?getAvailability({skuCode:sCode,config,dispatch,setItem,item}):available||dispatch({type:"setAvailability",payload:{quantity}})}else if(skus&&config.accessToken){const itemKeys=Object.keys(item).sort(),skuCodes=skus.map(s=>s?.code).sort();if(!isEqual(skuCodes,itemKeys)){const skusIds=skus.map(s=>s.id);getAvailabilityByIds({skusIds,config,dispatch,setItem})}}return()=>{dispatch({type:"setAvailability",payload:{}})}},[config.accessToken,item,sCode,skus]),_jsx(AvailabilityContext.Provider,{value:{...state},children})};AvailabilityContainer.propTypes=propTypes,AvailabilityContainer.displayName=displayName;export default AvailabilityContainer;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AvailabilityContext from"../context/AvailabilityContext";import Parent from"./utils/Parent";import{isEmpty}from"lodash";import components from"../config/components";import ItemContext from"../context/ItemContext";import SkuChildrenContext from"../context/SkuChildrenContext";const propTypes=components.AvailabilityTemplate.propTypes,defaultProps=components.AvailabilityTemplate.defaultProps,displayName=components.AvailabilityTemplate.displayName,AvailabilityTemplate=props=>{var _a;const{timeFormat,showShippingMethodName,showShippingMethodPrice,children}=props,p=__rest(props,["timeFormat","showShippingMethodName","showShippingMethodPrice","children"]);let{min,max,shipping_method,quantity}=useContext(AvailabilityContext);const{item}=useContext(ItemContext),{sku}=useContext(SkuChildrenContext),text=[];if(item&&sku){const code=sku.code,currentItem=item[code];if(currentItem){const[level]=((_a=currentItem.inventory)===null||_a===void 0?void 0:_a.levels)||[],[delivery]=(level==null?void 0:level.delivery_lead_times)||[];delivery&&(min=delivery==null?void 0:delivery.min,max=delivery==null?void 0:delivery.max,shipping_method=delivery==null?void 0:delivery.shipping_method),quantity=currentItem.inventory.quantity}}const mn=!isEmpty(min)&&timeFormat?min==null?void 0:min[timeFormat]:"",mx=!isEmpty(max)&&timeFormat?max==null?void 0:max[timeFormat]:"",shippingMethodPrice=showShippingMethodPrice&&(shipping_method==null?void 0:shipping_method.formatted_price_amount)?`(${shipping_method==null?void 0:shipping_method.formatted_price_amount})`:"",name=showShippingMethodName&&shipping_method?`with ${shipping_method.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps=Object.assign({min,max,shipping_method,quantity,text:text.join(" ")},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("p",Object.assign({},p,{children:text.join(" ")}))};AvailabilityTemplate.propTypes=propTypes,AvailabilityTemplate.defaultProps=defaultProps,AvailabilityTemplate.displayName=displayName;export default AvailabilityTemplate;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import AvailabilityContext from"../context/AvailabilityContext";import Parent from"./utils/Parent";import{isEmpty}from"lodash";import components from"../config/components";import ItemContext from"../context/ItemContext";import SkuChildrenContext from"../context/SkuChildrenContext";const propTypes=components.AvailabilityTemplate.propTypes,defaultProps=components.AvailabilityTemplate.defaultProps,displayName=components.AvailabilityTemplate.displayName,AvailabilityTemplate=props=>{const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props;let{min,max,shipping_method,quantity}=useContext(AvailabilityContext);const{item}=useContext(ItemContext),{sku}=useContext(SkuChildrenContext),text=[];if(item&&sku){const code=sku.code,currentItem=item[code];if(currentItem){const[level]=currentItem.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];delivery&&(min=delivery?.min,max=delivery?.max,shipping_method=delivery?.shipping_method),quantity=currentItem.inventory.quantity}}const mn=!isEmpty(min)&&timeFormat?min?.[timeFormat]:"",mx=!isEmpty(max)&&timeFormat?max?.[timeFormat]:"",shippingMethodPrice=showShippingMethodPrice&&shipping_method?.formatted_price_amount?`(${shipping_method?.formatted_price_amount})`:"",name=showShippingMethodName&&shipping_method?`with ${shipping_method.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps={min,max,shipping_method,quantity,text:text.join(" "),...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:text.join(" ")})};AvailabilityTemplate.propTypes=propTypes,AvailabilityTemplate.defaultProps=defaultProps,AvailabilityTemplate.displayName=displayName;export default AvailabilityTemplate;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BillingAddressContext from"../context/BillingAddressContext";import{useContext,useEffect,useReducer}from"react";import billingAddressReducer,{billingAddressInitialState,setBillingAddress,setBillingCustomerAddressId}from"../reducers/BillingAddressReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";const propTypes=components.BillingAddressContainer.propTypes,BillingAddressContainer=props=>{const{children}=props,[state,dispatch]=useReducer(billingAddressReducer,billingAddressInitialState),config=useContext(CommerceLayerContext),{order,include,addResourceToInclude}=useContext(OrderContext),{shipToDifferentAddress,setCloneAddress}=useContext(AddressContext);useEffect(()=>((include==null?void 0:include.includes("billing_address"))||addResourceToInclude({newResource:"billing_address",resourcesIncluded:include}),order&&config&&setBillingCustomerAddressId({dispatch,order,setCloneAddress}),()=>{dispatch({type:"cleanup",payload:{}})}),[order,include]);const contextValue=Object.assign(Object.assign({},state),{setBillingAddress:async(id,options)=>{await setBillingAddress(id,{config,dispatch,order,shipToDifferentAddress,customerAddressId:options==null?void 0:options.customerAddressId}),setCloneAddress(id,"billing_address")}});return _jsx(BillingAddressContext.Provider,Object.assign({value:contextValue},{children}))};BillingAddressContainer.propTypes=propTypes;export default BillingAddressContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BillingAddressContext from"../context/BillingAddressContext";import{useContext,useEffect,useReducer}from"react";import billingAddressReducer,{billingAddressInitialState,setBillingAddress,setBillingCustomerAddressId}from"../reducers/BillingAddressReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";const propTypes=components.BillingAddressContainer.propTypes,BillingAddressContainer=props=>{const{children}=props,[state,dispatch]=useReducer(billingAddressReducer,billingAddressInitialState),config=useContext(CommerceLayerContext),{order,include,addResourceToInclude}=useContext(OrderContext),{shipToDifferentAddress,setCloneAddress}=useContext(AddressContext);useEffect(()=>(include?.includes("billing_address")||addResourceToInclude({newResource:"billing_address",resourcesIncluded:include}),order&&config&&setBillingCustomerAddressId({dispatch,order,setCloneAddress}),()=>{dispatch({type:"cleanup",payload:{}})}),[order,include]);const contextValue={...state,setBillingAddress:async(id,options)=>{await setBillingAddress(id,{config,dispatch,order,shipToDifferentAddress,customerAddressId:options?.customerAddressId}),setCloneAddress(id,"billing_address")}};return _jsx(BillingAddressContext.Provider,{value:contextValue,children})};BillingAddressContainer.propTypes=propTypes;export default BillingAddressContainer;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../context/BillingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../utils/localStorage";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.BillingAddressForm.propTypes,BillingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c,_d,_e;if((include==null?void 0:include.includes("billing_address"))?(includeLoaded==null?void 0:includeLoaded.billing_address)||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(!isEmpty(values)){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],((field==null?void 0:field.value)||(field==null?void 0:field.required)===!1&&(field==null?void 0:field.type)!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=(_a=errors[fieldName])===null||_a===void 0?void 0:_a.code,message=(_b=errors[fieldName])===null||_b===void 0?void 0:_b.message;["billing_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName}):formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=((_d=(_c=ref.current)===null||_c===void 0?void 0:_c.querySelector('[name="billing_address_save_to_customer_book"]'))===null||_d===void 0?void 0:_d.checked)||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&((_e=ref.current)===null||_e===void 0||_e.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"billing_address"})},errorClassName,requiresBillingInfo:(order==null?void 0:order.requires_billing_info)||!1,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(BillingAddressFormContext.Provider,Object.assign({value:providerValues},{children:_jsx("form",Object.assign({ref,autoComplete},p,{children}))}))};BillingAddressForm.propTypes=propTypes;export default BillingAddressForm;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../context/BillingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../utils/localStorage";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.BillingAddressForm.propTypes,BillingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1,...p}=props,{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{if(include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(!isEmpty(values)){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field?.value||field?.required===!1&&field?.type!=="checkbox")&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),field?.type==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:{...values,...isBusiness&&{business:isBusiness}},resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;["billing_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName}):formErrors.push({code,message:message||"",resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=ref.current?.querySelector('[name="billing_address_save_to_customer_book"]')?.checked||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&(ref.current?.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:{...values,...field,...isBusiness&&{business:isBusiness}},resource:"billing_address"})},errorClassName,requiresBillingInfo:order?.requires_billing_info||!1,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(BillingAddressFormContext.Provider,{value:providerValues,children:_jsx("form",{ref,autoComplete,...p,children})})};BillingAddressForm.propTypes=propTypes;export default BillingAddressForm;
@@ -1 +1 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";import promisify from"../utils/promisify";const defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"},BraintreePayment=({authorization,config,templateCustomerSaveToWallet})=>{var _a,_b,_c;const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}=Object.assign(Object.assign({},defaultConfig),config),[loadBraintree,setLoadBraintree]=useState(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),ref=useRef(null),handleSubmitForm=async({event,hostedFieldsInstance,threeDSInstance})=>{var _a2,_b2;const savePaymentSourceToCustomerWallet=(_b2=(_a2=event==null?void 0:event.elements)===null||_a2===void 0?void 0:_a2.save_payment_source_to_customer_wallet)===null||_b2===void 0?void 0:_b2.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=await promisify(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order==null?void 0:order.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:order==null?void 0:order.total_amount_with_taxes_float,email:order==null?void 0:order.customer_email,billingAddress:{givenName:billingAddress==null?void 0:billingAddress.first_name,surname:billingAddress==null?void 0:billingAddress.last_name,phoneNumber:billingAddress==null?void 0:billingAddress.phone,streetAddress:billingAddress==null?void 0:billingAddress.line_1,countryCodeAlpha2:billingAddress==null?void 0:billingAddress.country_code,postalCode:billingAddress==null?void 0:billingAddress.zip_code,region:billingAddress==null?void 0:billingAddress.state_code,locality:billingAddress==null?void 0:billingAddress.city},onLookupComplete:(_data,next)=>{next()}},response=await threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}}),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1};return useEffect(()=>{if(!ref&&authorization&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!isEmpty(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,threeDSInstance)=>{threeDSecureErr&&(console.error("3DSecure error",threeDSecureErr),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:threeDSecureErr.message}])),ref.current&&(ref.current.onsubmit=paymentSource2=>handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:_jsx("div",Object.assign({className:containerClassName},{children:_jsxs("form",Object.assign({ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName},{children:[_jsxs("div",Object.assign({className:fieldsContainerClassName},{children:[_jsxs("div",Object.assign({className:cardContainerClassName},{children:[_jsx("label",Object.assign({className:fieldLabelClassName,htmlFor:"card-number"},{children:(_a=fields==null?void 0:fields.number)===null||_a===void 0?void 0:_a.label})),_jsx("div",{className:inputWrapperClassName,id:"card-number"})]})),_jsxs("div",Object.assign({className:cardDetailsContainerClassName},{children:[_jsxs("div",Object.assign({className:expDateContainerClassName},{children:[_jsx("label",Object.assign({className:fieldLabelClassName,htmlFor:"expiration-date"},{children:(_b=fields==null?void 0:fields.expirationDate)===null||_b===void 0?void 0:_b.label})),_jsx("div",{className:inputWrapperClassName,id:"expiration-date"})]})),_jsxs("div",Object.assign({className:cvvContainerClassName},{children:[_jsx("label",Object.assign({className:fieldLabelClassName,htmlFor:"cvv"},{children:(_c=fields==null?void 0:fields.cvv)===null||_c===void 0?void 0:_c.label})),_jsx("div",{className:inputWrapperClassName,id:"cvv"})]}))]}))]})),_jsx("div",Object.assign({className:fieldsContainerClassName},{children:templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))}))]}))}))};export default BraintreePayment;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";import promisify from"../utils/promisify";const defaultConfig={styles:{input:{"font-size":"16px",color:"#3A3A3A"},".number":{"font-family":"monospace"},":focus":{color:"blue"},".valid":{color:"green"},".invalid":{color:"red"},"@media screen and (max-width: 700px)":{input:{"font-size":"14px"}}},fields:{number:{label:"Card Number",selector:"#card-number",placeholder:"4111 1111 1111 1111"},cvv:{label:"CVV",selector:"#cvv",placeholder:"123"},expirationDate:{label:"Expiration Date",selector:"#expiration-date",placeholder:"10/2022"}},submitLabel:"Set payment method"},BraintreePayment=({authorization,config,templateCustomerSaveToWallet})=>{const{fields,styles,containerClassName,cardContainerClassName,fieldsContainerClassName,expDateContainerClassName,fieldLabelClassName,cvvContainerClassName,inputWrapperClassName,cardDetailsContainerClassName}={...defaultConfig,...config},[loadBraintree,setLoadBraintree]=useState(!1),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),ref=useRef(null),handleSubmitForm=async({event,hostedFieldsInstance,threeDSInstance})=>{const savePaymentSourceToCustomerWallet=event?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),hostedFieldsInstance)try{const payload=await promisify(hostedFieldsInstance).then(payload2=>payload2),billingAddress=order?.billing_address,verifyCardOptions={nonce:payload.nonce,bin:payload.details.bin,amount:order?.total_amount_with_taxes_float,email:order?.customer_email,billingAddress:{givenName:billingAddress?.first_name,surname:billingAddress?.last_name,phoneNumber:billingAddress?.phone,streetAddress:billingAddress?.line_1,countryCodeAlpha2:billingAddress?.country_code,postalCode:billingAddress?.zip_code,region:billingAddress?.state_code,locality:billingAddress?.city},onLookupComplete:(_data,next)=>{next()}},response=await threeDSInstance.verifyCard(verifyCardOptions);return response.rawCardinalSDKVerificationData.Validated&&paymentSource?(paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"braintree_payments",attributes:{payment_method_nonce:response.nonce,options:{id:response.nonce,card:{last4:response.details.lastFour,exp_year:response.details.expirationYear,exp_month:response.details.expirationMonth,brand:response.details.cardType.toLowerCase()}}}}),!0):!1}catch(error){return console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}return!1};return useEffect(()=>{if(!ref&&authorization&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),authorization&&!loadBraintree&&!isEmpty(window)){const braintreeClient=require("braintree-web/client"),hostedFields=require("braintree-web/hosted-fields"),threeDSecure=require("braintree-web/three-d-secure");braintreeClient.create({authorization},(clientErr,clientInstance)=>{if(clientErr){console.error(clientErr);return}hostedFields.create({client:clientInstance,fields,styles},(hostedFieldsErr,hostedFieldsInstance)=>{if(hostedFieldsErr){console.error(hostedFieldsErr);return}setLoadBraintree(!0),threeDSecure.create({authorization,version:2},(threeDSecureErr,threeDSInstance)=>{threeDSecureErr&&(console.error("3DSecure error",threeDSecureErr),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:threeDSecureErr.message}])),ref.current&&(ref.current.onsubmit=paymentSource2=>handleSubmitForm({event:ref.current,hostedFieldsInstance,threeDSInstance,paymentSource:paymentSource2}),setPaymentRef({ref}))})})})}return()=>{setPaymentRef({ref:{current:null}}),setLoadBraintree(!1)}},[authorization,ref]),!authorization&&!loadBraintree?null:_jsx("div",{className:containerClassName,children:_jsxs("form",{ref,id:"braintree-form",onSubmit:handleSubmitForm,className:containerClassName,children:[_jsxs("div",{className:fieldsContainerClassName,children:[_jsxs("div",{className:cardContainerClassName,children:[_jsx("label",{className:fieldLabelClassName,htmlFor:"card-number",children:fields?.number?.label}),_jsx("div",{className:inputWrapperClassName,id:"card-number"})]}),_jsxs("div",{className:cardDetailsContainerClassName,children:[_jsxs("div",{className:expDateContainerClassName,children:[_jsx("label",{className:fieldLabelClassName,htmlFor:"expiration-date",children:fields?.expirationDate?.label}),_jsx("div",{className:inputWrapperClassName,id:"expiration-date"})]}),_jsxs("div",{className:cvvContainerClassName,children:[_jsx("label",{className:fieldLabelClassName,htmlFor:"cvv",children:fields?.cvv?.label}),_jsx("div",{className:inputWrapperClassName,id:"cvv"})]})]})]}),_jsx("div",{className:fieldsContainerClassName,children:templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})})]})})};export default BraintreePayment;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import CommerceLayerContext from"../context/CommerceLayerContext";import getCartLink from"../utils/getCartLink";export default function CartLink(props){const{label,children}=props,p=__rest(props,["label","children"]),{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=slug&&(order==null?void 0:order.id)?getCartLink({slug,orderId:order==null?void 0:order.id,accessToken}):"",handleClick=async event=>{if(event.preventDefault(),order==null?void 0:order.id)location.href=href;else{const orderId=await createOrder();slug&&(location.href=getCartLink({slug,orderId,accessToken}))}},parentProps=Object.assign({handleClick,label,href},p);return accessToken?children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("a",Object.assign({href},p,{onClick:handleClick},{children:typeof label=="function"?label():label})):null}
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import CommerceLayerContext from"../context/CommerceLayerContext";import getCartLink from"../utils/getCartLink";export default function CartLink(props){const{label,children,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=slug&&order?.id?getCartLink({slug,orderId:order?.id,accessToken}):"",handleClick=async event=>{if(event.preventDefault(),order?.id)location.href=href;else{const orderId=await createOrder();slug&&(location.href=getCartLink({slug,orderId,accessToken}))}},parentProps={handleClick,label,href,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,onClick:handleClick,children:typeof label=="function"?label():label}):null}
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useRef}from"react";import useExternalScript from"../utils/hooks/useExternalScript";import PaymentMethodContext from"../context/PaymentMethodContext";import{Frames,CardNumber,ExpiryDate,Cvv}from"frames-react";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";const scriptUrl="https://cdn.checkout.com/js/framesv2.min.js",systemLanguages=["DE-DE","EN-GB","ES-ES","FR-FR","IT-IT","KR-KR","NL-NL"],defaultOptions={style:{base:{color:"black",fontSize:"18px"},autofill:{backgroundColor:"yellow"},hover:{color:"blue"},focus:{color:"blue"},valid:{color:"green"},invalid:{color:"red"},placeholder:{base:{color:"gray"},focus:{border:"solid 1px blue"}}}},CheckoutComPayment=_a=>{var{publicKey,options=defaultOptions,locale="EN-GB"}=_a,p=__rest(_a,["publicKey","options","locale"]);const ref=useRef(null),loaded=useExternalScript(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{containerClassName,templateCustomerSaveToWallet,success_url=window.location.href,failure_url=window.location.href,show}=p,divProps=__rest(p,["containerClassName","templateCustomerSaveToWallet","success_url","failure_url","show"]),handleSubmit=async()=>{var _a2,_b,_c,_d,_e,_f,_g,_h,_j,_k,_l;const savePaymentSourceToCustomerWallet=(_c=(_b=(_a2=ref==null?void 0:ref.current)===null||_a2===void 0?void 0:_a2.elements)===null||_b===void 0?void 0:_b.save_payment_source_to_customer_wallet)===null||_c===void 0?void 0:_c.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:(_d=order==null?void 0:order.billing_address)===null||_d===void 0?void 0:_d.full_name,billingAddress:{addressLine1:(_e=order==null?void 0:order.billing_address)===null||_e===void 0?void 0:_e.line_1,addressLine2:(_f=order==null?void 0:order.billing_address)===null||_f===void 0?void 0:_f.line_2,zip:(_g=order==null?void 0:order.billing_address)===null||_g===void 0?void 0:_g.zip_code,city:(_h=order==null?void 0:order.billing_address)===null||_h===void 0?void 0:_h.city,state:(_j=order==null?void 0:order.billing_address)===null||_j===void 0?void 0:_j.state_code,country:(_k=order==null?void 0:order.billing_address)===null||_k===void 0?void 0:_k.country_code},phone:(_l=order==null?void 0:order.billing_address)===null||_l===void 0?void 0:_l.phone};try{const data=await window.Frames.submitCard();if(data.token&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{token:data.token,payment_type:"token",success_url,failure_url,_authorize:!0}});ps&&ps.redirect_uri&&(window.location.href=ps.redirect_uri)}}catch(error){console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error==null?void 0:error.message}])}}return!1},lang=`${locale.toUpperCase()}-${locale.toUpperCase()}`,localization=systemLanguages.includes(lang)?lang:"EN-GB";return loaded&&show?_jsxs("form",Object.assign({ref},{children:[_jsx("div",Object.assign({className:containerClassName},divProps,{children:_jsxs(Frames,Object.assign({config:Object.assign({debug:!0,publicKey,localization},options),cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=()=>handleSubmit(),setPaymentRef({ref}))},cardTokenized:data=>data},{children:[_jsx(CardNumber,{}),_jsx(ExpiryDate,{}),_jsx(Cvv,{})]}))})),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}))]})):null};export default CheckoutComPayment;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useRef}from"react";import useExternalScript from"../utils/hooks/useExternalScript";import PaymentMethodContext from"../context/PaymentMethodContext";import{Frames,CardNumber,ExpiryDate,Cvv}from"frames-react";import OrderContext from"../context/OrderContext";import Parent from"./utils/Parent";import{setCustomerOrderParam}from"../utils/localStorage";const scriptUrl="https://cdn.checkout.com/js/framesv2.min.js",systemLanguages=["DE-DE","EN-GB","ES-ES","FR-FR","IT-IT","KR-KR","NL-NL"],defaultOptions={style:{base:{color:"black",fontSize:"18px"},autofill:{backgroundColor:"yellow"},hover:{color:"blue"},focus:{color:"blue"},valid:{color:"green"},invalid:{color:"red"},placeholder:{base:{color:"gray"},focus:{border:"solid 1px blue"}}}},CheckoutComPayment=({publicKey,options=defaultOptions,locale="EN-GB",...p})=>{const ref=useRef(null),loaded=useExternalScript(scriptUrl),{setPaymentRef,currentPaymentMethodType,paymentSource,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{containerClassName,templateCustomerSaveToWallet,success_url=window.location.href,failure_url=window.location.href,show,...divProps}=p,handleSubmit=async()=>{const savePaymentSourceToCustomerWallet=ref?.current?.elements?.save_payment_source_to_customer_wallet?.checked;if(savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),window.Frames){window.Frames.cardholder={name:order?.billing_address?.full_name,billingAddress:{addressLine1:order?.billing_address?.line_1,addressLine2:order?.billing_address?.line_2,zip:order?.billing_address?.zip_code,city:order?.billing_address?.city,state:order?.billing_address?.state_code,country:order?.billing_address?.country_code},phone:order?.billing_address?.phone};try{const data=await window.Frames.submitCard();if(data.token&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{token:data.token,payment_type:"token",success_url,failure_url,_authorize:!0}});ps&&ps.redirect_uri&&(window.location.href=ps.redirect_uri)}}catch(error){console.error(error),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error?.message}])}}return!1},lang=`${locale.toUpperCase()}-${locale.toUpperCase()}`,localization=systemLanguages.includes(lang)?lang:"EN-GB";return loaded&&show?_jsxs("form",{ref,children:[_jsx("div",{className:containerClassName,...divProps,children:_jsxs(Frames,{config:{debug:!0,publicKey,localization,...options},cardValidationChanged:e=>{e.isValid&&ref.current&&(ref.current.onsubmit=()=>handleSubmit(),setPaymentRef({ref}))},cardTokenized:data=>data,children:[_jsx(CardNumber,{}),_jsx(ExpiryDate,{}),_jsx(Cvv,{})]})}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet})]}):null};export default CheckoutComPayment;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../context/OrderContext";import components from"../config/components";import Parent from"./utils/Parent";import CommerceLayerContext from"../context/CommerceLayerContext";const propTypes=components.CheckoutLink.propTypes,defaultProps=components.CheckoutLink.defaultProps,displayName=components.CheckoutLink.displayName,CheckoutLink=props=>{const{label,hostedCheckout=!0,children}=props,p=__rest(props,["label","hostedCheckout","children"]),{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=hostedCheckout?`${slug}.checkout.commercelayer.app/${order==null?void 0:order.id}?accessToken=${accessToken}`:order==null?void 0:order.checkout_url,parentProps=Object.assign({checkoutUrl:order==null?void 0:order.checkout_url,hostedCheckout,label,href},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("a",Object.assign({href},p,{children:label}))};CheckoutLink.propTypes=propTypes,CheckoutLink.defaultProps=defaultProps,CheckoutLink.displayName=displayName;export default CheckoutLink;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../context/OrderContext";import components from"../config/components";import Parent from"./utils/Parent";import CommerceLayerContext from"../context/CommerceLayerContext";const propTypes=components.CheckoutLink.propTypes,defaultProps=components.CheckoutLink.defaultProps,displayName=components.CheckoutLink.displayName,CheckoutLink=props=>{const{label,hostedCheckout=!0,children,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=hostedCheckout?`${slug}.checkout.commercelayer.app/${order?.id}?accessToken=${accessToken}`:order?.checkout_url,parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,children:label})};CheckoutLink.propTypes=propTypes,CheckoutLink.defaultProps=defaultProps,CheckoutLink.displayName=displayName;export default CheckoutLink;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";const propTypes=components.CommerceLayer.propTypes,CommerceLayer=props=>{const{children}=props,p=__rest(props,["children"]);return _jsx(CommerceLayerContext.Provider,Object.assign({value:Object.assign({},p)},{children}))};CommerceLayer.propTypes=propTypes;export default CommerceLayer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";const propTypes=components.CommerceLayer.propTypes,CommerceLayer=props=>{const{children,...p}=props;return _jsx(CommerceLayerContext.Provider,{value:{...p},children})};CommerceLayer.propTypes=propTypes;export default CommerceLayer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useReducer}from"react";import customerReducer,{customerInitialState,getCustomerAddresses,getCustomerPaymentSources}from"../reducers/CustomerReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{saveCustomerUser}from"../reducers/CustomerReducer";import CustomerContext from"../context/CustomerContext";import{defaultCustomerContext}from"../context/CustomerContext";const propTypes=components.CustomerContainer.propTypes,displayName=components.CustomerContainer.displayName,CustomerContainer=props=>{const{children,isGuest=!1}=props,[state,dispatch]=useReducer(customerReducer,customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{!(include==null?void 0:include.includes("available_customer_payment_sources.payment_source"))&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!(includeLoaded==null?void 0:includeLoaded["available_customer_payment_sources.payment_source"])&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include,includeLoaded]),useEffect(()=>{var _a;config.accessToken&&order&&((_a=state.addresses)===null||_a===void 0?void 0:_a.length)===0&&!isGuest&&getCustomerAddresses({config,dispatch}),(order==null?void 0:order.available_customer_payment_sources)&&!isGuest&&getCustomerPaymentSources({dispatch,order})},[config.accessToken,order,isGuest]);const contextValue=Object.assign(Object.assign({isGuest},state),{saveCustomerUser:async customerEmail=>{await saveCustomerUser({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>defaultCustomerContext.setCustomerErrors(errors,dispatch),setCustomerEmail:customerEmail=>defaultCustomerContext.setCustomerEmail(customerEmail,dispatch),getCustomerPaymentSources:()=>getCustomerPaymentSources({dispatch,order})});return _jsx(CustomerContext.Provider,Object.assign({value:contextValue},{children}))};CustomerContainer.propTypes=propTypes,CustomerContainer.displayName=displayName;export default CustomerContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useReducer}from"react";import customerReducer,{customerInitialState,getCustomerAddresses,getCustomerPaymentSources}from"../reducers/CustomerReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{saveCustomerUser}from"../reducers/CustomerReducer";import CustomerContext from"../context/CustomerContext";import{defaultCustomerContext}from"../context/CustomerContext";const propTypes=components.CustomerContainer.propTypes,displayName=components.CustomerContainer.displayName,CustomerContainer=props=>{const{children,isGuest=!1}=props,[state,dispatch]=useReducer(customerReducer,customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include,includeLoaded]),useEffect(()=>{config.accessToken&&order&&state.addresses?.length===0&&!isGuest&&getCustomerAddresses({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&getCustomerPaymentSources({dispatch,order})},[config.accessToken,order,isGuest]);const contextValue={isGuest,...state,saveCustomerUser:async customerEmail=>{await saveCustomerUser({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>defaultCustomerContext.setCustomerErrors(errors,dispatch),setCustomerEmail:customerEmail=>defaultCustomerContext.setCustomerEmail(customerEmail,dispatch),getCustomerPaymentSources:()=>getCustomerPaymentSources({dispatch,order})};return _jsx(CustomerContext.Provider,{value:contextValue,children})};CustomerContainer.propTypes=propTypes,CustomerContainer.displayName=displayName;export default CustomerContainer;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import useRapidForm from"rapid-form";import CustomerContext from"../context/CustomerContext";import isEmpty from"lodash/isEmpty";const propTypes=components.CustomerInput.propTypes,displayName=components.CustomerInput.displayName,CustomerInput=props=>{const{name="customer_email",placeholder="",required=!0,saveOnBlur=!1,type="email",value,onBlur,className,errorClassName}=props,p=__rest(props,["name","placeholder","required","saveOnBlur","type","value","onBlur","className","errorClassName"]),{validation,values,errors}=useRapidForm({fieldEvent:"blur"}),{saveCustomerUser,setCustomerErrors,setCustomerEmail}=useContext(CustomerContext),[hasError,setHasError]=useState(!1),handleOnBlur=async()=>{saveOnBlur&&isEmpty(errors)&&!isEmpty(values)&&(await saveCustomerUser(values[name].value),onBlur&&onBlur(values[name].value))};useEffect(()=>{var _a,_b;if(isEmpty(errors))isEmpty(values)||(setCustomerErrors([]),setCustomerEmail(values[name].value),setHasError(!1));else{const formErrors=[];for(const fieldName in errors){const code=(_a=errors[fieldName])===null||_a===void 0?void 0:_a.code,message=(_b=errors[fieldName])===null||_b===void 0?void 0:_b.message;formErrors.push({code,message:message||"",resource:"orders",field:fieldName})}isEmpty(formErrors)||(setHasError(!0),setCustomerErrors(formErrors))}return()=>{setHasError(!1)}},[errors]);const classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseInput,Object.assign({name,type,ref:validation,required,placeholder,defaultValue:value,onBlur:handleOnBlur,className:classNameComputed},p))};CustomerInput.propTypes=propTypes,CustomerInput.displayName=displayName;export default CustomerInput;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import{useRapidForm}from"rapid-form";import CustomerContext from"../context/CustomerContext";import isEmpty from"lodash/isEmpty";const propTypes=components.CustomerInput.propTypes,displayName=components.CustomerInput.displayName,CustomerInput=props=>{const{name="customer_email",placeholder="",required=!0,saveOnBlur=!1,type="email",value,onBlur,className,errorClassName,...p}=props,{validation,values,errors}=useRapidForm({fieldEvent:"blur"}),{saveCustomerUser,setCustomerErrors,setCustomerEmail}=useContext(CustomerContext),[hasError,setHasError]=useState(!1),handleOnBlur=async()=>{saveOnBlur&&isEmpty(errors)&&!isEmpty(values)&&(await saveCustomerUser(values[name].value),onBlur&&onBlur(values[name].value))};useEffect(()=>{if(isEmpty(errors))isEmpty(values)||(setCustomerErrors([]),setCustomerEmail(values[name].value),setHasError(!1));else{const formErrors=[];for(const fieldName in errors){const code=errors[fieldName]?.code,message=errors[fieldName]?.message;formErrors.push({code,message:message||"",resource:"orders",field:fieldName})}isEmpty(formErrors)||(setHasError(!0),setCustomerErrors(formErrors))}return()=>{setHasError(!1)}},[errors]);const classNameComputed=`${className} ${hasError?errorClassName:""}`;return _jsx(BaseInput,{name,type,ref:validation,required,placeholder,defaultValue:value,onBlur:handleOnBlur,className:classNameComputed,...p})};CustomerInput.propTypes=propTypes,CustomerInput.displayName=displayName;export default CustomerInput;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.DeliveryLeadTime.propTypes,displayName=components.DeliveryLeadTime.displayName,DeliveryLeadTime=props=>{const{type}=props,p=__rest(props,["type"]),[text,setText]=useState(),{deliveryLeadTimeForShipment}=useContext(ShippingMethodChildrenContext);useEffect(()=>(deliveryLeadTimeForShipment&&deliveryLeadTimeForShipment[type]&&setText(deliveryLeadTimeForShipment[type]),()=>{setText("")}),[deliveryLeadTimeForShipment]);const parentProps=Object.assign({text},p);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("span",Object.assign({},p,{children:text}))};DeliveryLeadTime.propTypes=propTypes,DeliveryLeadTime.displayName=displayName;export default DeliveryLeadTime;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.DeliveryLeadTime.propTypes,displayName=components.DeliveryLeadTime.displayName,DeliveryLeadTime=props=>{const{type,...p}=props,[text,setText]=useState(),{deliveryLeadTimeForShipment}=useContext(ShippingMethodChildrenContext);useEffect(()=>(deliveryLeadTimeForShipment&&deliveryLeadTimeForShipment[type]&&setText(deliveryLeadTimeForShipment[type]),()=>{setText("")}),[deliveryLeadTimeForShipment]);const parentProps={text,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:text})};DeliveryLeadTime.propTypes=propTypes,DeliveryLeadTime.displayName=displayName;export default DeliveryLeadTime;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.DiscountAmount.propTypes,defaultProps=components.DiscountAmount.defaultProps,displayName=components.DiscountAmount.displayName,DiscountAmount=props=>_jsx(BaseOrderPrice,Object.assign({base:"amount",type:"discount"},props));DiscountAmount.propTypes=propTypes,DiscountAmount.defaultProps=defaultProps,DiscountAmount.displayName=displayName;export default DiscountAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.DiscountAmount.propTypes,defaultProps=components.DiscountAmount.defaultProps,displayName=components.DiscountAmount.displayName,DiscountAmount=props=>_jsx(BaseOrderPrice,{base:"amount",type:"discount",...props});DiscountAmount.propTypes=propTypes,DiscountAmount.defaultProps=defaultProps,DiscountAmount.displayName=displayName;export default DiscountAmount;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,Fragment,useMemo}from"react";import Parent from"./utils/Parent";import GiftCardContext from"../context/GiftCardContext";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";import getAllErrors from"./utils/getAllErrors";import LineItemContext from"../context/LineItemContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import PaymentMethodContext from"../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import ShipmentContext from"../context/ShipmentContext";const propTypes=components.Errors.propTypes,displayName=components.Errors.displayName,Errors=props=>{const{children,messages=[],resource,field}=props,p=__rest(props,["children","messages","resource","field"]),{payment}=useContext(PaymentMethodChildrenContext),{errors:orderErrors}=useContext(OrderContext),{errors:giftCardErrors}=useContext(GiftCardContext),{errors:lineItemErrors}=useContext(LineItemContext),{errors:addressErrors}=useContext(AddressContext),{errors:customerErrors}=useContext(CustomerContext),{errors:shipmentErrors}=useContext(ShipmentContext),{errors:paymentMethodErrors,currentPaymentMethodType,currentPaymentMethodId}=useContext(PaymentMethodContext),{lineItem}=useContext(LineItemChildrenContext),allErrors=useMemo(()=>[...giftCardErrors||[],...orderErrors||[],...lineItemErrors||[],...addressErrors||[],...customerErrors||[],...shipmentErrors||[],...(paymentMethodErrors==null?void 0:paymentMethodErrors.filter(v=>v.field===currentPaymentMethodType&&(payment==null?void 0:payment.id)===currentPaymentMethodId))||[]],[giftCardErrors,orderErrors,lineItemErrors,addressErrors,customerErrors,shipmentErrors,paymentMethodErrors]).filter((v,k,a)=>{var _a;return(v==null?void 0:v.code)!==((_a=a[k-1])===null||_a===void 0?void 0:_a.code)}),msgErrors=getAllErrors({allErrors,field,messages,props:p,lineItem,resource,returnHtml:!children}),parentProps=Object.assign({messages,resource,field,errors:msgErrors},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx(Fragment,{children:msgErrors})};Errors.propTypes=propTypes,Errors.displayName=displayName;export default Errors;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,Fragment,useMemo}from"react";import Parent from"./utils/Parent";import GiftCardContext from"../context/GiftCardContext";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";import getAllErrors from"./utils/getAllErrors";import LineItemContext from"../context/LineItemContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import PaymentMethodContext from"../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import ShipmentContext from"../context/ShipmentContext";const propTypes=components.Errors.propTypes,displayName=components.Errors.displayName,Errors=props=>{const{children,messages=[],resource,field,...p}=props,{payment}=useContext(PaymentMethodChildrenContext),{errors:orderErrors}=useContext(OrderContext),{errors:giftCardErrors}=useContext(GiftCardContext),{errors:lineItemErrors}=useContext(LineItemContext),{errors:addressErrors}=useContext(AddressContext),{errors:customerErrors}=useContext(CustomerContext),{errors:shipmentErrors}=useContext(ShipmentContext),{errors:paymentMethodErrors,currentPaymentMethodType,currentPaymentMethodId}=useContext(PaymentMethodContext),{lineItem}=useContext(LineItemChildrenContext),allErrors=useMemo(()=>[...giftCardErrors||[],...orderErrors||[],...lineItemErrors||[],...addressErrors||[],...customerErrors||[],...shipmentErrors||[],...paymentMethodErrors?.filter(v=>v.field===currentPaymentMethodType&&payment?.id===currentPaymentMethodId)||[]],[giftCardErrors,orderErrors,lineItemErrors,addressErrors,customerErrors,shipmentErrors,paymentMethodErrors]).filter((v,k,a)=>v?.code!==a[k-1]?.code),msgErrors=getAllErrors({allErrors,field,messages,props:p,lineItem,resource,returnHtml:!children}),parentProps={messages,resource,field,errors:msgErrors,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx(Fragment,{children:msgErrors})};Errors.propTypes=propTypes,Errors.displayName=displayName;export default Errors;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import ExternalFunctionContext,{callExternalFunction}from"../context/ExternalFunctionContext";import components from"../config/components";const propTypes=components.ExternalFunction.propTypes,displayName=components.ExternalFunction.displayName,ExternalFunction=({children,url})=>_jsx(ExternalFunctionContext.Provider,Object.assign({value:{url,callExternalFunction}},{children}));ExternalFunction.propTypes=propTypes,ExternalFunction.displayName=displayName;export default ExternalFunction;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import ExternalFunctionContext,{callExternalFunction}from"../context/ExternalFunctionContext";import components from"../config/components";const propTypes=components.ExternalFunction.propTypes,displayName=components.ExternalFunction.displayName,ExternalFunction=({children,url})=>_jsx(ExternalFunctionContext.Provider,{value:{url,callExternalFunction},children});ExternalFunction.propTypes=propTypes,ExternalFunction.displayName=displayName;export default ExternalFunction;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useRef,useContext}from"react";import validateFormFields from"../utils/validateFormFields";import{isEmpty}from"lodash";import GiftCardContext from"../context/GiftCardContext";import components from"../config/components";const propTypes=components.GiftCard.propTypes,defaultProps=components.GiftCard.defaultProps,displayName=components.GiftCard.displayName,GiftCard=props=>{const{children,onSubmit}=props,name="giftCardForm",ref=useRef(null),{addGiftCard,addGiftCardError}=useContext(GiftCardContext);return _jsx(Fragment,{children:_jsx("form",Object.assign({name,ref,onSubmit:e=>{e.preventDefault();const currentForm=ref.current,elements=currentForm==null?void 0:currentForm.elements,{errors,values}=validateFormFields(elements,["currencyCode","balanceCents"],"gift_cards");isEmpty(errors)?(addGiftCard(values),currentForm==null||currentForm.reset(),onSubmit&&onSubmit(values)):addGiftCardError(errors)}},{children}),name)})};GiftCard.propTypes=propTypes,GiftCard.defaultProps=defaultProps,GiftCard.displayName=displayName;export default GiftCard;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useRef,useContext}from"react";import validateFormFields from"../utils/validateFormFields";import{isEmpty}from"lodash";import GiftCardContext from"../context/GiftCardContext";import components from"../config/components";const propTypes=components.GiftCard.propTypes,defaultProps=components.GiftCard.defaultProps,displayName=components.GiftCard.displayName,GiftCard=props=>{const{children,onSubmit}=props,name="giftCardForm",ref=useRef(null),{addGiftCard,addGiftCardError}=useContext(GiftCardContext);return _jsx(Fragment,{children:_jsx("form",{name,ref,onSubmit:e=>{e.preventDefault();const currentForm=ref.current,elements=currentForm?.elements,{errors,values}=validateFormFields(elements,["currencyCode","balanceCents"],"gift_cards");isEmpty(errors)?(addGiftCard(values),currentForm?.reset(),onSubmit&&onSubmit(values)):addGiftCardError(errors)},children},name)})};GiftCard.propTypes=propTypes,GiftCard.defaultProps=defaultProps,GiftCard.displayName=displayName;export default GiftCard;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.GiftCardAmount.propTypes,displayName=components.GiftCardAmount.displayName,GiftCardAmount=props=>_jsx(BaseOrderPrice,Object.assign({base:"amount",type:"gift_card"},props));GiftCardAmount.propTypes=propTypes,GiftCardAmount.displayName=displayName;export default GiftCardAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.GiftCardAmount.propTypes,displayName=components.GiftCardAmount.displayName,GiftCardAmount=props=>_jsx(BaseOrderPrice,{base:"amount",type:"gift_card",...props});GiftCardAmount.propTypes=propTypes,GiftCardAmount.displayName=displayName;export default GiftCardAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useContext}from"react";import GiftCardContext from"../context/GiftCardContext";import CommerceLayerContext from"../context/CommerceLayerContext";import giftCardReducer,{giftCardInitialState,addGiftCardRecipient,addGiftCard,addGiftCardError,addGiftCardLoading}from"../reducers/GiftCardReducer";import OrderContext from"../context/OrderContext";import components from"../config/components";const propTypes=components.GiftCardContainer.propTypes,displayName=components.GiftCardContainer.displayName,GiftCardContainer=props=>{const{children}=props,[state,dispatch]=useReducer(giftCardReducer,giftCardInitialState),config=useContext(CommerceLayerContext),{getOrder,createOrder,order}=useContext(OrderContext),giftCardValue=Object.assign(Object.assign({},state),{addGiftCardRecipient:values=>addGiftCardRecipient(values,config,dispatch),addGiftCard:values=>addGiftCard(Object.assign({},values),{config,dispatch,getOrder,createOrder,order}),addGiftCardError:errors=>addGiftCardError(errors,dispatch),addGiftCardLoading:loading=>addGiftCardLoading(loading,dispatch)});return _jsx(GiftCardContext.Provider,Object.assign({value:giftCardValue},{children}))};GiftCardContainer.propTypes=propTypes,GiftCardContainer.displayName=displayName;export default GiftCardContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useContext}from"react";import GiftCardContext from"../context/GiftCardContext";import CommerceLayerContext from"../context/CommerceLayerContext";import giftCardReducer,{giftCardInitialState,addGiftCardRecipient,addGiftCard,addGiftCardError,addGiftCardLoading}from"../reducers/GiftCardReducer";import OrderContext from"../context/OrderContext";import components from"../config/components";const propTypes=components.GiftCardContainer.propTypes,displayName=components.GiftCardContainer.displayName,GiftCardContainer=props=>{const{children}=props,[state,dispatch]=useReducer(giftCardReducer,giftCardInitialState),config=useContext(CommerceLayerContext),{getOrder,createOrder,order}=useContext(OrderContext),giftCardValue={...state,addGiftCardRecipient:values=>addGiftCardRecipient(values,config,dispatch),addGiftCard:values=>addGiftCard({...values},{config,dispatch,getOrder,createOrder,order}),addGiftCardError:errors=>addGiftCardError(errors,dispatch),addGiftCardLoading:loading=>addGiftCardLoading(loading,dispatch)};return _jsx(GiftCardContext.Provider,{value:giftCardValue,children})};GiftCardContainer.propTypes=propTypes,GiftCardContainer.displayName=displayName;export default GiftCardContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseSelect from"./utils/BaseSelect";import currencyOptions from"../config/currency";import components from"../config/components";const propTypes=components.GiftCardCurrencySelector.propTypes,defaultProps=components.GiftCardCurrencySelector.defaultProps,displayName=components.GiftCardCurrencySelector.displayName,GiftCardCurrencySelector=props=>_jsx(BaseSelect,Object.assign({options:currencyOptions,name:"currencyCode"},props));GiftCardCurrencySelector.propTypes=propTypes,GiftCardCurrencySelector.defaultProps=defaultProps,GiftCardCurrencySelector.displayName=displayName;export default GiftCardCurrencySelector;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseSelect from"./utils/BaseSelect";import currencyOptions from"../config/currency";import components from"../config/components";const propTypes=components.GiftCardCurrencySelector.propTypes,defaultProps=components.GiftCardCurrencySelector.defaultProps,displayName=components.GiftCardCurrencySelector.displayName,GiftCardCurrencySelector=props=>_jsx(BaseSelect,{options:currencyOptions,name:"currencyCode",...props});GiftCardCurrencySelector.propTypes=propTypes,GiftCardCurrencySelector.defaultProps=defaultProps,GiftCardCurrencySelector.displayName=displayName;export default GiftCardCurrencySelector;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import BaseInput from"./utils/BaseInput";import components from"../config/components";const propTypes=components.GiftCardInput.propTypes,displayName=components.GiftCardInput.displayName,GiftCardInput=props=>{const{placeholder=""}=props,p=__rest(props,["placeholder"]);return _jsx(BaseInput,Object.assign({placeholder},p))};GiftCardInput.propTypes=propTypes,GiftCardInput.displayName=displayName;export default GiftCardInput;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseInput from"./utils/BaseInput";import components from"../config/components";const propTypes=components.GiftCardInput.propTypes,displayName=components.GiftCardInput.displayName,GiftCardInput=props=>{const{placeholder="",...p}=props;return _jsx(BaseInput,{placeholder,...p})};GiftCardInput.propTypes=propTypes,GiftCardInput.displayName=displayName;export default GiftCardInput;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import components from"../config/components";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import has from"lodash/has";import isEmpty from"lodash/isEmpty";const propTypes=components.GiftCardOrCouponCode.propTypes,displayName=components.GiftCardOrCouponCode.displayName,GiftCardOrCouponCode=_a=>{var{children,type}=_a,props=__rest(_a,["children","type"]);const{order}=useContext(OrderContext);let codeType=type&&`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),parentProps=Object.assign(Object.assign({},props),{code,hide,discountAmountCents:order==null?void 0:order.discount_amount_cents,discountAmountFloat:order==null?void 0:order.discount_amount_float,formattedDiscountAmount:order==null?void 0:order.formatted_discount_amount});return children?_jsx(Parent,Object.assign({},parentProps,{children})):hide?null:_jsx("span",Object.assign({},props,{children:code}))};GiftCardOrCouponCode.propTypes=propTypes,GiftCardOrCouponCode.displayName=displayName;export default GiftCardOrCouponCode;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import components from"../config/components";import Parent from"./utils/Parent";import OrderContext from"../context/OrderContext";import has from"lodash/has";import isEmpty from"lodash/isEmpty";const propTypes=components.GiftCardOrCouponCode.propTypes,displayName=components.GiftCardOrCouponCode.displayName,GiftCardOrCouponCode=({children,type,...props})=>{const{order}=useContext(OrderContext);let codeType=type&&`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),parentProps={...props,code,hide,discountAmountCents:order?.discount_amount_cents,discountAmountFloat:order?.discount_amount_float,formattedDiscountAmount:order?.formatted_discount_amount};return children?_jsx(Parent,{...parentProps,children}):hide?null:_jsx("span",{...props,children:code})};GiftCardOrCouponCode.propTypes=propTypes,GiftCardOrCouponCode.displayName=displayName;export default GiftCardOrCouponCode;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef,useState}from"react";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import components from"../config/components";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import{findIndex}from"lodash";const propTypes=components.GiftCardOrCouponForm.propTypes,GiftCardOrCouponForm=props=>{const{children,autoComplete="on",onSubmit}=props,p=__rest(props,["children","autoComplete","onSubmit"]),{validation,values,reset}=useRapidForm(),[codeType,setCodeType]=useState("gift_card_or_coupon_code"),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{var _a,_b,_c,_d;if(((_a=values[inputName])===null||_a===void 0?void 0:_a.value)===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors(err),onSubmit&&onSubmit({value:(_b=values[inputName])===null||_b===void 0?void 0:_b.value,success:!1})}((_c=values[inputName])===null||_c===void 0?void 0:_c.value)===""&&(setOrderErrors([]),onSubmit&&onSubmit({value:(_d=values[inputName])===null||_d===void 0?void 0:_d.value,success:!1}))},[values]),useEffect(()=>{(order==null?void 0:order.gift_card_code)&&!(order==null?void 0:order.coupon_code)&&setCodeType("coupon_code"),!(order==null?void 0:order.gift_card_code)&&(order==null?void 0:order.coupon_code)&&setCodeType("gift_card_code"),!(order==null?void 0:order.gift_card_code)&&!(order==null?void 0:order.coupon_code)&&setCodeType("gift_card_or_coupon_code")},[order]);const handleSubmit=async e=>{var _a;e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code){const{success}=await setGiftCardOrCouponCode({code,codeType}),value=(_a=values[inputName])===null||_a===void 0?void 0:_a.value;onSubmit&&onSubmit({success,value}),success&&reset(e)}};return(order==null?void 0:order.gift_card_code)&&(order==null?void 0:order.coupon_code)||isEmpty(order)?null:_jsx(CouponAndGiftCardFormContext.Provider,Object.assign({value:{validation,codeType}},{children:_jsx("form",Object.assign({ref,autoComplete,onSubmit:handleSubmit},p,{children}))}))};GiftCardOrCouponForm.propTypes=propTypes;export default GiftCardOrCouponForm;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useRapidForm}from"rapid-form";import{useContext,useEffect,useRef,useState}from"react";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import components from"../config/components";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import{findIndex}from"lodash";const propTypes=components.GiftCardOrCouponForm.propTypes,GiftCardOrCouponForm=props=>{const{children,autoComplete="on",onSubmit,...p}=props,{validation,values,reset}=useRapidForm(),[codeType,setCodeType]=useState("gift_card_or_coupon_code"),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{if(values[inputName]?.value===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors(err),onSubmit&&onSubmit({value:values[inputName]?.value,success:!1})}values[inputName]?.value===""&&(setOrderErrors([]),onSubmit&&onSubmit({value:values[inputName]?.value,success:!1}))},[values]),useEffect(()=>{order?.gift_card_code&&!order?.coupon_code&&setCodeType("coupon_code"),!order?.gift_card_code&&order?.coupon_code&&setCodeType("gift_card_code"),!order?.gift_card_code&&!order?.coupon_code&&setCodeType("gift_card_or_coupon_code")},[order]);const handleSubmit=async e=>{e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code){const{success}=await setGiftCardOrCouponCode({code,codeType}),value=values[inputName]?.value;onSubmit&&onSubmit({success,value}),success&&reset(e)}};return order?.gift_card_code&&order?.coupon_code||isEmpty(order)?null:_jsx(CouponAndGiftCardFormContext.Provider,{value:{validation,codeType},children:_jsx("form",{ref,autoComplete,onSubmit:handleSubmit,...p,children})})};GiftCardOrCouponForm.propTypes=propTypes;export default GiftCardOrCouponForm;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import components from"../config/components";import BaseInput from"./utils/BaseInput";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";const propTypes=components.GiftCardOrCouponInput.propTypes,displayName=components.GiftCardOrCouponInput.displayName,GiftCardOrCouponInput=props=>{const{placeholder="",required,value,placeholderTranslation}=props,p=__rest(props,["placeholder","required","value","placeholderTranslation"]),{validation,codeType}=useContext(CouponAndGiftCardFormContext);let placeholderLabel=placeholder;return placeholderTranslation&&codeType&&(placeholderLabel=placeholderTranslation(codeType)),_jsx(BaseInput,Object.assign({type:"text",name:"gift_card_or_coupon_code",ref:validation,required:required!==void 0?required:!0,placeholder:placeholderLabel,defaultValue:value},p))};GiftCardOrCouponInput.propTypes=propTypes,GiftCardOrCouponInput.displayName=displayName;export default GiftCardOrCouponInput;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import components from"../config/components";import BaseInput from"./utils/BaseInput";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";const propTypes=components.GiftCardOrCouponInput.propTypes,displayName=components.GiftCardOrCouponInput.displayName,GiftCardOrCouponInput=props=>{const{placeholder="",required,value,placeholderTranslation,...p}=props,{validation,codeType}=useContext(CouponAndGiftCardFormContext);let placeholderLabel=placeholder;return placeholderTranslation&&codeType&&(placeholderLabel=placeholderTranslation(codeType)),_jsx(BaseInput,{type:"text",name:"gift_card_or_coupon_code",ref:validation,required:required!==void 0?required:!0,placeholder:placeholderLabel,defaultValue:value,...p})};GiftCardOrCouponInput.propTypes=propTypes,GiftCardOrCouponInput.displayName=displayName;export default GiftCardOrCouponInput;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import OrderContext from"../context/OrderContext";import{has,isEmpty}from"lodash";const propTypes=components.GiftCardOrCouponRemoveButton.propTypes,displayName=components.GiftCardOrCouponRemoveButton.displayName,GiftCardOrCouponRemoveButton=props=>{const{children,label="Remove",onClick,type}=props,p=__rest(props,["children","label","onClick","type"]),{order,removeGiftCardOrCouponCode}=useContext(OrderContext);let codeType=`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=async()=>{const response=removeGiftCardOrCouponCode&&await removeGiftCardOrCouponCode({codeType});onClick&&onClick(response)},parentProps=Object.assign(Object.assign({},p),{label,handleClick,codeType});return children?_jsx(Parent,Object.assign({},parentProps,{children})):hide?null:_jsx("button",Object.assign({type:"button",onClick:handleClick},p,{children:label}))};GiftCardOrCouponRemoveButton.propTypes=propTypes,GiftCardOrCouponRemoveButton.displayName=displayName;export default GiftCardOrCouponRemoveButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import OrderContext from"../context/OrderContext";import{has,isEmpty}from"lodash";const propTypes=components.GiftCardOrCouponRemoveButton.propTypes,displayName=components.GiftCardOrCouponRemoveButton.displayName,GiftCardOrCouponRemoveButton=props=>{const{children,label="Remove",onClick,type,...p}=props,{order,removeGiftCardOrCouponCode}=useContext(OrderContext);let codeType=`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=async()=>{const response=removeGiftCardOrCouponCode&&await removeGiftCardOrCouponCode({codeType});onClick&&onClick(response)},parentProps={...p,label,handleClick,codeType};return children?_jsx(Parent,{...parentProps,children}):hide?null:_jsx("button",{type:"button",onClick:handleClick,...p,children:label})};GiftCardOrCouponRemoveButton.propTypes=propTypes,GiftCardOrCouponRemoveButton.displayName=displayName;export default GiftCardOrCouponRemoveButton;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.GiftCardOrCouponSubmit.propTypes,displayName=components.GiftCardOrCouponSubmit.displayName,GiftCardOrCouponSubmit=props=>{const{children,label="Submit"}=props,p=__rest(props,["children","label"]),parentProps=Object.assign(Object.assign({},p),{label});return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({type:"submit"},p,{children:label}))};GiftCardOrCouponSubmit.propTypes=propTypes,GiftCardOrCouponSubmit.displayName=displayName;export default GiftCardOrCouponSubmit;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.GiftCardOrCouponSubmit.propTypes,displayName=components.GiftCardOrCouponSubmit.displayName,GiftCardOrCouponSubmit=props=>{const{children,label="Submit",...p}=props,parentProps={...p,label};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"submit",...p,children:label})};GiftCardOrCouponSubmit.propTypes=propTypes,GiftCardOrCouponSubmit.displayName=displayName;export default GiftCardOrCouponSubmit;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useEffect}from"react";import ItemContext,{initialItemContext}from"../context/ItemContext";import itemReducer,{itemInitialState,setItemState}from"../reducers/ItemReducer";import components from"../config/components";const propTypes=components.ItemContainer.propTypes,displayName=components.ItemContainer.displayName,ItemContainer=props=>{const{children,skuCode,lineItem}=props,[state,dispatch]=useReducer(itemReducer,itemInitialState);useEffect(()=>{const code=skuCode;code&&setItemState(code,{type:"setSkuCode",key:"skuCode"},dispatch),lineItem&&setItemState(lineItem,{type:"setCustomLineItem",key:"lineItem"},dispatch)},[]);const setItems=items=>setItemState(items,{type:"setItems",key:"items"},dispatch),setItem=item=>setItemState(item,{type:"setItem",key:"item"},dispatch),setQuantity=item=>setItemState(item,{type:"setQuantity",key:"quantity"},dispatch),setOption=item=>setItemState(item,{type:"setOption",key:"option"},dispatch),setPrices=item=>setItemState(item,{type:"setPrices",key:"prices"},dispatch),setCustomLineItems=item=>setItemState(item,{type:"setCustomLineItems",key:"lineItems"},dispatch),setSkuCode=code=>setItemState(code,{type:"setSkuCode",key:"skuCode"},dispatch),itemValue=Object.assign(Object.assign(Object.assign({},initialItemContext),state),{setItems,setItem,setQuantity,setOption,setPrices,setCustomLineItems,setSkuCode});return _jsx(ItemContext.Provider,Object.assign({value:itemValue},{children}))};ItemContainer.propTypes=propTypes,ItemContainer.displayName=displayName;export default ItemContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useEffect}from"react";import ItemContext,{initialItemContext}from"../context/ItemContext";import itemReducer,{itemInitialState,setItemState}from"../reducers/ItemReducer";import components from"../config/components";const propTypes=components.ItemContainer.propTypes,displayName=components.ItemContainer.displayName,ItemContainer=props=>{const{children,skuCode,lineItem}=props,[state,dispatch]=useReducer(itemReducer,itemInitialState);useEffect(()=>{const code=skuCode;code&&setItemState(code,{type:"setSkuCode",key:"skuCode"},dispatch),lineItem&&setItemState(lineItem,{type:"setCustomLineItem",key:"lineItem"},dispatch)},[]);const itemValue={...initialItemContext,...state,setItems:items=>setItemState(items,{type:"setItems",key:"items"},dispatch),setItem:item=>setItemState(item,{type:"setItem",key:"item"},dispatch),setQuantity:item=>setItemState(item,{type:"setQuantity",key:"quantity"},dispatch),setOption:item=>setItemState(item,{type:"setOption",key:"option"},dispatch),setPrices:item=>setItemState(item,{type:"setPrices",key:"prices"},dispatch),setCustomLineItems:item=>setItemState(item,{type:"setCustomLineItems",key:"lineItems"},dispatch),setSkuCode:code=>setItemState(code,{type:"setSkuCode",key:"skuCode"},dispatch)};return _jsx(ItemContext.Provider,{value:itemValue,children})};ItemContainer.propTypes=propTypes,ItemContainer.displayName=displayName;export default ItemContainer;