@commercelayer/react-components 3.14.1 → 3.15.0-beta.10

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 +1 -0
  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 +3 -2
  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,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import useExternalScript from"../utils/hooks/useExternalScript";import PlaceOrderContext from"../context/PlaceOrderContext";function typeOfLine(lineItemType){switch(lineItemType){case"payment_methods":default:return null;case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical"}}function klarnaOrderLines(lineItems){return lineItems?lineItems.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{name:item.name,quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}export default function KlarnaPayment(_a){var _b,_c,_d,_e,_f,_g,_h,_j,_k,_l,_m,_o,_p,_q,_r,_s,_t,_u,{clientToken,placeOrderCallback,locale="EN"}=_a,p=__rest(_a,["clientToken","placeOrderCallback","locale"]);const ref=useRef(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{setPlaceOrder}=useContext(PlaceOrderContext),loaded=useExternalScript("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=useState(),{containerClassName}=p,divProps=__rest(p,["containerClassName"]);useEffect(()=>{loaded&&(window==null?void 0:window.Klarna)!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),useEffect(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=()=>handleClick(klarna),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=async kl=>{var _a2,_b2,_c2,_d2,_e2,_f2,_g2,_h2,_j2,_k2,_l2,_m2,_o2,_p2,_q2,_r2;const[first]=(paymentSource==null?void 0:paymentSource.payment_methods)||void 0,payment_method_category=first==null?void 0:first.identifier,billing_address={given_name:(_a2=order==null?void 0:order.billing_address)===null||_a2===void 0?void 0:_a2.first_name,family_name:(_b2=order==null?void 0:order.billing_address)===null||_b2===void 0?void 0:_b2.last_name,email:order==null?void 0:order.customer_email,street_address:(_c2=order==null?void 0:order.billing_address)===null||_c2===void 0?void 0:_c2.line_1,street_address2:null,organization_name:null,postal_code:(_d2=order==null?void 0:order.billing_address)===null||_d2===void 0?void 0:_d2.zip_code,city:(_e2=order==null?void 0:order.billing_address)===null||_e2===void 0?void 0:_e2.city,region:(_f2=order==null?void 0:order.billing_address)===null||_f2===void 0?void 0:_f2.state_code,phone:(_g2=order==null?void 0:order.billing_address)===null||_g2===void 0?void 0:_g2.phone,country:(_h2=order==null?void 0:order.billing_address)===null||_h2===void 0?void 0:_h2.country_code},shipping_address={given_name:(_j2=order==null?void 0:order.shipping_address)===null||_j2===void 0?void 0:_j2.first_name,family_name:(_k2=order==null?void 0:order.shipping_address)===null||_k2===void 0?void 0:_k2.last_name,email:order==null?void 0:order.customer_email,street_address:(_l2=order==null?void 0:order.shipping_address)===null||_l2===void 0?void 0:_l2.line_1,street_address2:null,postal_code:(_m2=order==null?void 0:order.shipping_address)===null||_m2===void 0?void 0:_m2.zip_code,organization_name:null,city:(_o2=order==null?void 0:order.shipping_address)===null||_o2===void 0?void 0:_o2.city,region:(_p2=order==null?void 0:order.shipping_address)===null||_p2===void 0?void 0:_p2.state_code,phone:(_q2=order==null?void 0:order.shipping_address)===null||_q2===void 0?void 0:_q2.phone,country:(_r2=order==null?void 0:order.shipping_address)===null||_r2===void 0?void 0:_r2.country_code},klarnaData={merchant_data:order==null?void 0:order.id,purchase_country:order==null?void 0:order.country_code,purchase_currency:order==null?void 0:order.currency_code,locale,shipping_address,billing_address,order_amount:order==null?void 0:order.total_amount_cents,order_lines:klarnaOrderLines(order==null?void 0:order.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category},{billing_address,shipping_address},async function({show_form}){if(show_form)try{await kl.Payments.authorize({payment_method_category},klarnaData,async function(res){if(res.approved&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}}),{placed}=setPlaceOrder&&ps&&await setPlaceOrder({paymentSource:ps})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})}catch(e){console.error("Load Klarna libray",e)}};if(klarna&&clientToken){const[first]=(paymentSource==null?void 0:paymentSource.payment_methods)||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first==null?void 0:first.identifier},{billing_address:{given_name:(_b=order==null?void 0:order.billing_address)===null||_b===void 0?void 0:_b.first_name,family_name:(_c=order==null?void 0:order.billing_address)===null||_c===void 0?void 0:_c.last_name,email:order==null?void 0:order.customer_email,street_address:(_d=order==null?void 0:order.billing_address)===null||_d===void 0?void 0:_d.line_1,street_address2:(_e=order==null?void 0:order.billing_address)===null||_e===void 0?void 0:_e.line_2,postal_code:(_f=order==null?void 0:order.billing_address)===null||_f===void 0?void 0:_f.zip_code,city:(_g=order==null?void 0:order.billing_address)===null||_g===void 0?void 0:_g.city,region:(_h=order==null?void 0:order.billing_address)===null||_h===void 0?void 0:_h.state_code,phone:(_j=order==null?void 0:order.billing_address)===null||_j===void 0?void 0:_j.phone,country:(_k=order==null?void 0:order.billing_address)===null||_k===void 0?void 0:_k.country_code},shipping_address:{given_name:(_l=order==null?void 0:order.shipping_address)===null||_l===void 0?void 0:_l.first_name,family_name:(_m=order==null?void 0:order.shipping_address)===null||_m===void 0?void 0:_m.last_name,street_address:(_o=order==null?void 0:order.shipping_address)===null||_o===void 0?void 0:_o.line_1,street_address2:(_p=order==null?void 0:order.shipping_address)===null||_p===void 0?void 0:_p.line_2,postal_code:(_q=order==null?void 0:order.shipping_address)===null||_q===void 0?void 0:_q.zip_code,city:(_r=order==null?void 0:order.shipping_address)===null||_r===void 0?void 0:_r.city,region:(_s=order==null?void 0:order.shipping_address)===null||_s===void 0?void 0:_s.state_code,phone:(_t=order==null?void 0:order.shipping_address)===null||_t===void 0?void 0:_t.phone,country:(_u=order==null?void 0:order.shipping_address)===null||_u===void 0?void 0:_u.country_code}})}return _jsx("form",Object.assign({ref},{children:_jsx("div",Object.assign({className:containerClassName},divProps,{children:_jsx("div",{id:"klarna-payments-container"})}))}))}
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import useExternalScript from"../utils/hooks/useExternalScript";import PlaceOrderContext from"../context/PlaceOrderContext";function typeOfLine(lineItemType){switch(lineItemType){case"payment_methods":default:return null;case"percentage_discount_promotions":return"discount";case"shipments":return"shipping_fee";case"skus":return"physical"}}function klarnaOrderLines(lineItems){return lineItems?lineItems.map(item=>{const type=item.item_type?typeOfLine(item.item_type):null;return{name:item.name,quantity:item.quantity,total_amount:item.total_amount_cents,unit_price:item.unit_amount_cents,type}}):[]}export default function KlarnaPayment({clientToken,placeOrderCallback,locale="EN",...p}){const ref=useRef(null),{paymentSource,currentPaymentMethodType,setPaymentRef,setPaymentSource,setPaymentMethodErrors}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{setPlaceOrder}=useContext(PlaceOrderContext),loaded=useExternalScript("https://x.klarnacdn.net/kp/lib/v1/api.js"),[klarna,setKlarna]=useState(),{containerClassName,...divProps}=p;useEffect(()=>{loaded&&window?.Klarna!==void 0&&setKlarna(window.Klarna)},[loaded,window.Klarna]),useEffect(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&loaded&&klarna&&(ref.current.onsubmit=()=>handleClick(klarna),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType,loaded,klarna]);const handleClick=async kl=>{const[first]=paymentSource?.payment_methods||void 0,payment_method_category=first?.identifier,billing_address={given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:null,organization_name:null,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shipping_address={given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,email:order?.customer_email,street_address:order?.shipping_address?.line_1,street_address2:null,postal_code:order?.shipping_address?.zip_code,organization_name:null,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code},klarnaData={merchant_data:order?.id,purchase_country:order?.country_code,purchase_currency:order?.currency_code,locale,shipping_address,billing_address,order_amount:order?.total_amount_cents,order_lines:klarnaOrderLines(order?.line_items)};try{kl.Payments.load({container:"#klarna-payments-container",payment_method_category},{billing_address,shipping_address},async function({show_form}){if(show_form)try{await kl.Payments.authorize({payment_method_category},klarnaData,async function(res){if(res.approved&&paymentSource&&currentPaymentMethodType){const ps=await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{auth_token:res.authorization_token}}),{placed}=setPlaceOrder&&ps&&await setPlaceOrder({paymentSource:ps})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}})}catch(e){console.error("e",e),setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:"Authorization error"}])}})}catch(e){console.error("Load Klarna libray",e)}};if(klarna&&clientToken){const[first]=paymentSource?.payment_methods||void 0;klarna.Payments.init({client_token:clientToken}),klarna.Payments.load({container:"#klarna-payments-container",payment_method_category:first?.identifier},{billing_address:{given_name:order?.billing_address?.first_name,family_name:order?.billing_address?.last_name,email:order?.customer_email,street_address:order?.billing_address?.line_1,street_address2:order?.billing_address?.line_2,postal_code:order?.billing_address?.zip_code,city:order?.billing_address?.city,region:order?.billing_address?.state_code,phone:order?.billing_address?.phone,country:order?.billing_address?.country_code},shipping_address:{given_name:order?.shipping_address?.first_name,family_name:order?.shipping_address?.last_name,street_address:order?.shipping_address?.line_1,street_address2:order?.shipping_address?.line_2,postal_code:order?.shipping_address?.zip_code,city:order?.shipping_address?.city,region:order?.shipping_address?.state_code,phone:order?.shipping_address?.phone,country:order?.shipping_address?.country_code}})}return _jsx("form",{ref,children:_jsx("div",{className:containerClassName,...divProps,children:_jsx("div",{id:"klarna-payments-container"})})})}
@@ -1 +1 @@
1
- import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemContext from"../context/LineItemContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";const propTypes=components.LineItem.propTypes,displayName=components.LineItem.displayName,LineItem=props=>{const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),items=shipmentLineItems&&(shipmentLineItems==null?void 0:shipmentLineItems.length)>0?shipmentLineItems:lineItems,components2=items&&items.filter(l=>l.item_type===type).map((lineItem,k,check)=>{var _a;if(lineItem.item_type==="bundles"&&k>0&&((_a=check[k-1])===null||_a===void 0?void 0:_a.bundle_code)===lineItem.bundle_code||lineItem.item_type==="gift_cards"&&(lineItem==null?void 0:lineItem.total_amount_cents)&&(lineItem==null?void 0:lineItem.total_amount_cents)<=0)return null;const lineProps={lineItem};return _jsx(LineItemChildrenContext.Provider,Object.assign({value:lineProps},{children}),k)});return _jsx(_Fragment,{children:components2})};LineItem.propTypes=propTypes,LineItem.displayName=displayName;export default LineItem;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemContext from"../context/LineItemContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";const propTypes=components.LineItem.propTypes,displayName=components.LineItem.displayName,LineItem=props=>{const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),items=shipmentLineItems&&shipmentLineItems?.length>0?shipmentLineItems:lineItems,components2=items&&items.filter(l=>l.item_type===type).map((lineItem,k,check)=>{if(lineItem.item_type==="bundles"&&k>0&&check[k-1]?.bundle_code===lineItem.bundle_code||lineItem.item_type==="gift_cards"&&lineItem?.total_amount_cents&&lineItem?.total_amount_cents<=0)return null;const lineProps={lineItem};return _jsx(LineItemChildrenContext.Provider,{value:lineProps,children},k)});return _jsx(_Fragment,{children:components2})};LineItem.propTypes=propTypes,LineItem.displayName=displayName;export default LineItem;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import LineItemChildrenContext from"../context/LineItemChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemAmount.propTypes,defaultProps=components.LineItemAmount.defaultProps,displayName=components.LineItemAmount.displayName,LineItemAmount=props=>{const{format="formatted",type="total"}=props,p=__rest(props,["format","type"]),{lineItem}=useContext(LineItemChildrenContext),[price,setPrice]=useState("");useEffect(()=>{if(lineItem){const p2=getAmount({base:"amount",type,format,obj:lineItem});setPrice(p2)}return()=>{setPrice("")}},[lineItem]);const parentProps=Object.assign({price},p);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("span",Object.assign({},p,{children:price}))};LineItemAmount.propTypes=propTypes,LineItemAmount.defaultProps=defaultProps,LineItemAmount.displayName=displayName;export default LineItemAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import LineItemChildrenContext from"../context/LineItemChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemAmount.propTypes,defaultProps=components.LineItemAmount.defaultProps,displayName=components.LineItemAmount.displayName,LineItemAmount=props=>{const{format="formatted",type="total",...p}=props,{lineItem}=useContext(LineItemChildrenContext),[price,setPrice]=useState("");useEffect(()=>{if(lineItem){const p2=getAmount({base:"amount",type,format,obj:lineItem});setPrice(p2)}return()=>{setPrice("")}},[lineItem]);const parentProps={price,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:price})};LineItemAmount.propTypes=propTypes,LineItemAmount.defaultProps=defaultProps,LineItemAmount.displayName=displayName;export default LineItemAmount;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemCode.propTypes,displayName=components.LineItemCode.displayName,LineItemCode=_a=>{var{type="sku_code",children}=_a,p=__rest(_a,["type","children"]);const{lineItem}=useContext(LineItemChildrenContext),labelName=lineItem==null?void 0:lineItem[type],parentProps=Object.assign({lineItem,skuCode:labelName},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("p",Object.assign({},p,{children:labelName}))};LineItemCode.propTypes=propTypes,LineItemCode.displayName=displayName;export default LineItemCode;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemCode.propTypes,displayName=components.LineItemCode.displayName,LineItemCode=({type="sku_code",children,...p})=>{const{lineItem}=useContext(LineItemChildrenContext),labelName=lineItem?.[type],parentProps={lineItem,skuCode:labelName,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:labelName})};LineItemCode.propTypes=propTypes,LineItemCode.displayName=displayName;export default LineItemCode;
@@ -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 LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import{defaultGiftCardImgUrl,defaultImgUrl}from"../utils/placeholderImages";const propTypes=components.LineItemImage.propTypes,displayName=components.LineItemImage.displayName,LineItemImage=props=>{const{placeholder,children}=props,p=__rest(props,["placeholder","children"]),{lineItem}=useContext(LineItemChildrenContext),itemType=lineItem==null?void 0:lineItem.item_type;let src=lineItem==null?void 0:lineItem.image_url;src||((placeholder==null?void 0:placeholder[itemType])?src=placeholder==null?void 0:placeholder[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps=Object.assign({lineItem,src,placeholder},p);return children?_jsx(Parent,Object.assign({},parenProps,{children})):src?_jsx("img",Object.assign({alt:"",src},p)):null};LineItemImage.propTypes=propTypes,LineItemImage.displayName=displayName;export default LineItemImage;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import{defaultGiftCardImgUrl,defaultImgUrl}from"../utils/placeholderImages";const propTypes=components.LineItemImage.propTypes,displayName=components.LineItemImage.displayName,LineItemImage=props=>{const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),itemType=lineItem?.item_type;let src=lineItem?.image_url;src||(placeholder?.[itemType]?src=placeholder?.[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps={lineItem,src,placeholder,...p};return children?_jsx(Parent,{...parenProps,children}):src?_jsx("img",{alt:"",src,...p}):null};LineItemImage.propTypes=propTypes,LineItemImage.displayName=displayName;export default LineItemImage;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemName.propTypes,displayName=components.LineItemName.displayName,LineItemName=props=>{const{lineItem}=useContext(LineItemChildrenContext),label=lineItem==null?void 0:lineItem.name,parentProps=Object.assign({label,lineItem},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("p",Object.assign({},props,{children:label}))};LineItemName.propTypes=propTypes,LineItemName.displayName=displayName;export default LineItemName;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemName.propTypes,displayName=components.LineItemName.displayName,LineItemName=props=>{const{lineItem}=useContext(LineItemChildrenContext),label=lineItem?.name,parentProps={label,lineItem,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("p",{...props,children:label})};LineItemName.propTypes=propTypes,LineItemName.displayName=displayName;export default LineItemName;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import LineItemOptionChildrenContext from"../context/LineItemOptionChildrenContext";import get from"lodash/get";import has from"lodash/has";import map from"lodash/map";import Parent from"./utils/Parent";import components from"../config/components";import isJSON from"../utils/isJSON";const propTypes=components.LineItemOption.propTypes,displayName=components.LineItemOption.displayName,LineItemOption=props=>{const{name,children,valueClassName,id,key,tagElement="li",tagContainer="ul"}=props,p=__rest(props,["name","children","valueClassName","id","key","tagElement","tagContainer"]),{lineItemOption,showAll}=useContext(LineItemOptionChildrenContext),parentProps=Object.assign(Object.assign({},props),{lineItemOption}),TagElement=tagElement,TagContainer=tagContainer,components2=showAll&&isJSON(JSON.stringify(lineItemOption==null?void 0:lineItemOption.options))?map(lineItemOption==null?void 0:lineItemOption.options,(value,key2)=>_jsxs(TagElement,Object.assign({},p,{children:[`${key2}:`,_jsx("span",Object.assign({className:valueClassName},{children:`${value}`}))]}),key2)):has(lineItemOption,`options.${name}`)?_jsxs(TagElement,Object.assign({},p,{children:[`${name}:`,_jsx("span",Object.assign({className:valueClassName},p,{children:`${get(lineItemOption,`options.${name}`)}`}))]}),key):null;return children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx(TagContainer,{children:components2})};LineItemOption.propTypes=propTypes,LineItemOption.displayName=displayName;export default LineItemOption;
1
+ import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import LineItemOptionChildrenContext from"../context/LineItemOptionChildrenContext";import get from"lodash/get";import has from"lodash/has";import map from"lodash/map";import Parent from"./utils/Parent";import components from"../config/components";import isJSON from"../utils/isJSON";const propTypes=components.LineItemOption.propTypes,displayName=components.LineItemOption.displayName,LineItemOption=props=>{const{name,children,valueClassName,id,key,tagElement="li",tagContainer="ul",...p}=props,{lineItemOption,showAll}=useContext(LineItemOptionChildrenContext),parentProps={...props,lineItemOption},TagElement=tagElement,TagContainer=tagContainer,components2=showAll&&isJSON(JSON.stringify(lineItemOption?.options))?map(lineItemOption?.options,(value,key2)=>_jsxs(TagElement,{...p,children:[`${key2}:`,_jsx("span",{className:valueClassName,children:`${value}`})]},key2)):has(lineItemOption,`options.${name}`)?_jsxs(TagElement,{...p,children:[`${name}:`,_jsx("span",{className:valueClassName,...p,children:`${get(lineItemOption,`options.${name}`)}`})]},key):null;return children?_jsx(Parent,{...parentProps,children:props.children}):_jsx(TagContainer,{children:components2})};LineItemOption.propTypes=propTypes,LineItemOption.displayName=displayName;export default LineItemOption;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import LineItemOptionChildrenContext from"../context/LineItemOptionChildrenContext";import{isEmpty}from"lodash";import components from"../config/components";const displayName=components.LineItemOptions.displayName,LineItemOptions=props=>{const{skuOptionId,title,children,showName=!0,showAll,className,titleTagElement="h6",titleClassName}=props,p=__rest(props,["skuOptionId","title","children","showName","showAll","className","titleTagElement","titleClassName"]),{lineItem}=useContext(LineItemChildrenContext),lineItemOptions=isEmpty(lineItem)?[]:(lineItem==null?void 0:lineItem.line_item_options)||[],TitleTagElement=titleTagElement,options=lineItemOptions.filter(o=>showAll?!0:o.skuOption().id===skuOptionId).map((o,k)=>{const showTitle=showName?_jsx(TitleTagElement,Object.assign({className:titleClassName},{children:title||o.name})):null,valueProps={lineItemOption:o,showAll};return _jsxs("div",Object.assign({className},p,{children:[showTitle,_jsx(LineItemOptionChildrenContext.Provider,Object.assign({value:valueProps},{children}))]}),k)});return _jsx(_Fragment,{children:options})};LineItemOptions.displayName=displayName;export default LineItemOptions;
1
+ import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import LineItemOptionChildrenContext from"../context/LineItemOptionChildrenContext";import{isEmpty}from"lodash";import components from"../config/components";const displayName=components.LineItemOptions.displayName,LineItemOptions=props=>{const{skuOptionId,title,children,showName=!0,showAll,className,titleTagElement="h6",titleClassName,...p}=props,{lineItem}=useContext(LineItemChildrenContext),lineItemOptions=isEmpty(lineItem)?[]:lineItem?.line_item_options||[],TitleTagElement=titleTagElement,options=lineItemOptions.filter(o=>showAll?!0:o.skuOption().id===skuOptionId).map((o,k)=>{const showTitle=showName?_jsx(TitleTagElement,{className:titleClassName,children:title||o.name}):null,valueProps={lineItemOption:o,showAll};return _jsxs("div",{className,...p,children:[showTitle,_jsx(LineItemOptionChildrenContext.Provider,{value:valueProps,children})]},k)});return _jsx(_Fragment,{children:options})};LineItemOptions.displayName=displayName;export default LineItemOptions;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import LineItemContext from"../context/LineItemContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemQuantity.propTypes,defaultProps=components.LineItemQuantity.defaultProps,displayName=components.LineItemQuantity.displayName,LineItemQuantity=props=>{const{max=50,readonly=!1}=props,p=__rest(props,["max","readonly"]),{lineItem}=useContext(LineItemChildrenContext),{updateLineItem}=useContext(LineItemContext),options=[];for(let i=1;i<=max;i++)options.push(_jsx("option",Object.assign({value:`${i}`},{children:i}),i));const handleChange=e=>{const quantity2=Number(e.target.value);updateLineItem&&lineItem&&updateLineItem(lineItem.id,quantity2)},quantity=lineItem==null?void 0:lineItem.quantity,parentProps=Object.assign({handleChange,quantity},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):readonly?_jsx("span",Object.assign({},p,{children:quantity})):_jsx("select",Object.assign({title:lineItem==null?void 0:lineItem.name,value:quantity,onChange:handleChange},p,{children:options}))};LineItemQuantity.propTypes=propTypes,LineItemQuantity.defaultProps=defaultProps,LineItemQuantity.displayName=displayName;export default LineItemQuantity;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import LineItemContext from"../context/LineItemContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemQuantity.propTypes,defaultProps=components.LineItemQuantity.defaultProps,displayName=components.LineItemQuantity.displayName,LineItemQuantity=props=>{const{max=50,readonly=!1,...p}=props,{lineItem}=useContext(LineItemChildrenContext),{updateLineItem}=useContext(LineItemContext),options=[];for(let i=1;i<=max;i++)options.push(_jsx("option",{value:`${i}`,children:i},i));const handleChange=e=>{const quantity2=Number(e.target.value);updateLineItem&&lineItem&&updateLineItem(lineItem.id,quantity2)},quantity=lineItem?.quantity,parentProps={handleChange,quantity,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):readonly?_jsx("span",{...p,children:quantity}):_jsx("select",{title:lineItem?.name,value:quantity,onChange:handleChange,...p,children:options})};LineItemQuantity.propTypes=propTypes,LineItemQuantity.defaultProps=defaultProps,LineItemQuantity.displayName=displayName;export default LineItemQuantity;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import LineItemContext from"../context/LineItemContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemRemoveLink.propTypes,defaultProps=components.LineItemRemoveLink.defaultProps,displayName=components.LineItemRemoveLink.displayName,LineItemRemoveLink=props=>{const{label="Remove"}=props,{lineItem}=useContext(LineItemChildrenContext),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem&&lineItem&&deleteLineItem(lineItem.id)},parentProps=Object.assign({handleRemove},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("a",Object.assign({},props,{href:"#",onClick:handleRemove},{children:label}))};LineItemRemoveLink.propTypes=propTypes,LineItemRemoveLink.defaultProps=defaultProps,LineItemRemoveLink.displayName=displayName;export default LineItemRemoveLink;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../context/LineItemChildrenContext";import LineItemContext from"../context/LineItemContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.LineItemRemoveLink.propTypes,defaultProps=components.LineItemRemoveLink.defaultProps,displayName=components.LineItemRemoveLink.displayName,LineItemRemoveLink=props=>{const{label="Remove"}=props,{lineItem}=useContext(LineItemChildrenContext),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem&&lineItem&&deleteLineItem(lineItem.id)},parentProps={handleRemove,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("a",{...props,href:"#",onClick:handleRemove,children:label})};LineItemRemoveLink.propTypes=propTypes,LineItemRemoveLink.defaultProps=defaultProps,LineItemRemoveLink.displayName=displayName;export default LineItemRemoveLink;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext}from"react";import lineItemReducer,{lineItemInitialState,updateLineItem,deleteLineItem}from"../reducers/LineItemReducer";import OrderContext from"../context/OrderContext";import LineItemContext from"../context/LineItemContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";const propTypes=components.LineItemsContainer.propTypes,defaultProps=components.LineItemsContainer.defaultProps,displayName=components.LineItemsContainer.displayName,LineItemsContainer=props=>{const{children,loader="Loading..."}=props,{order,addResourceToInclude,include,orderId,getOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(lineItemReducer,lineItemInitialState);useEffect(()=>{(include==null?void 0:include.includes("line_items.line_item_options.sku_option"))?(includeLoaded==null?void 0:includeLoaded["line_items.line_item_options.sku_option"])||addResourceToInclude({newResourceLoaded:{"line_items.line_item_options.sku_option":!0}}):addResourceToInclude({newResource:["line_items.line_item_options.sku_option"]}),(include==null?void 0:include.includes("line_items.item"))?(includeLoaded==null?void 0:includeLoaded["line_items.item"])||addResourceToInclude({newResourceLoaded:{"line_items.item":!0}}):addResourceToInclude({newResource:["line_items.item"]})},[include,includeLoaded]),useEffect(()=>{(order==null?void 0:order.line_items)&&dispatch({type:"setLineItems",payload:{lineItems:order.line_items}})},[order==null?void 0:order.line_items]);const lineItemValue=Object.assign(Object.assign({},state),{loader,updateLineItem:(lineItemId,quantity=1)=>updateLineItem({lineItemId,quantity,dispatch,config,getOrder,orderId,errors:state.errors}),deleteLineItem:lineItemId=>deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})});return _jsx(LineItemContext.Provider,Object.assign({value:lineItemValue},{children:state.loading?loader:children}))};LineItemsContainer.propTypes=propTypes,LineItemsContainer.defaultProps=defaultProps,LineItemsContainer.displayName=displayName;export default LineItemsContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext}from"react";import lineItemReducer,{lineItemInitialState,updateLineItem,deleteLineItem}from"../reducers/LineItemReducer";import OrderContext from"../context/OrderContext";import LineItemContext from"../context/LineItemContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";const propTypes=components.LineItemsContainer.propTypes,defaultProps=components.LineItemsContainer.defaultProps,displayName=components.LineItemsContainer.displayName,LineItemsContainer=props=>{const{children,loader="Loading..."}=props,{order,addResourceToInclude,include,orderId,getOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext),[state,dispatch]=useReducer(lineItemReducer,lineItemInitialState);useEffect(()=>{include?.includes("line_items.line_item_options.sku_option")?includeLoaded?.["line_items.line_item_options.sku_option"]||addResourceToInclude({newResourceLoaded:{"line_items.line_item_options.sku_option":!0}}):addResourceToInclude({newResource:["line_items.line_item_options.sku_option"]}),include?.includes("line_items.item")?includeLoaded?.["line_items.item"]||addResourceToInclude({newResourceLoaded:{"line_items.item":!0}}):addResourceToInclude({newResource:["line_items.item"]})},[include,includeLoaded]),useEffect(()=>{order?.line_items&&dispatch({type:"setLineItems",payload:{lineItems:order.line_items}})},[order?.line_items]);const lineItemValue={...state,loader,updateLineItem:(lineItemId,quantity=1)=>updateLineItem({lineItemId,quantity,dispatch,config,getOrder,orderId,errors:state.errors}),deleteLineItem:lineItemId=>deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})};return _jsx(LineItemContext.Provider,{value:lineItemValue,children:state.loading?loader:children})};LineItemsContainer.propTypes=propTypes,LineItemsContainer.defaultProps=defaultProps,LineItemsContainer.displayName=displayName;export default LineItemsContainer;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"./utils/Parent";import getLineItemsCount from"../utils/getLineItemsCount";import LineItemContext from"../context/LineItemContext";import components from"../config/components";const propTypes=components.LineItemsCount.propTypes,displayName=components.LineItemsCount.displayName,LineItemsCount=props=>{const{children,typeAccepted}=props,p=__rest(props,["children","typeAccepted"]),{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(0);useEffect(()=>{if(lineItems&&lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[],typeAccepted});setQuantity(qty)}return()=>{setQuantity(0)}},[lineItems,typeAccepted]);const parentProps=Object.assign({quantity,typeAccepted},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("span",Object.assign({},p,{children:quantity}))};LineItemsCount.propTypes=propTypes,LineItemsCount.displayName=displayName;export default LineItemsCount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"./utils/Parent";import getLineItemsCount from"../utils/getLineItemsCount";import LineItemContext from"../context/LineItemContext";import components from"../config/components";const propTypes=components.LineItemsCount.propTypes,displayName=components.LineItemsCount.displayName,LineItemsCount=props=>{const{children,typeAccepted,...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(0);useEffect(()=>{if(lineItems&&lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[],typeAccepted});setQuantity(qty)}return()=>{setQuantity(0)}},[lineItems,typeAccepted]);const parentProps={quantity,typeAccepted,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:quantity})};LineItemsCount.propTypes=propTypes,LineItemsCount.displayName=displayName;export default LineItemsCount;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"./utils/Parent";import getLineItemsCount from"../utils/getLineItemsCount";import LineItemContext from"../context/LineItemContext";import components from"../config/components";const propTypes=components.LineItemsEmpty.propTypes,displayName=components.LineItemsEmpty.displayName;export default function LineItemsEmpty(props){const{children,text="Your shopping bag is empty"}=props,p=__rest(props,["children","text"]),{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(),emptyText=quantity===0?_jsx("span",Object.assign({},p,{children:text})):null;useEffect(()=>{if(lineItems)if(lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[]});setQuantity(qty)}else setQuantity(0);return()=>{setQuantity(void 0)}},[lineItems]);const parentProps=Object.assign({quantity,text},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):emptyText}LineItemsEmpty.propTypes=propTypes,LineItemsEmpty.displayName=displayName;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"./utils/Parent";import getLineItemsCount from"../utils/getLineItemsCount";import LineItemContext from"../context/LineItemContext";import components from"../config/components";const propTypes=components.LineItemsEmpty.propTypes,displayName=components.LineItemsEmpty.displayName;export default function LineItemsEmpty(props){const{children,text="Your shopping bag is empty",...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(),emptyText=quantity===0?_jsx("span",{...p,children:text}):null;useEffect(()=>{if(lineItems)if(lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[]});setQuantity(qty)}else setQuantity(0);return()=>{setQuantity(void 0)}},[lineItems]);const parentProps={quantity,text,...p};return children?_jsx(Parent,{...parentProps,children}):emptyText}LineItemsEmpty.propTypes=propTypes,LineItemsEmpty.displayName=displayName;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseInput from"./utils/BaseInput";import components from"../config/components";const propTypes=components.MetadataInput.propTypes,displayName=components.MetadataInput.displayName,MetadataInput=props=>_jsx(BaseInput,Object.assign({"data-metadata":!0},props));MetadataInput.propTypes=propTypes,MetadataInput.displayName=displayName;export default MetadataInput;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseInput from"./utils/BaseInput";import components from"../config/components";const propTypes=components.MetadataInput.propTypes,displayName=components.MetadataInput.displayName,MetadataInput=props=>_jsx(BaseInput,{"data-metadata":!0,...props});MetadataInput.propTypes=propTypes,MetadataInput.displayName=displayName;export default MetadataInput;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder}from"../reducers/OrderReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../context/OrderContext";import components from"../config/components";import OrderStorageContext from"../context/OrderStorageContext";import compareObjAttribute from"../utils/compareObjAttribute";const propTypes=components.OrderContainer.propTypes,defaultProps=components.OrderContainer.defaultProps,displayName=components.OrderContainer.displayName,OrderContainer=props=>{const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),config=useContext(CommerceLayerContext),{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext);useEffect(()=>{if(attributes&&(state==null?void 0:state.order)&&!lock){const updateAttributes=compareObjAttribute({attributes,object:state.order});Object.keys(updateAttributes).length>0&&(updateOrder({id:state.order.id,attributes:updateAttributes,dispatch,config,include:state.include,state}),setLock(!0))}return()=>{if(attributes&&(state==null?void 0:state.order)){const updateAttributes=compareObjAttribute({attributes,object:state.order});state.order&&Object.keys(updateAttributes).length===0&&setLock(!1)}}},[attributes,state==null?void 0:state.order,lock]),useEffect(()=>{var _a;const startRequest=Object.keys((state==null?void 0:state.includeLoaded)||{}).filter(key=>{var _a2;return((_a2=state==null?void 0:state.includeLoaded)===null||_a2===void 0?void 0:_a2[key])===!0});if(config.accessToken&&!state.loading){const localOrder=persistKey?getLocalOrder(persistKey):orderId;localOrder&&!state.order&&((_a=state.include)===null||_a===void 0?void 0:_a.length)===startRequest.length?getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state}):(state==null?void 0:state.order)&&fetchOrder&&fetchOrder(state.order)}return()=>{var _a2,_b;!state.order&&state.loading&&(((_a2=state.include)===null||_a2===void 0?void 0:_a2.length)===0&&startRequest.length>0?dispatch({type:"setLoading",payload:{loading:!1}}):state.include&&((_b=state.include)===null||_b===void 0?void 0:_b.length)>0&&dispatch({type:"setIncludesResource",payload:{include:[]}}))}},[config.accessToken,state.includeLoaded,state.include,orderId,state.order,state.loading]);const orderValue=useMemo(()=>Object.assign(Object.assign({},state),{setOrder:order=>setOrder(order,dispatch),getOrder:id=>getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:()=>createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:values=>defaultOrderContext.addToCart(Object.assign(Object.assign({},values),{persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder})),saveAddressToCustomerAddressBook:args=>defaultOrderContext.saveAddressToCustomerAddressBook(Object.assign(Object.assign({},args),{dispatch})),setGiftCardOrCouponCode:({code,codeType})=>defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:({codeType})=>defaultOrderContext.removeGiftCardOrCouponCode({codeType,dispatch,order:state.order,config,include:state.include,state}),addResourceToInclude:args=>defaultOrderContext.addResourceToInclude(Object.assign(Object.assign({},args),{dispatch,resourcesIncluded:state.include,resourceIncludedLoaded:state.includeLoaded})),updateOrder:async args=>await defaultOrderContext.updateOrder(Object.assign(Object.assign({},args),{dispatch,config,include:state.include,state}))}),[state,config.accessToken]);return _jsx(OrderContext.Provider,Object.assign({value:orderValue},{children}))};OrderContainer.propTypes=propTypes,OrderContainer.defaultProps=defaultProps,OrderContainer.displayName=displayName;export default OrderContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder}from"../reducers/OrderReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../context/OrderContext";import components from"../config/components";import OrderStorageContext from"../context/OrderStorageContext";import compareObjAttribute from"../utils/compareObjAttribute";const propTypes=components.OrderContainer.propTypes,defaultProps=components.OrderContainer.defaultProps,displayName=components.OrderContainer.displayName,OrderContainer=props=>{const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useContext(CommerceLayerContext),{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext);useEffect(()=>{state.withoutIncludes||dispatch({type:"setLoading",payload:{loading:!0}})},[state.withoutIncludes]),useEffect(()=>{if(attributes&&state?.order&&!lock){const updateAttributes=compareObjAttribute({attributes,object:state.order});Object.keys(updateAttributes).length>0&&(updateOrder({id:state.order.id,attributes:updateAttributes,dispatch,config,include:state.include,state}),setLock(!0))}return()=>{if(attributes&&state?.order){const updateAttributes=compareObjAttribute({attributes,object:state.order});state.order&&Object.keys(updateAttributes).length===0&&setLock(!1)}}},[attributes,state?.order,lock]),useEffect(()=>{const localOrder=persistKey?getLocalOrder(persistKey):orderId,startRequest=Object.keys(state?.includeLoaded||{}).filter(key=>state?.includeLoaded?.[key]===!0),getOrder=async()=>{localOrder&&await getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state})};return config.accessToken&&!state.loading?localOrder&&!state.order&&state.include?.length===startRequest.length&&!state.withoutIncludes&&!lockOrder?getOrder():state?.order?fetchOrder&&fetchOrder(state.order):state.withoutIncludes&&!state.include?.length&&startRequest.length===0&&getOrder():[config.accessToken,!state.order,state.loading,state.withoutIncludes].every(Boolean)?dispatch({type:"setLoading",payload:{loading:!1}}):[config.accessToken,!state.order,state.loading,!state.withoutIncludes].every(Boolean)&&dispatch({type:"setLoading",payload:{loading:!1}}),()=>{!state.order&&state.loading&&!state.withoutIncludes&&(state.include?.length===0&&startRequest.length>0?dispatch({type:"setLoading",payload:{loading:!1}}):state.include&&state.include?.length>0&&(dispatch({type:"setIncludesResource",payload:{include:[]}}),setLockOrder(!1)))}},[config.accessToken,state.includeLoaded,state.include,orderId,state.order,state.loading,state.withoutIncludes,lockOrder]);const orderValue=useMemo(()=>({...state,setOrder:order=>setOrder(order,dispatch),getOrder:id=>getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:()=>createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:values=>defaultOrderContext.addToCart({...values,persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder}),saveAddressToCustomerAddressBook:args=>defaultOrderContext.saveAddressToCustomerAddressBook({...args,dispatch}),setGiftCardOrCouponCode:({code,codeType})=>defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:({codeType})=>defaultOrderContext.removeGiftCardOrCouponCode({codeType,dispatch,order:state.order,config,include:state.include,state}),addResourceToInclude:args=>defaultOrderContext.addResourceToInclude({...args,dispatch,resourcesIncluded:state.include,resourceIncludedLoaded:state.includeLoaded}),updateOrder:async args=>await defaultOrderContext.updateOrder({...args,dispatch,config,include:state.include,state})}),[state,config.accessToken]);return _jsx(OrderContext.Provider,{value:orderValue,children})};OrderContainer.propTypes=propTypes,OrderContainer.defaultProps=defaultProps,OrderContainer.displayName=displayName;export default OrderContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import components from"../config/components";import BaseField from"./utils/BaseField";const propTypes=components.OrderNumber.propTypes,displayName=components.OrderNumber.displayName,OrderNumber=props=>_jsx(BaseField,Object.assign({attribute:"number"},props));OrderNumber.propTypes=propTypes,OrderNumber.displayName=displayName;export default OrderNumber;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import components from"../config/components";import BaseField from"./utils/BaseField";const propTypes=components.OrderNumber.propTypes,displayName=components.OrderNumber.displayName,OrderNumber=props=>_jsx(BaseField,{attribute:"number",...props});OrderNumber.propTypes=propTypes,OrderNumber.displayName=displayName;export default OrderNumber;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import OrderStorageContext from"../context/OrderStorageContext";import components from"../config/components";import{getLocalOrder,setLocalOrder,deleteLocalOrder}from"../utils/localStorage";const propTypes=components.OrderStorage.propTypes,displayName=components.OrderStorage.displayName,OrderStorage=props=>{const{children,clearWhenPlaced=!0}=props,p=__rest(props,["children","clearWhenPlaced"]);return _jsx(OrderStorageContext.Provider,Object.assign({value:Object.assign(Object.assign({},p),{setLocalOrder,getLocalOrder,deleteLocalOrder,clearWhenPlaced})},{children}))};OrderStorage.propTypes=propTypes,OrderStorage.displayName=displayName;export default OrderStorage;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import OrderStorageContext from"../context/OrderStorageContext";import components from"../config/components";import{getLocalOrder,setLocalOrder,deleteLocalOrder}from"../utils/localStorage";const propTypes=components.OrderStorage.propTypes,displayName=components.OrderStorage.displayName,OrderStorage=props=>{const{children,clearWhenPlaced=!0,...p}=props;return _jsx(OrderStorageContext.Provider,{value:{...p,setLocalOrder,getLocalOrder,deleteLocalOrder,clearWhenPlaced},children})};OrderStorage.propTypes=propTypes,OrderStorage.displayName=displayName;export default OrderStorage;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../context/OrderContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../context/PaymentMethodContext";import getPaypalConfig from"../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../utils/getLoaderComponent";import AdyenGateway from"./gateways/AdyenGateway";import StripeGateway from"./gateways/StripeGateway";import BraintreeGateway from"./gateways/BraintreeGateway";import PaypalGateway from"./gateways/PaypalGateway";import WireTransferGateway from"./gateways/WireTransferGateway";import CustomerContext from"../context/CustomerContext";import CheckoutComGateway from"./gateways/CheckoutComGateway";import KlarnaGateway from"./gateways/KlarnaGateway";const PaymentGateway=_a=>{var _b,{readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading..."}=_a,p=__rest(_a,["readonly","showCard","handleEditClick","children","templateCustomerCards","templateCustomerSaveToWallet","onClickCustomerCards","show","loader"]);const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment==null?void 0:payment.payment_source_type;useEffect(()=>{var _a2;if((payment==null?void 0:payment.id)===currentPaymentMethodId&&paymentResource&&((_a2=order==null?void 0:order.payment_method)===null||_a2===void 0?void 0:_a2.payment_source_type)===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&await getCustomerPaymentSources()};(!paymentSource&&(order==null?void 0:order.payment_method.id)&&show||!paymentSource||paymentSource.type!==paymentResource)&&setPaymentSources(),(paymentSource==null?void 0:paymentSource.mismatched_amounts)&&show&&setPaymentSources(),setLoading(!1)}return()=>{setLoading(!0)}},[(_b=order==null?void 0:order.payment_method)===null||_b===void 0?void 0:_b.id,show,paymentSource]);const gatewayConfig=Object.assign({readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet},p);switch(paymentResource){case"stripe_payments":return _jsx(StripeGateway,Object.assign({},gatewayConfig,{children}));case"klarna_payments":return _jsx(KlarnaGateway,Object.assign({},gatewayConfig,{children}));case"adyen_payments":return _jsx(AdyenGateway,Object.assign({},gatewayConfig,{children}));case"braintree_payments":return _jsx(BraintreeGateway,Object.assign({},gatewayConfig,{children}));case"wire_transfers":return _jsx(WireTransferGateway,Object.assign({},gatewayConfig,{children}));case"paypal_payments":return _jsx(PaypalGateway,Object.assign({},gatewayConfig,{children}));case"checkout_com_payments":return _jsx(CheckoutComGateway,Object.assign({},gatewayConfig,{children}));default:return null}};export default PaymentGateway;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../context/OrderContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../context/PaymentMethodContext";import getPaypalConfig from"../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../utils/getLoaderComponent";import AdyenGateway from"./gateways/AdyenGateway";import StripeGateway from"./gateways/StripeGateway";import BraintreeGateway from"./gateways/BraintreeGateway";import PaypalGateway from"./gateways/PaypalGateway";import WireTransferGateway from"./gateways/WireTransferGateway";import CustomerContext from"../context/CustomerContext";import CheckoutComGateway from"./gateways/CheckoutComGateway";import KlarnaGateway from"./gateways/KlarnaGateway";const PaymentGateway=({readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading...",...p})=>{const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment?.payment_source_type;useEffect(()=>{if(payment?.id===currentPaymentMethodId&&paymentResource&&order?.payment_method?.payment_source_type===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&await getCustomerPaymentSources()};(!paymentSource&&order?.payment_method.id&&show||!paymentSource||paymentSource.type!==paymentResource)&&setPaymentSources(),paymentSource?.mismatched_amounts&&show&&setPaymentSources(),setLoading(!1)}return()=>{setLoading(!0)}},[order?.payment_method?.id,show,paymentSource]);const gatewayConfig={readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet,...p};switch(paymentResource){case"stripe_payments":return _jsx(StripeGateway,{...gatewayConfig,children});case"klarna_payments":return _jsx(KlarnaGateway,{...gatewayConfig,children});case"adyen_payments":return _jsx(AdyenGateway,{...gatewayConfig,children});case"braintree_payments":return _jsx(BraintreeGateway,{...gatewayConfig,children});case"wire_transfers":return _jsx(WireTransferGateway,{...gatewayConfig,children});case"paypal_payments":return _jsx(PaypalGateway,{...gatewayConfig,children});case"checkout_com_payments":return _jsx(CheckoutComGateway,{...gatewayConfig,children});default:return null}};export default PaymentGateway;
@@ -5,6 +5,7 @@ declare type PaymentMethodProps = {
5
5
  children: ReactNode;
6
6
  activeClass?: string;
7
7
  loader?: LoaderType;
8
+ autoSelectSinglePaymentMethod?: boolean | (() => void);
8
9
  } & Omit<JSX.IntrinsicElements['div'], 'onClick'> & ({
9
10
  clickableContainer: true;
10
11
  onClick?: (payment?: PaymentMethodType | Record<string, any>) => void;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import components from"../config/components";import getLoaderComponent from"../utils/getLoaderComponent";const propTypes=components.PaymentMethod.propTypes,displayName=components.PaymentMethod.displayName,PaymentMethod=_a=>{var{children,className,activeClass,loader="Loading...",clickableContainer,onClick}=_a,p=__rest(_a,["children","className","activeClass","loader","clickableContainer","onClick"]);const[loading,setLoading]=useState(!0),[paymentSelected,setPaymentSelected]=useState(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder}=useContext(PaymentMethodContext);useEffect(()=>(paymentMethods&&setLoading(!1),currentPaymentMethodId&&setPaymentSelected(currentPaymentMethodId),()=>{setLoading(!0)}),[paymentMethods,currentPaymentMethodId]);const components2=paymentMethods&&paymentMethods.map((payment,k)=>{const isActive=currentPaymentMethodId===(payment==null?void 0:payment.id),paymentMethodProps={payment,clickableContainer,paymentSelected,setPaymentSelected},paymentResource=payment==null?void 0:payment.payment_source_type,onClickable=clickableContainer?async e=>{e.stopPropagation(),setLoadingPlaceOrder({loading:!0}),setPaymentSelected(payment.id);const paymentMethodId=payment==null?void 0:payment.id;await setPaymentMethod({paymentResource,paymentMethodId}),onClick&&onClick(payment),setLoadingPlaceOrder({loading:!1})}:void 0;return _jsx("div",Object.assign({"data-test-id":paymentResource,className:`${className} ${isActive?activeClass:""}`,onClick:onClickable},p,{children:_jsx(PaymentMethodChildrenContext.Provider,Object.assign({value:paymentMethodProps},{children}))}),k)});return loading?getLoaderComponent(loader):_jsx(Fragment,{children:components2})};PaymentMethod.propTypes=propTypes,PaymentMethod.displayName=displayName;export default PaymentMethod;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import components from"../config/components";import getLoaderComponent from"../utils/getLoaderComponent";const propTypes=components.PaymentMethod.propTypes,displayName=components.PaymentMethod.displayName,PaymentMethod=({children,className,activeClass,loader="Loading...",clickableContainer,autoSelectSinglePaymentMethod,onClick,...p})=>{const[loading,setLoading]=useState(!0),[paymentSelected,setPaymentSelected]=useState(""),{paymentMethods,currentPaymentMethodId,setPaymentMethod,setLoading:setLoadingPlaceOrder}=useContext(PaymentMethodContext);useEffect(()=>{paymentMethods!=null&&(autoSelectSinglePaymentMethod!=null?(async()=>{if(paymentMethods.length===1){const[paymentMethod]=paymentMethods||[];if(paymentMethod){setLoadingPlaceOrder({loading:!0}),setPaymentSelected(paymentMethod.id);const paymentMethodId=paymentMethod?.id,paymentResource=paymentMethod?.payment_source_type;await setPaymentMethod({paymentResource,paymentMethodId}),onClick&&onClick(paymentMethod),setLoadingPlaceOrder({loading:!1})}typeof autoSelectSinglePaymentMethod=="function"&&autoSelectSinglePaymentMethod()}else setTimeout(()=>{setLoading(!1)},200)})():setLoading(!1))},[paymentMethods]),useEffect(()=>(paymentMethods&&setLoading(!1),currentPaymentMethodId&&setPaymentSelected(currentPaymentMethodId),()=>{setLoading(!0)}),[paymentMethods,currentPaymentMethodId]);const components2=paymentMethods&&paymentMethods.map((payment,k)=>{const isActive=currentPaymentMethodId===payment?.id,paymentMethodProps={payment,clickableContainer,paymentSelected,setPaymentSelected},paymentResource=payment?.payment_source_type,onClickable=clickableContainer?async e=>{e.stopPropagation(),setLoadingPlaceOrder({loading:!0}),setPaymentSelected(payment.id);const paymentMethodId=payment?.id;await setPaymentMethod({paymentResource,paymentMethodId}),onClick&&onClick(payment),setLoadingPlaceOrder({loading:!1})}:void 0;return _jsx("div",{"data-test-id":paymentResource,className:`${className} ${isActive?activeClass:""}`,onClick:onClickable,...p,children:_jsx(PaymentMethodChildrenContext.Provider,{value:paymentMethodProps,children})},k)});return loading?getLoaderComponent(loader):_jsx(Fragment,{children:components2})};PaymentMethod.propTypes=propTypes,PaymentMethod.displayName=displayName;export default PaymentMethod;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.PaymentMethodAmount.propTypes,defaultProps=components.PaymentMethodAmount.defaultProps,displayName=components.PaymentMethodAmount.displayName,PaymentMethodAmount=props=>_jsx(BaseOrderPrice,Object.assign({base:"amount",type:"payment_method"},props));PaymentMethodAmount.propTypes=propTypes,PaymentMethodAmount.defaultProps=defaultProps,PaymentMethodAmount.displayName=displayName;export default PaymentMethodAmount;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import BaseOrderPrice from"./utils/BaseOrderPrice";import components from"../config/components";const propTypes=components.PaymentMethodAmount.propTypes,defaultProps=components.PaymentMethodAmount.defaultProps,displayName=components.PaymentMethodAmount.displayName,PaymentMethodAmount=props=>_jsx(BaseOrderPrice,{base:"amount",type:"payment_method",...props});PaymentMethodAmount.propTypes=propTypes,PaymentMethodAmount.defaultProps=defaultProps,PaymentMethodAmount.displayName=displayName;export default PaymentMethodAmount;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentMethodName.propTypes,displayName=components.PaymentMethodName.displayName,PaymentMethodName=props=>{const{payment}=useContext(PaymentMethodChildrenContext),labelName=payment==null?void 0:payment.name,htmlFor=payment==null?void 0:payment.payment_source_type,parentProps=Object.assign({htmlFor,labelName},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("label",Object.assign({htmlFor},props,{children:labelName}))};PaymentMethodName.propTypes=propTypes,PaymentMethodName.displayName=displayName;export default PaymentMethodName;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentMethodName.propTypes,displayName=components.PaymentMethodName.displayName,PaymentMethodName=props=>{const{payment}=useContext(PaymentMethodChildrenContext),labelName=payment?.name,htmlFor=payment?.payment_source_type,parentProps={htmlFor,labelName,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("label",{htmlFor,...props,children:labelName})};PaymentMethodName.propTypes=propTypes,PaymentMethodName.displayName=displayName;export default PaymentMethodName;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentMethodPrice.propTypes,displayName=components.PaymentMethodPrice.displayName,PaymentMethodPrice=props=>{const{format="formatted",type="amount",labelFree="Free"}=props,p=__rest(props,["format","type","labelFree"]),{payment}=useContext(PaymentMethodChildrenContext),[price,setPrice]=useState(""),[priceCents,setPriceCents]=useState(0);useEffect(()=>{if(payment){const p2=getAmount({base:"price",type,format,obj:payment});setPrice(p2);const c=getAmount({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps=Object.assign({labelFree,price,priceCents},p);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("span",Object.assign({},p,{children:priceCents===0?labelFree:price}))};PaymentMethodPrice.propTypes=propTypes,PaymentMethodPrice.displayName=displayName;export default PaymentMethodPrice;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentMethodPrice.propTypes,displayName=components.PaymentMethodPrice.displayName,PaymentMethodPrice=props=>{const{format="formatted",type="amount",labelFree="Free",...p}=props,{payment}=useContext(PaymentMethodChildrenContext),[price,setPrice]=useState(""),[priceCents,setPriceCents]=useState(0);useEffect(()=>{if(payment){const p2=getAmount({base:"price",type,format,obj:payment});setPrice(p2);const c=getAmount({base:"price",type,format:"cents",obj:payment});setPriceCents(c)}return()=>{setPrice(""),setPriceCents(0)}},[payment]);const parentProps={labelFree,price,priceCents,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:priceCents===0?labelFree:price})};PaymentMethodPrice.propTypes=propTypes,PaymentMethodPrice.displayName=displayName;export default PaymentMethodPrice;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentMethodRadioButton.propTypes,displayName=components.PaymentMethodRadioButton.displayName,PaymentMethodRadioButton=props=>{const{onChange}=props,p=__rest(props,["onChange"]),{payment,paymentSelected,setPaymentSelected,clickableContainer}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=(order==null?void 0:order.id)||"",paymentResource=payment==null?void 0:payment.payment_source_type,paymentMethodId=payment==null?void 0:payment.id,name=`payment-${orderId}`,checked=paymentSelected===(payment==null?void 0:payment.id),handleOnChange=async e=>{e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer&&await setPaymentMethod({paymentResource,paymentMethodId}),onChange&&onChange(payment),setLoading({loading:!1})},id=payment==null?void 0:payment.payment_source_type,parentProps=Object.assign({handleOnChange,checked,id,name},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("input",Object.assign({title:name,type:"radio",id,onChange:handleOnChange,checked},p))};PaymentMethodRadioButton.propTypes=propTypes,PaymentMethodRadioButton.displayName=displayName;export default PaymentMethodRadioButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentMethodRadioButton.propTypes,displayName=components.PaymentMethodRadioButton.displayName,PaymentMethodRadioButton=props=>{const{onChange,...p}=props,{payment,paymentSelected,setPaymentSelected,clickableContainer}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=order?.id||"",paymentResource=payment?.payment_source_type,paymentMethodId=payment?.id,name=`payment-${orderId}`,checked=paymentSelected===payment?.id,handleOnChange=async e=>{e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer&&await setPaymentMethod({paymentResource,paymentMethodId}),onChange&&onChange(payment),setLoading({loading:!1})},id=payment?.payment_source_type,parentProps={handleOnChange,checked,id,name,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("input",{title:name,type:"radio",id,onChange:handleOnChange,checked,...p})};PaymentMethodRadioButton.propTypes=propTypes,PaymentMethodRadioButton.displayName=displayName;export default PaymentMethodRadioButton;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig}from"../reducers/PaymentMethodReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{isEmpty}from"lodash";import{setPaymentRef}from"../reducers/PaymentMethodReducer";const propTypes=components.PaymentMethodsContainer.propTypes,displayName=components.PaymentMethodsContainer.displayName,PaymentMethodsContainer=props=>{const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useContext(OrderContext),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{(include==null?void 0:include.includes("available_payment_methods"))?(includeLoaded==null?void 0:includeLoaded.available_payment_methods)||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0,"line_items.line_item_options.sku_option":!0,"line_items.item":!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method","line_items.line_item_options.sku_option","line_items.item"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&(state.paymentMethods||getPayMethods()),(order==null?void 0:order.payment_source)&&dispatch({type:"setPaymentSource",payload:{paymentSource:order==null?void 0:order.payment_source}}),(order==null?void 0:order.payment_source)===null&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},[order,credentials,include,includeLoaded]);const contextValue=useMemo(()=>Object.assign(Object.assign({},state),{setLoading:({loading})=>defaultPaymentMethodContext.setLoading({loading,dispatch}),setPaymentRef:({ref})=>setPaymentRef({ref,dispatch}),setPaymentMethodErrors:errors=>defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch),setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod(Object.assign(Object.assign({},args),{config:credentials,updateOrder,order,dispatch,setOrderErrors})),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource(Object.assign(Object.assign(Object.assign({},state),args),{config:credentials,dispatch,getOrder,updateOrder,order})),updatePaymentSource:async args=>await defaultPaymentMethodContext.updatePaymentSource(Object.assign(Object.assign({},args),{config:credentials,dispatch})),destroyPaymentSource:async args=>await defaultPaymentMethodContext.destroyPaymentSource(Object.assign(Object.assign({},args),{dispatch,config:credentials,updateOrder,orderId:order==null?void 0:order.id}))}),[state]);return _jsx(PaymentMethodContext.Provider,Object.assign({value:contextValue},{children}))};PaymentMethodsContainer.propTypes=propTypes,PaymentMethodsContainer.displayName=displayName;export default PaymentMethodsContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext,{defaultPaymentMethodContext}from"../context/PaymentMethodContext";import{useContext,useEffect,useReducer,useMemo}from"react";import paymentMethodReducer,{paymentMethodInitialState,getPaymentMethods,setPaymentMethodConfig}from"../reducers/PaymentMethodReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{isEmpty}from"lodash";import{setPaymentRef}from"../reducers/PaymentMethodReducer";const propTypes=components.PaymentMethodsContainer.propTypes,displayName=components.PaymentMethodsContainer.displayName,PaymentMethodsContainer=props=>{const{children,config}=props,[state,dispatch]=useReducer(paymentMethodReducer,paymentMethodInitialState),{order,getOrder,setOrderErrors,include,addResourceToInclude,updateOrder,includeLoaded}=useContext(OrderContext),credentials=useContext(CommerceLayerContext);async function getPayMethods(){order&&await getPaymentMethods({order,dispatch})}useEffect(()=>{include?.includes("available_payment_methods")?includeLoaded?.available_payment_methods||addResourceToInclude({newResourceLoaded:{available_payment_methods:!0,payment_source:!0,payment_method:!0,"line_items.line_item_options.sku_option":!0,"line_items.item":!0}}):addResourceToInclude({newResource:["available_payment_methods","payment_source","payment_method","line_items.line_item_options.sku_option","line_items.item"]}),config&&isEmpty(state.config)&&setPaymentMethodConfig(config,dispatch),credentials&&order&&(state.paymentMethods||getPayMethods()),order?.payment_source&&dispatch({type:"setPaymentSource",payload:{paymentSource:order?.payment_source}}),order?.payment_source===null&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},[order,credentials,include,includeLoaded]);const contextValue=useMemo(()=>({...state,setLoading:({loading})=>defaultPaymentMethodContext.setLoading({loading,dispatch}),setPaymentRef:({ref})=>setPaymentRef({ref,dispatch}),setPaymentMethodErrors:errors=>defaultPaymentMethodContext.setPaymentMethodErrors(errors,dispatch),setPaymentMethod:async args=>await defaultPaymentMethodContext.setPaymentMethod({...args,config:credentials,updateOrder,order,dispatch,setOrderErrors}),setPaymentSource:async args=>await defaultPaymentMethodContext.setPaymentSource({...state,...args,config:credentials,dispatch,getOrder,updateOrder,order}),updatePaymentSource:async args=>await defaultPaymentMethodContext.updatePaymentSource({...args,config:credentials,dispatch}),destroyPaymentSource:async args=>await defaultPaymentMethodContext.destroyPaymentSource({...args,dispatch,config:credentials,updateOrder,orderId:order?.id})}),[state]);return _jsx(PaymentMethodContext.Provider,{value:contextValue,children})};PaymentMethodsContainer.propTypes=propTypes,PaymentMethodsContainer.displayName=displayName;export default PaymentMethodsContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import CustomerContext from"../context/CustomerContext";import PaymentGateway from"./PaymentGateway";import getCardDetails from"../utils/getCardDetails";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentSource.propTypes,displayName=components.PaymentSource.displayName,PaymentSource=props=>{const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>(readonly?(setShow(!0),setShowCard(!0)):(payment==null?void 0:payment.id)===currentPaymentMethodId?(setShow(!0),getCardDetails({paymentType:payment==null?void 0:payment.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!1),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const handleEditClick=async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource==null?void 0:paymentSource.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment==null?void 0:payment.payment_source_type})}setShowCard(!showCard),setShow(!0)},gatewayProps=Object.assign(Object.assign({},props),{show,showCard,handleEditClick,readonly});return _jsx(PaymentGateway,Object.assign({},gatewayProps))};PaymentSource.propTypes=propTypes,PaymentSource.displayName=displayName;export default PaymentSource;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import CustomerContext from"../context/CustomerContext";import PaymentGateway from"./PaymentGateway";import getCardDetails from"../utils/getCardDetails";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentSource.propTypes,displayName=components.PaymentSource.displayName,PaymentSource=props=>{const{readonly}=props,{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{payments}=useContext(CustomerContext),{currentPaymentMethodId,paymentSource,destroyPaymentSource}=useContext(PaymentMethodContext),[show,setShow]=useState(!1),[showCard,setShowCard]=useState(!1);useEffect(()=>(readonly?(setShow(!0),setShowCard(!0)):payment?.id===currentPaymentMethodId?(setShow(!0),getCardDetails({paymentType:payment?.payment_source_type,customerPayment:{payment_source:paymentSource}}).brand&&setShowCard(!0)):setShow(!1),()=>{setShow(!1),setShowCard(!1)}),[currentPaymentMethodId,paymentSource,payments,payment,readonly,order]);const gatewayProps={...props,show,showCard,handleEditClick:async e=>{if(e.stopPropagation(),paymentSource){const paymentSourceId=paymentSource?.id;await destroyPaymentSource({paymentSourceId,paymentResource:payment?.payment_source_type})}setShowCard(!showCard),setShow(!0)},readonly};return _jsx(PaymentGateway,{...gatewayProps})};PaymentSource.propTypes=propTypes,PaymentSource.displayName=displayName;export default PaymentSource;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../context/PaymentSourceContext";import{useContext,useRef}from"react";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentSourceBrandIcon.propTypes,displayName=components.PaymentSourceBrandIcon.displayName,PaymentSourceBrandIcon=_a=>{var{src,width=32,children}=_a,p=__rest(_a,["src","width","children"]);const{brand}=useContext(PaymentSourceContext),ref=useRef(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${brand}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps=Object.assign({brand,defaultSrc,url,width},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("img",Object.assign({ref,src:url,onError:handleError,width},p))};PaymentSourceBrandIcon.propTypes=propTypes,PaymentSourceBrandIcon.displayName=displayName;export default PaymentSourceBrandIcon;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../context/PaymentSourceContext";import{useContext,useRef}from"react";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentSourceBrandIcon.propTypes,displayName=components.PaymentSourceBrandIcon.displayName,PaymentSourceBrandIcon=({src,width=32,children,...p})=>{const{brand}=useContext(PaymentSourceContext),ref=useRef(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${brand}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand,defaultSrc,url,width,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("img",{ref,src:url,onError:handleError,width,...p})};PaymentSourceBrandIcon.propTypes=propTypes,PaymentSourceBrandIcon.displayName=displayName;export default PaymentSourceBrandIcon;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../context/PaymentSourceContext";import{capitalize}from"lodash";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentSourceBrandName.propTypes,displayName=components.PaymentSourceBrandName.displayName,PaymentSourceBrandName=_a=>{var{children,label}=_a,props=__rest(_a,["children","label"]);const{brand}=useContext(PaymentSourceContext),brandName=brand&&capitalize(brand.replace("-"," ")),parentProps=Object.assign({brand:brandName,label},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("span",Object.assign({},props,{children:label||capitalize(brandName)}))};PaymentSourceBrandName.propTypes=propTypes,PaymentSourceBrandName.displayName=displayName;export default PaymentSourceBrandName;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../context/PaymentSourceContext";import{capitalize}from"lodash";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";const propTypes=components.PaymentSourceBrandName.propTypes,displayName=components.PaymentSourceBrandName.displayName,PaymentSourceBrandName=({children,label,...props})=>{const{brand}=useContext(PaymentSourceContext),brandName=brand&&capitalize(brand.replace("-"," ")),parentProps={brand:brandName,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...props,children:label||capitalize(brandName)})};PaymentSourceBrandName.propTypes=propTypes,PaymentSourceBrandName.displayName=displayName;export default PaymentSourceBrandName;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import components from"../config/components";import PaymentSourceContext from"../context/PaymentSourceContext";import{has}from"lodash";import{useContext}from"react";import Parent from"./utils/Parent";const propTypes=components.PaymentSourceDetail.propTypes,displayName=components.PaymentSourceDetail.displayName,PaymentSourceDetail=_a=>{var{type,children}=_a,p=__rest(_a,["type","children"]);const card=useContext(PaymentSourceContext),text=has(card,type)?card[type]:type==="last4"?"****":"**",parentProps=Object.assign({type,text},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("span",Object.assign({},p,{children:text}))};PaymentSourceDetail.propTypes=propTypes,PaymentSourceDetail.displayName=displayName;export default PaymentSourceDetail;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import components from"../config/components";import PaymentSourceContext from"../context/PaymentSourceContext";import{has}from"lodash";import{useContext}from"react";import Parent from"./utils/Parent";const propTypes=components.PaymentSourceDetail.propTypes,displayName=components.PaymentSourceDetail.displayName,PaymentSourceDetail=({type,children,...p})=>{const card=useContext(PaymentSourceContext),text=has(card,type)?card[type]:type==="last4"?"****":"**",parentProps={type,text,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:text})};PaymentSourceDetail.propTypes=propTypes,PaymentSourceDetail.displayName=displayName;export default PaymentSourceDetail;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../context/PaymentSourceContext";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";const displayName=components.PaymentSourceEditButton.displayName,propTypes=components.PaymentSourceEditButton.propTypes,PaymentSourceEditButton=_a=>{var{children,label="Edit"}=_a,props=__rest(_a,["children","label"]);const{showCard,handleEditClick,readonly}=useContext(PaymentSourceContext),parentProps=Object.assign({showCard,label,handleEditClick},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):readonly?null:_jsx("button",Object.assign({},props,{onClick:handleEditClick},{children:label}))};PaymentSourceEditButton.propTypes=propTypes,PaymentSourceEditButton.displayName=displayName;export default PaymentSourceEditButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../context/PaymentSourceContext";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";const displayName=components.PaymentSourceEditButton.displayName,propTypes=components.PaymentSourceEditButton.propTypes,PaymentSourceEditButton=({children,label="Edit",...props})=>{const{showCard,handleEditClick,readonly}=useContext(PaymentSourceContext),parentProps={showCard,label,handleEditClick,...props};return children?_jsx(Parent,{...parentProps,children}):readonly?null:_jsx("button",{...props,onClick:handleEditClick,children:label})};PaymentSourceEditButton.propTypes=propTypes,PaymentSourceEditButton.displayName=displayName;export default PaymentSourceEditButton;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext from"../context/PaymentMethodContext";import isFunction from"lodash/isFunction";import{useContext,useEffect,useRef}from"react";const defaultMessage="by placing the order, you will be redirected to the PayPal website to sign in and authorize the payment",PaypalPayment=_a=>{var{infoMessage}=_a,p=__rest(_a,["infoMessage"]);const ref=useRef(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext);useEffect(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&(paymentSource==null?void 0:paymentSource.approval_url)&&(ref.current.onsubmit=()=>handleClick(),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=async()=>{if(paymentSource&&currentPaymentMethodType)try{return await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"paypal",last4:""}}}}),!0}catch{return!1}return!1};return _jsx("form",Object.assign({ref},{children:_jsx("div",Object.assign({},p,{children:_jsx("span",Object.assign({className:infoMessage==null?void 0:infoMessage.className},{children:isFunction(infoMessage==null?void 0:infoMessage.text)?infoMessage==null?void 0:infoMessage.text():(infoMessage==null?void 0:infoMessage.text)||defaultMessage}))}))}))};export default PaypalPayment;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PaymentMethodContext from"../context/PaymentMethodContext";import isFunction from"lodash/isFunction";import{useContext,useEffect,useRef}from"react";const defaultMessage="by placing the order, you will be redirected to the PayPal website to sign in and authorize the payment",PaypalPayment=({infoMessage,...p})=>{const ref=useRef(null),{setPaymentSource,paymentSource,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext);useEffect(()=>(ref.current&&paymentSource&&currentPaymentMethodType&&paymentSource?.approval_url&&(ref.current.onsubmit=()=>handleClick(),setPaymentRef({ref})),()=>{setPaymentRef({ref:{current:null}})}),[ref,paymentSource,currentPaymentMethodType]);const handleClick=async()=>{if(paymentSource&&currentPaymentMethodType)try{return await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:currentPaymentMethodType,attributes:{metadata:{card:{id:paymentSource.id,brand:"paypal",last4:""}}}}),!0}catch{return!1}return!1};return _jsx("form",{ref,children:_jsx("div",{...p,children:_jsx("span",{className:infoMessage?.className,children:isFunction(infoMessage?.text)?infoMessage?.text():infoMessage?.text||defaultMessage})})})};export default PaypalPayment;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import PlaceOrderContext from"../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import getCardDetails from"../utils/getCardDetails";const propTypes=components.PlaceOrderButton.propTypes,defaultProps=components.PlaceOrderButton.defaultProps,displayName=components.PlaceOrderButton.displayName,PlaceOrderButton=props=>{var _a;const{children,label="Place order",disabled,onClick}=props,p=__rest(props,["children","label","disabled","onClick"]),{isPermitted,setPlaceOrder,options,paymentType}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=(order==null?void 0:order.total_amount_with_taxes_cents)===0;useEffect(()=>{var _a2;if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree&&isPermitted||((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,(_a=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a===void 0?void 0:_a.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&(options==null?void 0:options.paypalPayerId)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.paypalPayerId,paymentType]),useEffect(()=>{var _a2,_b;paymentType==="adyen_payments"&&((_a2=options==null?void 0:options.adyen)===null||_a2===void 0?void 0:_a2.MD)&&((_b=options==null?void 0:options.adyen)===null||_b===void 0?void 0:_b.PaRes)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.adyen,paymentType]),useEffect(()=>{var _a2;paymentType==="checkout_com_payments"&&((_a2=options==null?void 0:options.checkoutCom)===null||_a2===void 0?void 0:_a2.session_id)&&(order==null?void 0:order.status)&&["draft","pending"].includes(order==null?void 0:order.status)&&handleClick()},[options==null?void 0:options.checkoutCom,paymentType]);const handleClick=async()=>{var _a2,_b,_c,_d;let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});((_a2=currentPaymentMethodRef==null?void 0:currentPaymentMethodRef.current)===null||_a2===void 0?void 0:_a2.onsubmit)&&[!(options==null?void 0:options.paypalPayerId),!((_b=options==null?void 0:options.adyen)===null||_b===void 0?void 0:_b.MD),!((_c=options==null?void 0:options.checkoutCom)===null||_c===void 0?void 0:_c.session_id)].every(Boolean)?isValid=await((_d=currentPaymentMethodRef.current)===null||_d===void 0?void 0:_d.onsubmit(paymentSource)):(card==null?void 0:card.brand)&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps=Object.assign(Object.assign({},p),{label,disabled:disabledButton,handleClick});return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({type:"button",disabled:disabledButton||forceDisable,onClick:handleClick},p,{children:isFunction(label)?label():label}))};PlaceOrderButton.propTypes=propTypes,PlaceOrderButton.defaultProps=defaultProps,PlaceOrderButton.displayName=displayName;export default PlaceOrderButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import PlaceOrderContext from"../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";import getCardDetails from"../utils/getCardDetails";const propTypes=components.PlaceOrderButton.propTypes,defaultProps=components.PlaceOrderButton.defaultProps,displayName=components.PlaceOrderButton.displayName,PlaceOrderButton=props=>{const ref=useRef(null),{children,label="Place order",disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&order?.status&&["draft","pending"].includes(order?.status)){const attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult},paymentData:paymentSource.payment_response.paymentData},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode;["Authorised","Pending","Received"].includes(resultCode)&&handleClick()})}paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.adyen,paymentType]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref!=null&&ref.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async()=>{let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit(paymentSource),isValid===!1&&paymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps={...p,label,disabled:disabledButton,handleClick,ref};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:handleClick,...p,children:isFunction(label)?label():label})};PlaceOrderButton.propTypes=propTypes,PlaceOrderButton.defaultProps=defaultProps,PlaceOrderButton.displayName=displayName;export default PlaceOrderButton;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import PlaceOrderContext from"../context/PlaceOrderContext";import{useContext,useEffect,useReducer}from"react";import placeOrderReducer,{placeOrderInitialState,placeOrderPermitted}from"../reducers/PlaceOrderReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{setPlaceOrder}from"../reducers/PlaceOrderReducer";const propTypes=components.PlaceOrderContainer.propTypes,displayName=components.PlaceOrderContainer.displayName,PlaceOrderContainer=props=>{const{children,options}=props,[state,dispatch]=useReducer(placeOrderReducer,placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{(include==null?void 0:include.includes("shipments.available_shipping_methods"))?(includeLoaded==null?void 0:includeLoaded["shipments.available_shipping_methods"])||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.shipment_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.shipment_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),(include==null?void 0:include.includes("billing_address"))?(includeLoaded==null?void 0:includeLoaded.billing_address)||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),(include==null?void 0:include.includes("shipping_address"))?(includeLoaded==null?void 0:includeLoaded.shipping_address)||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&placeOrderPermitted({config,dispatch,order,options:Object.assign({},options)})},[order,include,includeLoaded]);const contextValue=Object.assign(Object.assign({},state),{setPlaceOrder:({paymentSource})=>setPlaceOrder({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>placeOrderPermitted({config,dispatch,order,options:Object.assign({},options)})});return _jsx(PlaceOrderContext.Provider,Object.assign({value:contextValue},{children}))};PlaceOrderContainer.propTypes=propTypes,PlaceOrderContainer.displayName=displayName;export default PlaceOrderContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import PlaceOrderContext from"../context/PlaceOrderContext";import{useContext,useEffect,useReducer}from"react";import placeOrderReducer,{placeOrderInitialState,placeOrderPermitted,setButtonRef}from"../reducers/PlaceOrderReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{setPlaceOrder}from"../reducers/PlaceOrderReducer";const propTypes=components.PlaceOrderContainer.propTypes,displayName=components.PlaceOrderContainer.displayName,PlaceOrderContainer=props=>{const{children,options}=props,[state,dispatch]=useReducer(placeOrderReducer,placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.shipment_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.shipment_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&placeOrderPermitted({config,dispatch,order,options:{...options}})},[order,include,includeLoaded]);const contextValue={...state,setPlaceOrder:({paymentSource})=>setPlaceOrder({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>placeOrderPermitted({config,dispatch,order,options:{...options}}),setButtonRef:ref=>setButtonRef(ref,dispatch)};return _jsx(PlaceOrderContext.Provider,{value:contextValue,children})};PlaceOrderContainer.propTypes=propTypes,PlaceOrderContainer.displayName=displayName;export default PlaceOrderContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useState,useEffect,useContext}from"react";import{isEmpty,has,indexOf}from"lodash";import Parent from"./utils/Parent";import PricesContext from"../context/PricesContext";import{getPricesComponent}from"../utils/getPrices";import components from"../config/components";import SkuChildrenContext from"../context/SkuChildrenContext";const propTypes=components.Price.propTypes,defaultProps=components.Price.defaultProps,displayName=components.Price.displayName,Price=props=>{const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=useContext(PricesContext),{sku}=useContext(SkuChildrenContext),[skuPrices,setSkuPrices]=useState([]),sCode=pricesSkuCode||skuCode||(sku==null?void 0:sku.code);useEffect(()=>(!isEmpty(prices)&&has(prices,`${sCode}`)?setSkuPrices(prices[sCode]):sCode&&indexOf(skuCodes,sCode)===-1&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes(skuCodes)),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps=Object.assign({loading,loader,prices:skuPrices},props),pricesComponent=isEmpty(prices)||isEmpty(skuPrices)?null:getPricesComponent(skuPrices,props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx(Fragment,{children:loading||isEmpty(pricesComponent)?loader:pricesComponent})};Price.propTypes=propTypes,Price.defaultProps=defaultProps,Price.displayName=displayName;export default Price;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useState,useEffect,useContext}from"react";import{isEmpty,has,indexOf}from"lodash";import Parent from"./utils/Parent";import PricesContext from"../context/PricesContext";import{getPricesComponent}from"../utils/getPrices";import components from"../config/components";import SkuChildrenContext from"../context/SkuChildrenContext";const propTypes=components.Price.propTypes,defaultProps=components.Price.defaultProps,displayName=components.Price.displayName,Price=props=>{const{children,skuCode=""}=props,{prices,skuCode:pricesSkuCode,loading,skuCodes,setSkuCodes,loader}=useContext(PricesContext),{sku}=useContext(SkuChildrenContext),[skuPrices,setSkuPrices]=useState([]),sCode=pricesSkuCode||skuCode||sku?.code;useEffect(()=>(!isEmpty(prices)&&has(prices,`${sCode}`)?setSkuPrices(prices[sCode]):sCode&&indexOf(skuCodes,sCode)===-1&&(skuCodes.push(sCode),setSkuCodes&&setSkuCodes(skuCodes)),()=>{setSkuPrices([])}),[prices,sCode]);const parentProps={loading,loader,prices:skuPrices,...props},pricesComponent=isEmpty(prices)||isEmpty(skuPrices)?null:getPricesComponent(skuPrices,props);return children?_jsx(Parent,{...parentProps,children}):_jsx(Fragment,{children:loading||isEmpty(pricesComponent)?loader:pricesComponent})};Price.propTypes=propTypes,Price.defaultProps=defaultProps,Price.displayName=displayName;export default Price;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useContext,useReducer}from"react";import getPrices from"../utils/getPrices";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import indexOf from"lodash/indexOf";import CommerceLayerContext from"../context/CommerceLayerContext";import priceReducer,{unsetPriceState}from"../reducers/PriceReducer";import{priceInitialState,getSkusPrice}from"../reducers/PriceReducer";import PricesContext from"../context/PricesContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import ItemContext from"../context/ItemContext";import components from"../config/components";import SkuContext from"../context/SkuContext";const propTypes=components.PricesContainer.propTypes,defaultProps=components.PricesContainer.defaultProps,displayName=components.PricesContainer.displayName,PricesContainer=props=>{const{children,skuCode="",loader="Loading...",perPage=10,filters={}}=props,[state,dispatch]=useReducer(priceReducer,priceInitialState),config=useContext(CommerceLayerContext),{skuCodes}=useContext(SkuContext),{setPrices,prices,items,item:currentItem,skuCode:itemSkuCode}=useContext(ItemContext);indexOf(state.skuCodes,skuCode)===-1&&skuCode&&state.skuCodes.push(skuCode);const sCode=skuCodes&&(skuCodes==null?void 0:skuCodes.length)>0?"":skuCode||getCurrentItemKey(currentItem)||itemSkuCode||"",setSkuCodes=skuCodes2=>{dispatch({type:"setSkuCodes",payload:{skuCodes:skuCodes2}})};useEffect(()=>{if(state.skuCodes.length===0&&skuCodes&&skuCodes.length>0&&setSkuCodes(skuCodes),currentItem&&has(prices,sCode)&&dispatch({type:"setPrices",payload:{prices}}),!isEmpty(items)&&isEmpty(currentItem)){const p=getPrices(items);dispatch({type:"setPrices",payload:{prices:p}})}return config.accessToken&&!has(prices,itemSkuCode||sCode)&&(state.skuCodes.length>0||itemSkuCode||sCode)&&getSkusPrice(sCode&&[itemSkuCode||sCode]||state.skuCodes,{config,dispatch,setPrices,prices,perPage,filters}),config.accessToken&&isEmpty(currentItem)&&(state.skuCodes.length>0||skuCode)&&getSkusPrice(sCode&&[sCode]||state.skuCodes,{config,dispatch,setPrices,prices,perPage,filters}),()=>{isEmpty(currentItem)&&unsetPriceState(dispatch)}},[config.accessToken,currentItem,sCode,state.skuCodes.length,itemSkuCode]);const priceValue=Object.assign(Object.assign({},state),{skuCode:sCode,loader,setSkuCodes});return _jsx(PricesContext.Provider,Object.assign({value:priceValue},{children}))};PricesContainer.propTypes=propTypes,PricesContainer.defaultProps=defaultProps,PricesContainer.displayName=displayName;export default PricesContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useContext,useReducer}from"react";import getPrices from"../utils/getPrices";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import indexOf from"lodash/indexOf";import CommerceLayerContext from"../context/CommerceLayerContext";import priceReducer,{unsetPriceState}from"../reducers/PriceReducer";import{priceInitialState,getSkusPrice}from"../reducers/PriceReducer";import PricesContext from"../context/PricesContext";import getCurrentItemKey from"../utils/getCurrentItemKey";import ItemContext from"../context/ItemContext";import components from"../config/components";import SkuContext from"../context/SkuContext";const propTypes=components.PricesContainer.propTypes,defaultProps=components.PricesContainer.defaultProps,displayName=components.PricesContainer.displayName,PricesContainer=props=>{const{children,skuCode="",loader="Loading...",perPage=10,filters={}}=props,[state,dispatch]=useReducer(priceReducer,priceInitialState),config=useContext(CommerceLayerContext),{skuCodes}=useContext(SkuContext),{setPrices,prices,items,item:currentItem,skuCode:itemSkuCode}=useContext(ItemContext);indexOf(state.skuCodes,skuCode)===-1&&skuCode&&state.skuCodes.push(skuCode);const sCode=skuCodes&&skuCodes?.length>0?"":skuCode||getCurrentItemKey(currentItem)||itemSkuCode||"",setSkuCodes=skuCodes2=>{dispatch({type:"setSkuCodes",payload:{skuCodes:skuCodes2}})};useEffect(()=>{if(state.skuCodes.length===0&&skuCodes&&skuCodes.length>0&&setSkuCodes(skuCodes),currentItem&&has(prices,sCode)&&dispatch({type:"setPrices",payload:{prices}}),!isEmpty(items)&&isEmpty(currentItem)){const p=getPrices(items);dispatch({type:"setPrices",payload:{prices:p}})}return config.accessToken&&!has(prices,itemSkuCode||sCode)&&(state.skuCodes.length>0||itemSkuCode||sCode)&&getSkusPrice(sCode&&[itemSkuCode||sCode]||state.skuCodes,{config,dispatch,setPrices,prices,perPage,filters}),config.accessToken&&isEmpty(currentItem)&&(state.skuCodes.length>0||skuCode)&&getSkusPrice(sCode&&[sCode]||state.skuCodes,{config,dispatch,setPrices,prices,perPage,filters}),()=>{isEmpty(currentItem)&&unsetPriceState(dispatch)}},[config.accessToken,currentItem,sCode,state.skuCodes.length,itemSkuCode]);const priceValue={...state,skuCode:sCode,loader,setSkuCodes};return _jsx(PricesContext.Provider,{value:priceValue,children})};PricesContainer.propTypes=propTypes,PricesContainer.defaultProps=defaultProps,PricesContainer.displayName=displayName;export default PricesContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import components from"../config/components";import OrderContext from"../context/OrderContext";import PlaceOrderContext from"../context/PlaceOrderContext";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";const propTypes=components.PrivacyAndTermsCheckbox.propTypes,displayName=components.PrivacyAndTermsCheckbox.displayName,PrivacyAndTermsCheckbox=props=>{const{order}=useContext(OrderContext),{placeOrderPermitted}=useContext(PlaceOrderContext),[forceDisabled,setForceDisabled]=useState(!0),[checked,setChecked]=useState(!1),fieldName="privacy-terms",handleChange=e=>{var _a;const v=(_a=e.target)===null||_a===void 0?void 0:_a.checked;setChecked(v),localStorage.setItem(fieldName,`${v}`),placeOrderPermitted&&placeOrderPermitted()};return useEffect(()=>((order==null?void 0:order.privacy_url)&&(order==null?void 0:order.terms_url)&&setForceDisabled(!1),checked||localStorage.setItem(fieldName,`${checked}`),()=>{setForceDisabled(!0),localStorage.removeItem(fieldName)}),[order==null?void 0:order.privacy_url,order==null?void 0:order.terms_url]),_jsx(BaseInput,Object.assign({type:"checkbox",name:fieldName,disabled:forceDisabled,onChange:handleChange,checked},props))};PrivacyAndTermsCheckbox.propTypes=propTypes,PrivacyAndTermsCheckbox.displayName=displayName;export default PrivacyAndTermsCheckbox;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import components from"../config/components";import OrderContext from"../context/OrderContext";import PlaceOrderContext from"../context/PlaceOrderContext";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";const propTypes=components.PrivacyAndTermsCheckbox.propTypes,displayName=components.PrivacyAndTermsCheckbox.displayName,PrivacyAndTermsCheckbox=props=>{const{order}=useContext(OrderContext),{placeOrderPermitted}=useContext(PlaceOrderContext),[forceDisabled,setForceDisabled]=useState(!0),[checked,setChecked]=useState(!1),fieldName="privacy-terms",handleChange=e=>{const v=e.target?.checked;setChecked(v),localStorage.setItem(fieldName,`${v}`),placeOrderPermitted&&placeOrderPermitted()};return useEffect(()=>(order?.privacy_url&&order?.terms_url&&setForceDisabled(!1),checked||localStorage.setItem(fieldName,`${checked}`),()=>{setForceDisabled(!0),localStorage.removeItem(fieldName)}),[order?.privacy_url,order?.terms_url]),_jsx(BaseInput,{type:"checkbox",name:fieldName,disabled:forceDisabled,onChange:handleChange,checked,...props})};PrivacyAndTermsCheckbox.propTypes=propTypes,PrivacyAndTermsCheckbox.displayName=displayName;export default PrivacyAndTermsCheckbox;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"./utils/Parent";import has from"lodash/has";import isEmpty from"lodash/isEmpty";import getCurrentItemKey from"../utils/getCurrentItemKey";import ItemContext from"../context/ItemContext";import components from"../config/components";import SkuListsContext from"../context/SkuListsContext";import SkuChildrenContext from"../context/SkuChildrenContext";const propTypes=components.QuantitySelector.propTypes,defaultProps=components.QuantitySelector.defaultProps,displayName=components.QuantitySelector.displayName,QuantitySelector=props=>{var _a,_b,_c;const{skuCode,skuListId,children,min=1,max}=props,p=__rest(props,["skuCode","skuListId","children","min","max"]),{item,setQuantity,items,quantity,prices,skuCode:itemSkuCode}=useContext(ItemContext),{sku}=useContext(SkuChildrenContext),{skuLists,listIds}=useContext(SkuListsContext),defaultVal=(p==null?void 0:p.value)||min,[value,setValue]=useState(defaultVal),[disabled,setDisabled]=useState(!!p.disabled),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,inventory=isEmpty(item)?50:(_c=(_b=item[sCode])===null||_b===void 0?void 0:_b.inventory)===null||_c===void 0?void 0:_c.quantity,maxInv=max||inventory;useEffect(()=>{if(setValue(defaultVal),(!prices[sCode]||!sCode)&&setDisabled(!0),skuListId&&setDisabled(!1),sCode&&!quantity[sCode]){const qty=Number(defaultVal);setQuantity&&setQuantity(Object.assign(Object.assign({},quantity),{[`${sCode}`]:qty})),!isEmpty(prices)&&has(prices,sCode)&&setDisabled(!1)}return()=>{setValue(defaultVal)}},[item,listIds,prices,quantity]);const handleChange=e=>{const qty=Number(e.target.value),valid=Number(qty)>=Number(min)&&Number(qty)<=Number(maxInv);setValue(qty),!isEmpty(skuLists)&&skuListId&&valid?setQuantity&&setQuantity(Object.assign(Object.assign({},quantity),{[`${skuListId}`]:Number(qty)})):sCode&&valid&&setQuantity&&setQuantity(Object.assign(Object.assign({},quantity),{[`${sCode}`]:Number(qty)}))},handleBlur=e=>{const qty=e.target.value;if(!(Number(qty)>=Number(min)&&Number(qty)<=Number(maxInv))){const resetVal=Number(qty)<Number(min)?min:maxInv;resetVal&&setValue(resetVal),!isEmpty(skuLists)&&skuListId?setQuantity&&setQuantity(Object.assign(Object.assign({},quantity),{[`${skuListId}`]:Number(resetVal)})):setQuantity&&setQuantity(Object.assign(Object.assign({},quantity),{[`${sCode}`]:Number(resetVal)}))}},parentProps=Object.assign({min,max:maxInv,disabled,handleChange,handleBlur,value},props);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("input",Object.assign({type:"number",max:maxInv,min,value:value||"",disabled,onChange:handleChange,onBlur:handleBlur},p))};QuantitySelector.propTypes=propTypes,QuantitySelector.defaultProps=defaultProps,QuantitySelector.displayName=displayName;export default QuantitySelector;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"./utils/Parent";import has from"lodash/has";import isEmpty from"lodash/isEmpty";import getCurrentItemKey from"../utils/getCurrentItemKey";import ItemContext from"../context/ItemContext";import components from"../config/components";import SkuListsContext from"../context/SkuListsContext";import SkuChildrenContext from"../context/SkuChildrenContext";const propTypes=components.QuantitySelector.propTypes,defaultProps=components.QuantitySelector.defaultProps,displayName=components.QuantitySelector.displayName,QuantitySelector=props=>{const{skuCode,skuListId,children,min=1,max,...p}=props,{item,setQuantity,items,quantity,prices,skuCode:itemSkuCode}=useContext(ItemContext),{sku}=useContext(SkuChildrenContext),{skuLists,listIds}=useContext(SkuListsContext),defaultVal=p?.value||min,[value,setValue]=useState(defaultVal),[disabled,setDisabled]=useState(!!p.disabled),sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:sku?.code||skuCode||getCurrentItemKey(item)||itemSkuCode,inventory=isEmpty(item)?50:item[sCode]?.inventory?.quantity,maxInv=max||inventory;useEffect(()=>{if(setValue(defaultVal),(!prices[sCode]||!sCode)&&setDisabled(!0),skuListId&&setDisabled(!1),sCode&&!quantity[sCode]){const qty=Number(defaultVal);setQuantity&&setQuantity({...quantity,[`${sCode}`]:qty}),!isEmpty(prices)&&has(prices,sCode)&&setDisabled(!1)}return()=>{setValue(defaultVal)}},[item,listIds,prices,quantity]);const handleChange=e=>{const qty=Number(e.target.value),valid=Number(qty)>=Number(min)&&Number(qty)<=Number(maxInv);setValue(qty),!isEmpty(skuLists)&&skuListId&&valid?setQuantity&&setQuantity({...quantity,[`${skuListId}`]:Number(qty)}):sCode&&valid&&setQuantity&&setQuantity({...quantity,[`${sCode}`]:Number(qty)})},handleBlur=e=>{const qty=e.target.value;if(!(Number(qty)>=Number(min)&&Number(qty)<=Number(maxInv))){const resetVal=Number(qty)<Number(min)?min:maxInv;resetVal&&setValue(resetVal),!isEmpty(skuLists)&&skuListId?setQuantity&&setQuantity({...quantity,[`${skuListId}`]:Number(resetVal)}):setQuantity&&setQuantity({...quantity,[`${sCode}`]:Number(resetVal)})}},parentProps={min,max:maxInv,disabled,handleChange,handleBlur,value,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("input",{type:"number",max:maxInv,min,value:value||"",disabled,onChange:handleChange,onBlur:handleBlur,...p})};QuantitySelector.propTypes=propTypes,QuantitySelector.defaultProps=defaultProps,QuantitySelector.displayName=displayName;export default QuantitySelector;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import AddressContext from"../context/AddressContext";import{isEmpty}from"lodash";import{billingAddressController,shippingAddressController,countryLockController}from"../utils/addressesManager";import OrderContext from"../context/OrderContext";import CustomerContext from"../context/CustomerContext";import isFunction from"lodash/isFunction";const propTypes=components.SaveAddressesButton.propTypes,defaultProps=components.SaveAddressesButton.defaultProps,displayName=components.SaveAddressesButton.displayName,SaveAddressesButton=props=>{const{children,label="Continue to delivery",resource,disabled=!1,onClick}=props,p=__rest(props,["children","label","resource","disabled","onClick"]),{errors,billing_address,shipToDifferentAddress,shipping_address,saveAddresses,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),{addresses,isGuest}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled),customerEmail=(isGuest===!0||typeof isGuest=="undefined")&&!(order==null?void 0:order.customer_email),billingDisable=billingAddressController({billing_address,errors,billingAddressId,requiresBillingInfo:order==null?void 0:order.requires_billing_info}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId}),countryLockDisable=countryLockController({countryCodeLock:order==null?void 0:order.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address,shipping_address,shippingAddressId}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=async()=>{isEmpty(errors)&&!disable&&(setForceDisable(!0),await saveAddresses(),setForceDisable(!1),onClick&&onClick())},parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({type:"button",disabled:disable||forceDisable,onClick:handleClick},p,{children:isFunction(label)?label():label}))};SaveAddressesButton.propTypes=propTypes,SaveAddressesButton.defaultProps=defaultProps,SaveAddressesButton.displayName=displayName;export default SaveAddressesButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import AddressContext from"../context/AddressContext";import{isEmpty}from"lodash";import{billingAddressController,shippingAddressController,countryLockController}from"../utils/addressesManager";import OrderContext from"../context/OrderContext";import CustomerContext from"../context/CustomerContext";import isFunction from"lodash/isFunction";const propTypes=components.SaveAddressesButton.propTypes,defaultProps=components.SaveAddressesButton.defaultProps,displayName=components.SaveAddressesButton.displayName,SaveAddressesButton=props=>{const{children,label="Continue to delivery",resource,disabled=!1,onClick,...p}=props,{errors,billing_address,shipToDifferentAddress,shipping_address,saveAddresses,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),{addresses,isGuest}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled),customerEmail=(isGuest===!0||typeof isGuest=="undefined")&&!order?.customer_email,billingDisable=billingAddressController({billing_address,errors,billingAddressId,requiresBillingInfo:order?.requires_billing_info}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId}),countryLockDisable=countryLockController({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address,shipping_address,shippingAddressId}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=async()=>{isEmpty(errors)&&!disable&&(setForceDisable(!0),await saveAddresses(),setForceDisable(!1),onClick&&onClick())},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable||forceDisable,onClick:handleClick,...p,children:isFunction(label)?label():label})};SaveAddressesButton.propTypes=propTypes,SaveAddressesButton.defaultProps=defaultProps,SaveAddressesButton.displayName=displayName;export default SaveAddressesButton;
@@ -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{isEmpty}from"lodash";import CustomerContext from"../context/CustomerContext";const propTypes=components.SaveCustomerButton.propTypes,defaultProps=components.SaveCustomerButton.defaultProps,displayName=components.SaveCustomerButton.displayName,SaveCustomerButton=props=>{const{children,label="Save",resource,disabled,onClick}=props,p=__rest(props,["children","label","resource","disabled","onClick"]),{errors,saveCustomerUser,customerEmail}=useContext(CustomerContext),disable=disabled||!isEmpty(errors)||isEmpty(customerEmail),handleClick=async()=>{isEmpty(errors)&&!disable&&(await saveCustomerUser(customerEmail),onClick&&onClick())},parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx("button",Object.assign({type:"button",disabled:disable,onClick:handleClick},p,{children:label}))};SaveCustomerButton.propTypes=propTypes,SaveCustomerButton.defaultProps=defaultProps,SaveCustomerButton.displayName=displayName;export default SaveCustomerButton;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import{isEmpty}from"lodash";import CustomerContext from"../context/CustomerContext";const propTypes=components.SaveCustomerButton.propTypes,defaultProps=components.SaveCustomerButton.defaultProps,displayName=components.SaveCustomerButton.displayName,SaveCustomerButton=props=>{const{children,label="Save",resource,disabled,onClick,...p}=props,{errors,saveCustomerUser,customerEmail}=useContext(CustomerContext),disable=disabled||!isEmpty(errors)||isEmpty(customerEmail),handleClick=async()=>{isEmpty(errors)&&!disable&&(await saveCustomerUser(customerEmail),onClick&&onClick())},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable,onClick:handleClick,...p,children:label})};SaveCustomerButton.propTypes=propTypes,SaveCustomerButton.defaultProps=defaultProps,SaveCustomerButton.displayName=displayName;export default SaveCustomerButton;
@@ -1 +1 @@
1
- import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShipmentContext from"../context/ShipmentContext";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";import components from"../config/components";import getLoaderComponent from"../utils/getLoaderComponent";const propTypes=components.Shipment.propTypes,displayName=components.Shipment.displayName;export default function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=useState(!0),{shipments,deliveryLeadTimes,setShippingMethod}=useContext(ShipmentContext);useEffect(()=>{shipments&&(autoSelectSingleShippingMethod?(async()=>await shipments.forEach(async shipment=>{var _a;const isSingle=((_a=shipment==null?void 0:shipment.available_shipping_methods)===null||_a===void 0?void 0:_a.length)===1;if(!(shipment==null?void 0:shipment.shipping_method)&&isSingle){const[shippingMethod]=(shipment==null?void 0:shipment.available_shipping_methods)||[];shippingMethod&&setShippingMethod(shipment.id,shippingMethod.id),typeof autoSelectSingleShippingMethod=="function"&&autoSelectSingleShippingMethod()}else setTimeout(()=>{setLoading(!1)},200)}))():setLoading(!1))},[shipments]);const components2=shipments&&shipments.map((shipment,k)=>{var _a,_b;const shipmentLineItems=shipment.shipment_line_items,lineItems=shipmentLineItems==null?void 0:shipmentLineItems.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?(_a=shippingMethods[0])===null||_a===void 0?void 0:_a.id:(_b=shipment.shipping_method)===null||_b===void 0?void 0:_b.id,stockTransfers=shipment.stock_transfers,times=deliveryLeadTimes==null?void 0:deliveryLeadTimes.filter(time=>{var _a2,_b2;return((_a2=time.stock_location)===null||_a2===void 0?void 0:_a2.id)===((_b2=shipment.stock_location)===null||_b2===void 0?void 0:_b2.id)}),shipmentProps={lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return _jsx(ShipmentChildrenContext.Provider,Object.assign({value:shipmentProps},{children}),k)});return loading?getLoaderComponent(loader):_jsx(_Fragment,{children:components2})}Shipment.propTypes=propTypes,Shipment.displayName=displayName;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShipmentContext from"../context/ShipmentContext";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";import components from"../config/components";import getLoaderComponent from"../utils/getLoaderComponent";const propTypes=components.Shipment.propTypes,displayName=components.Shipment.displayName;export default function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=useState(!0),{shipments,deliveryLeadTimes,setShippingMethod}=useContext(ShipmentContext);useEffect(()=>{shipments&&(autoSelectSingleShippingMethod?(async()=>await shipments.forEach(async shipment=>{const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];shippingMethod&&await setShippingMethod(shipment.id,shippingMethod.id),typeof autoSelectSingleShippingMethod=="function"&&autoSelectSingleShippingMethod()}else setTimeout(()=>{setLoading(!1)},200)}))():setLoading(!1))},[shipments]);const components2=shipments&&shipments.map((shipment,k)=>{const lineItems=shipment.shipment_line_items?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0]?.id:shipment.shipping_method?.id,stockTransfers=shipment.stock_transfers,times=deliveryLeadTimes?.filter(time=>time.stock_location?.id===shipment.stock_location?.id),shipmentProps={lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return _jsx(ShipmentChildrenContext.Provider,{value:shipmentProps,children},k)});return loading?getLoaderComponent(loader):_jsx(_Fragment,{children:components2})}Shipment.propTypes=propTypes,Shipment.displayName=displayName;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import get from"lodash/get";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";const propTypes=components.ShipmentField.propTypes,displayName=components.ShipmentField.displayName,ShipmentField=props=>{const{name}=props,{shipment,keyNumber}=useContext(ShipmentChildrenContext),key=name,text=key!=="key_number"?get(shipment,key):keyNumber,parentProps=Object.assign({shipment},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("span",Object.assign({},props,{children:text}))};ShipmentField.propTypes=propTypes,ShipmentField.displayName=displayName;export default ShipmentField;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import get from"lodash/get";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";const propTypes=components.ShipmentField.propTypes,displayName=components.ShipmentField.displayName,ShipmentField=props=>{const{name}=props,{shipment,keyNumber}=useContext(ShipmentChildrenContext),key=name,text=key!=="key_number"?get(shipment,key):keyNumber,parentProps={shipment,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...props,children:text})};ShipmentField.propTypes=propTypes,ShipmentField.displayName=displayName;export default ShipmentField;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import ShipmentContext,{defaultShipmentContext}from"../context/ShipmentContext";import{useContext,useEffect,useReducer}from"react";import shipmentReducer,{shipmentInitialState,setShipmentErrors,getShipments,setShippingMethod}from"../reducers/ShipmentReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{isEmpty}from"lodash";const propTypes=components.ShipmentsContainer.propTypes,displayName=components.ShipmentsContainer.displayName,ShipmentsContainer=props=>{const{children}=props,[state,dispatch]=useReducer(shipmentReducer,shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{(include==null?void 0:include.includes("shipments.available_shipping_methods"))?(includeLoaded==null?void 0:includeLoaded["shipments.available_shipping_methods"])||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.shipment_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.shipment_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),order&&!isEmpty(config)&&order.shipments&&getShipments({order,dispatch,config})},[order,include,includeLoaded]),useEffect(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&setShipmentErrors([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type})=>item_type==="skus").map(lineItem=>{var _a,_b,_c,_d;return!!(((_a=lineItem.item)===null||_a===void 0?void 0:_a.do_not_ship)||((_b=lineItem.item)===null||_b===void 0?void 0:_b.do_not_track)||((_d=(_c=lineItem.item)===null||_c===void 0?void 0:_c.inventory)===null||_d===void 0?void 0:_d.quantity)>=(lineItem==null?void 0:lineItem.quantity))}).includes(!1)&&setShipmentErrors([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{setShipmentErrors([],dispatch)}),[order==null?void 0:order.shipments]);const contextValue=Object.assign(Object.assign({},state),{setShipmentErrors:errors=>defaultShipmentContext.setShipmentErrors(errors,dispatch),setShippingMethod:async(shipmentId,shippingMethodId)=>await setShippingMethod({shippingMethodId,shipmentId,config,getOrder,order})});return _jsx(ShipmentContext.Provider,Object.assign({value:contextValue},{children}))};ShipmentsContainer.propTypes=propTypes,ShipmentsContainer.displayName=displayName;export default ShipmentsContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import ShipmentContext,{defaultShipmentContext}from"../context/ShipmentContext";import{useContext,useEffect,useReducer}from"react";import shipmentReducer,{shipmentInitialState,setShipmentErrors,getShipments,setShippingMethod}from"../reducers/ShipmentReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import{isEmpty}from"lodash";const propTypes=components.ShipmentsContainer.propTypes,displayName=components.ShipmentsContainer.displayName,ShipmentsContainer=props=>{const{children}=props,[state,dispatch]=useReducer(shipmentReducer,shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.shipment_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.shipment_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),order&&!isEmpty(config)&&order.shipments&&getShipments({order,dispatch,config})},[order,include,includeLoaded]),useEffect(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&setShipmentErrors([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type})=>item_type==="skus").map(lineItem=>!!(lineItem.item?.do_not_ship||lineItem.item?.do_not_track||lineItem.item?.inventory?.quantity>=lineItem?.quantity)).includes(!1)&&setShipmentErrors([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{setShipmentErrors([],dispatch)}),[order?.shipments]);const contextValue={...state,setShipmentErrors:errors=>defaultShipmentContext.setShipmentErrors(errors,dispatch),setShippingMethod:async(shipmentId,shippingMethodId)=>await setShippingMethod({shippingMethodId,shipmentId,config,getOrder,order})};return _jsx(ShipmentContext.Provider,{value:contextValue,children})};ShipmentsContainer.propTypes=propTypes,ShipmentsContainer.displayName=displayName;export default ShipmentsContainer;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import ShippingAddressContext from"../context/ShippingAddressContext";import{useContext,useEffect,useReducer}from"react";import shippingAddressReducer,{setShippingAddress,shippingAddressInitialState,setShippingCustomerAddressId}from"../reducers/ShippingAddressReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";const propTypes=components.ShippingAddressContainer.propTypes,ShippingAddressContainer=props=>{const{children}=props,[state,dispatch]=useReducer(shippingAddressReducer,shippingAddressInitialState),config=useContext(CommerceLayerContext),{order}=useContext(OrderContext),{setCloneAddress}=useContext(AddressContext);useEffect(()=>(order&&config&&setShippingCustomerAddressId({dispatch,order,setCloneAddress}),()=>{dispatch({type:"cleanup",payload:{}})}),[config,order]);const contextValue=Object.assign(Object.assign({},state),{setShippingAddress:async(id,options)=>{await setShippingAddress(id,{config,dispatch,order,customerAddressId:options==null?void 0:options.customerAddressId}),setCloneAddress(id,"shipping_address")}});return _jsx(ShippingAddressContext.Provider,Object.assign({value:contextValue},{children}))};ShippingAddressContainer.propTypes=propTypes;export default ShippingAddressContainer;
1
+ import{jsx as _jsx}from"react/jsx-runtime";import ShippingAddressContext from"../context/ShippingAddressContext";import{useContext,useEffect,useReducer}from"react";import shippingAddressReducer,{setShippingAddress,shippingAddressInitialState,setShippingCustomerAddressId}from"../reducers/ShippingAddressReducer";import CommerceLayerContext from"../context/CommerceLayerContext";import components from"../config/components";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";const propTypes=components.ShippingAddressContainer.propTypes,ShippingAddressContainer=props=>{const{children}=props,[state,dispatch]=useReducer(shippingAddressReducer,shippingAddressInitialState),config=useContext(CommerceLayerContext),{order}=useContext(OrderContext),{setCloneAddress}=useContext(AddressContext);useEffect(()=>(order&&config&&setShippingCustomerAddressId({dispatch,order,setCloneAddress}),()=>{dispatch({type:"cleanup",payload:{}})}),[config,order]);const contextValue={...state,setShippingAddress:async(id,options)=>{await setShippingAddress(id,{config,dispatch,order,customerAddressId:options?.customerAddressId}),setCloneAddress(id,"shipping_address")}};return _jsx(ShippingAddressContext.Provider,{value:contextValue,children})};ShippingAddressContainer.propTypes=propTypes;export default ShippingAddressContainer;