@commercelayer/react-components 4.8.0-beta.2 → 4.8.0-beta.4
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.
- package/lib/cjs/components/MetadataInput.d.ts +1 -0
- package/lib/cjs/components/addresses/Address.d.ts +18 -0
- package/lib/cjs/components/addresses/AddressCountrySelector.d.ts +24 -0
- package/lib/cjs/components/addresses/AddressCountrySelector.js +1 -1
- package/lib/cjs/components/addresses/AddressField.d.ts +22 -0
- package/lib/cjs/components/addresses/AddressInput.d.ts +19 -0
- package/lib/cjs/components/addresses/AddressInput.js +1 -1
- package/lib/cjs/components/addresses/AddressStateSelector.d.ts +26 -0
- package/lib/cjs/components/addresses/AddressStateSelector.js +1 -1
- package/lib/cjs/components/addresses/AddressesContainer.d.ts +22 -0
- package/lib/cjs/components/addresses/AddressesEmpty.d.ts +13 -0
- package/lib/cjs/components/addresses/BillingAddressForm.d.ts +20 -0
- package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
- package/lib/cjs/components/addresses/ShippingAddressContainer.d.ts +1 -0
- package/lib/cjs/components/addresses/ShippingAddressForm.d.ts +17 -0
- package/lib/cjs/components/auth/CommerceLayer.d.ts +1 -0
- package/lib/cjs/components/customers/CustomerAddressForm.d.ts +5 -0
- package/lib/cjs/components/customers/CustomerAddressForm.js +1 -1
- package/lib/cjs/components/customers/CustomerContainer.d.ts +20 -1
- package/lib/cjs/components/customers/CustomerField.d.ts +16 -0
- package/lib/cjs/components/customers/CustomerInput.d.ts +1 -0
- package/lib/cjs/components/customers/CustomerInput.js +1 -1
- package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +1 -0
- package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
- package/lib/cjs/components/customers/MyAccountLink.d.ts +11 -0
- package/lib/cjs/components/customers/MyIdentityLink.d.ts +16 -0
- package/lib/cjs/components/customers/MyIdentityLink.js +1 -1
- package/lib/cjs/components/errors/Errors.d.ts +1 -0
- package/lib/cjs/components/errors/Errors.js +1 -1
- package/lib/cjs/components/gift_cards/GiftCard.d.ts +1 -0
- package/lib/cjs/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
- package/lib/cjs/components/gift_cards/GiftCardInput.d.ts +1 -0
- package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
- package/lib/cjs/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
- package/lib/cjs/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
- package/lib/cjs/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItem.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItem.js +1 -1
- package/lib/cjs/components/line_items/LineItemAmount.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemAmount.js +1 -1
- package/lib/cjs/components/line_items/LineItemBundleSkuField.d.ts +24 -0
- package/lib/cjs/components/line_items/LineItemBundleSkuField.js +2 -0
- package/lib/cjs/components/line_items/LineItemBundleSkus.d.ts +6 -0
- package/lib/cjs/components/line_items/LineItemBundleSkus.js +2 -0
- package/lib/cjs/components/line_items/LineItemCode.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemCode.js +1 -1
- package/lib/cjs/components/line_items/LineItemField.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemImage.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemImage.js +1 -1
- package/lib/cjs/components/line_items/LineItemName.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemName.js +1 -1
- package/lib/cjs/components/line_items/LineItemQuantity.d.ts +5 -0
- package/lib/cjs/components/line_items/LineItemQuantity.js +1 -1
- package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
- package/lib/cjs/components/line_items/LineItemsContainer.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
- package/lib/cjs/components/line_items/LineItemsCount.d.ts +1 -0
- package/lib/cjs/components/line_items/LineItemsCount.js +1 -1
- package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +1 -0
- package/lib/cjs/components/orders/AddToCartButton.d.ts +32 -0
- package/lib/cjs/components/orders/AdjustmentAmount.d.ts +1 -0
- package/lib/cjs/components/orders/CartLink.d.ts +8 -0
- package/lib/cjs/components/orders/CartLink.js +1 -1
- package/lib/cjs/components/orders/CheckoutLink.d.ts +16 -0
- package/lib/cjs/components/orders/DiscountAmount.d.ts +1 -0
- package/lib/cjs/components/orders/GiftCardAmount.d.ts +1 -0
- package/lib/cjs/components/orders/HostedCart.d.ts +30 -8
- package/lib/cjs/components/orders/HostedCart.js +1 -1
- package/lib/cjs/components/orders/OrderContainer.d.ts +34 -0
- package/lib/cjs/components/orders/OrderContainer.js +1 -1
- package/lib/cjs/components/orders/OrderList.d.ts +1 -0
- package/lib/cjs/components/orders/OrderList.js +1 -1
- package/lib/cjs/components/orders/OrderListEmpty.d.ts +1 -0
- package/lib/cjs/components/orders/OrderListPaginationButtons.d.ts +1 -0
- package/lib/cjs/components/orders/OrderListPaginationInfo.d.ts +1 -0
- package/lib/cjs/components/orders/OrderListRow.d.ts +1 -0
- package/lib/cjs/components/orders/OrderNumber.d.ts +1 -0
- package/lib/cjs/components/orders/OrderStorage.d.ts +23 -0
- package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +1 -0
- package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
- package/lib/cjs/components/orders/ShippingAmount.d.ts +1 -0
- package/lib/cjs/components/orders/SubTotalAmount.d.ts +1 -0
- package/lib/cjs/components/orders/TaxesAmount.d.ts +1 -0
- package/lib/cjs/components/orders/TotalAmount.d.ts +1 -0
- package/lib/cjs/components/parcels/ParcelField.d.ts +1 -0
- package/lib/cjs/components/parcels/ParcelLineItem.d.ts +1 -0
- package/lib/cjs/components/parcels/ParcelLineItemField.d.ts +1 -0
- package/lib/cjs/components/parcels/ParcelLineItemsCount.d.ts +1 -0
- package/lib/cjs/components/parcels/Parcels.d.ts +1 -0
- package/lib/cjs/components/parcels/ParcelsCount.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/AdyenGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/BraintreeGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/ExternalGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/KlarnaGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/PaymentGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/PaymentGateway.js +1 -1
- package/lib/cjs/components/payment_gateways/PaypalGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/StripeGateway.d.ts +1 -0
- package/lib/cjs/components/payment_gateways/WireTransferGateway.d.ts +1 -0
- package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +1 -0
- package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +1 -0
- package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
- package/lib/cjs/components/payment_source/BraintreePayment.d.ts +1 -0
- package/lib/cjs/components/payment_source/CheckoutComPayment.d.ts +1 -0
- package/lib/cjs/components/payment_source/ExternalPayment.d.ts +1 -0
- package/lib/cjs/components/payment_source/ExternalPayment.js +1 -1
- package/lib/cjs/components/payment_source/KlarnaPayment.d.ts +1 -0
- package/lib/cjs/components/payment_source/KlarnaPayment.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSource.d.ts +1 -0
- package/lib/cjs/components/payment_source/PaymentSource.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
- package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
- package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +1 -0
- package/lib/cjs/components/payment_source/StripeExpressPayment.d.ts +1 -0
- package/lib/cjs/components/payment_source/StripePayment.d.ts +1 -0
- package/lib/cjs/components/payment_source/WireTransferPayment.d.ts +1 -0
- package/lib/cjs/components/prices/Price.d.ts +1 -0
- package/lib/cjs/components/prices/PricesContainer.d.ts +1 -0
- package/lib/cjs/components/shipments/ShipmentField.d.ts +1 -0
- package/lib/cjs/components/shipments/ShipmentsCount.d.ts +1 -0
- package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +1 -0
- package/lib/cjs/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
- package/lib/cjs/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
- package/lib/cjs/components/skus/AvailabilityContainer.d.ts +27 -1
- package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
- package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +17 -3
- package/lib/cjs/components/skus/DeliveryLeadTime.d.ts +1 -0
- package/lib/cjs/components/skus/SkuField.d.ts +14 -2
- package/lib/cjs/components/skus/Skus.d.ts +12 -0
- package/lib/cjs/components/skus/SkusContainer.d.ts +14 -1
- package/lib/cjs/components/stock_transfers/StockTransfer.d.ts +1 -0
- package/lib/cjs/components/stock_transfers/StockTransferField.d.ts +1 -0
- package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +1 -0
- package/lib/cjs/components/utils/BaseOrderPrice.d.ts +1 -0
- package/lib/cjs/components/utils/GenericFieldComponent.d.ts +6 -0
- package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +1 -0
- package/lib/cjs/components/utils/PriceTemplate.d.ts +1 -0
- package/lib/cjs/components/utils/getAllErrors.d.ts +1 -0
- package/lib/cjs/context/LineItemBundleChildrenContext.d.ts +11 -0
- package/lib/cjs/context/LineItemBundleChildrenContext.js +2 -0
- package/lib/cjs/context/LineItemBundleSkuChildrenContext.d.ts +9 -0
- package/lib/cjs/context/LineItemBundleSkuChildrenContext.js +2 -0
- package/lib/cjs/reducers/AddressReducer.js +1 -1
- package/lib/cjs/reducers/AvailabilityReducer.d.ts +3 -2
- package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
- package/lib/cjs/reducers/CustomerReducer.d.ts +1 -1
- package/lib/cjs/reducers/CustomerReducer.js +1 -1
- package/lib/cjs/reducers/LineItemReducer.d.ts +2 -1
- package/lib/cjs/reducers/LineItemReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.d.ts +1 -1
- package/lib/cjs/typings/globals.d.ts +1 -0
- package/lib/cjs/utils/addressesManager.d.ts +5 -4
- package/lib/cjs/utils/addressesManager.js +1 -1
- package/lib/cjs/utils/countryStateCity.d.ts +798 -5
- package/lib/cjs/utils/countryStateCity.js +1 -1
- package/lib/cjs/utils/filterChildren.d.ts +1 -0
- package/lib/cjs/utils/getLoaderComponent.d.ts +1 -0
- package/lib/cjs/utils/getPrices.d.ts +1 -0
- package/lib/cjs/utils/validateFormFields.d.ts +1 -1
- package/lib/cjs/utils/validateFormFields.js +1 -1
- package/lib/esm/components/MetadataInput.d.ts +1 -0
- package/lib/esm/components/addresses/Address.d.ts +18 -0
- package/lib/esm/components/addresses/AddressCountrySelector.d.ts +24 -0
- package/lib/esm/components/addresses/AddressCountrySelector.js +1 -1
- package/lib/esm/components/addresses/AddressField.d.ts +22 -0
- package/lib/esm/components/addresses/AddressInput.d.ts +19 -0
- package/lib/esm/components/addresses/AddressInput.js +1 -1
- package/lib/esm/components/addresses/AddressStateSelector.d.ts +26 -0
- package/lib/esm/components/addresses/AddressStateSelector.js +1 -1
- package/lib/esm/components/addresses/AddressesContainer.d.ts +22 -0
- package/lib/esm/components/addresses/AddressesEmpty.d.ts +13 -0
- package/lib/esm/components/addresses/BillingAddressForm.d.ts +20 -0
- package/lib/esm/components/addresses/SaveAddressesButton.js +1 -1
- package/lib/esm/components/addresses/ShippingAddressContainer.d.ts +1 -0
- package/lib/esm/components/addresses/ShippingAddressForm.d.ts +17 -0
- package/lib/esm/components/auth/CommerceLayer.d.ts +1 -0
- package/lib/esm/components/customers/CustomerAddressForm.d.ts +5 -0
- package/lib/esm/components/customers/CustomerAddressForm.js +1 -1
- package/lib/esm/components/customers/CustomerContainer.d.ts +20 -1
- package/lib/esm/components/customers/CustomerField.d.ts +16 -0
- package/lib/esm/components/customers/CustomerInput.d.ts +1 -0
- package/lib/esm/components/customers/CustomerInput.js +1 -1
- package/lib/esm/components/customers/CustomerPaymentSource.d.ts +1 -0
- package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +1 -0
- package/lib/esm/components/customers/MyAccountLink.d.ts +11 -0
- package/lib/esm/components/customers/MyIdentityLink.d.ts +16 -0
- package/lib/esm/components/customers/MyIdentityLink.js +1 -1
- package/lib/esm/components/errors/Errors.d.ts +1 -0
- package/lib/esm/components/errors/Errors.js +1 -1
- package/lib/esm/components/gift_cards/GiftCard.d.ts +1 -0
- package/lib/esm/components/gift_cards/GiftCardCurrencySelector.d.ts +1 -0
- package/lib/esm/components/gift_cards/GiftCardInput.d.ts +1 -0
- package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +1 -0
- package/lib/esm/components/gift_cards/GiftCardOrCouponForm.d.ts +1 -0
- package/lib/esm/components/gift_cards/GiftCardOrCouponInput.d.ts +1 -0
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionButton.d.ts +1 -0
- package/lib/esm/components/in_stock_subscriptions/InStockSubscriptionsContainer.d.ts +1 -0
- package/lib/esm/components/line_items/LineItem.d.ts +1 -0
- package/lib/esm/components/line_items/LineItem.js +1 -1
- package/lib/esm/components/line_items/LineItemAmount.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemAmount.js +1 -1
- package/lib/esm/components/line_items/LineItemBundleSkuField.d.ts +24 -0
- package/lib/esm/components/line_items/LineItemBundleSkuField.js +2 -0
- package/lib/esm/components/line_items/LineItemBundleSkus.d.ts +6 -0
- package/lib/esm/components/line_items/LineItemBundleSkus.js +2 -0
- package/lib/esm/components/line_items/LineItemCode.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemCode.js +1 -1
- package/lib/esm/components/line_items/LineItemField.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemImage.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemImage.js +1 -1
- package/lib/esm/components/line_items/LineItemName.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemName.js +1 -1
- package/lib/esm/components/line_items/LineItemQuantity.d.ts +5 -0
- package/lib/esm/components/line_items/LineItemQuantity.js +1 -1
- package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -1
- package/lib/esm/components/line_items/LineItemsContainer.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemsContainer.js +1 -1
- package/lib/esm/components/line_items/LineItemsCount.d.ts +1 -0
- package/lib/esm/components/line_items/LineItemsCount.js +1 -1
- package/lib/esm/components/line_items/LineItemsEmpty.d.ts +1 -0
- package/lib/esm/components/orders/AddToCartButton.d.ts +32 -0
- package/lib/esm/components/orders/AdjustmentAmount.d.ts +1 -0
- package/lib/esm/components/orders/CartLink.d.ts +8 -0
- package/lib/esm/components/orders/CartLink.js +1 -1
- package/lib/esm/components/orders/CheckoutLink.d.ts +16 -0
- package/lib/esm/components/orders/DiscountAmount.d.ts +1 -0
- package/lib/esm/components/orders/GiftCardAmount.d.ts +1 -0
- package/lib/esm/components/orders/HostedCart.d.ts +30 -8
- package/lib/esm/components/orders/HostedCart.js +1 -1
- package/lib/esm/components/orders/OrderContainer.d.ts +34 -0
- package/lib/esm/components/orders/OrderContainer.js +1 -1
- package/lib/esm/components/orders/OrderList.d.ts +1 -0
- package/lib/esm/components/orders/OrderList.js +1 -1
- package/lib/esm/components/orders/OrderListEmpty.d.ts +1 -0
- package/lib/esm/components/orders/OrderListPaginationButtons.d.ts +1 -0
- package/lib/esm/components/orders/OrderListPaginationInfo.d.ts +1 -0
- package/lib/esm/components/orders/OrderListRow.d.ts +1 -0
- package/lib/esm/components/orders/OrderNumber.d.ts +1 -0
- package/lib/esm/components/orders/OrderStorage.d.ts +23 -0
- package/lib/esm/components/orders/PaymentMethodAmount.d.ts +1 -0
- package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +1 -0
- package/lib/esm/components/orders/ShippingAmount.d.ts +1 -0
- package/lib/esm/components/orders/SubTotalAmount.d.ts +1 -0
- package/lib/esm/components/orders/TaxesAmount.d.ts +1 -0
- package/lib/esm/components/orders/TotalAmount.d.ts +1 -0
- package/lib/esm/components/parcels/ParcelField.d.ts +1 -0
- package/lib/esm/components/parcels/ParcelLineItem.d.ts +1 -0
- package/lib/esm/components/parcels/ParcelLineItemField.d.ts +1 -0
- package/lib/esm/components/parcels/ParcelLineItemsCount.d.ts +1 -0
- package/lib/esm/components/parcels/Parcels.d.ts +1 -0
- package/lib/esm/components/parcels/ParcelsCount.d.ts +1 -0
- package/lib/esm/components/payment_gateways/AdyenGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/BraintreeGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/CheckoutComGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/ExternalGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/KlarnaGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/PaymentGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/PaymentGateway.js +1 -1
- package/lib/esm/components/payment_gateways/PaypalGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/StripeGateway.d.ts +1 -0
- package/lib/esm/components/payment_gateways/WireTransferGateway.d.ts +1 -0
- package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -0
- package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +1 -0
- package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +1 -0
- package/lib/esm/components/payment_source/BraintreePayment.d.ts +1 -0
- package/lib/esm/components/payment_source/CheckoutComPayment.d.ts +1 -0
- package/lib/esm/components/payment_source/ExternalPayment.d.ts +1 -0
- package/lib/esm/components/payment_source/ExternalPayment.js +1 -1
- package/lib/esm/components/payment_source/KlarnaPayment.d.ts +1 -0
- package/lib/esm/components/payment_source/KlarnaPayment.js +1 -1
- package/lib/esm/components/payment_source/PaymentSource.d.ts +1 -0
- package/lib/esm/components/payment_source/PaymentSource.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +1 -0
- package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +1 -0
- package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +1 -0
- package/lib/esm/components/payment_source/StripeExpressPayment.d.ts +1 -0
- package/lib/esm/components/payment_source/StripePayment.d.ts +1 -0
- package/lib/esm/components/payment_source/WireTransferPayment.d.ts +1 -0
- package/lib/esm/components/prices/Price.d.ts +1 -0
- package/lib/esm/components/prices/PricesContainer.d.ts +1 -0
- package/lib/esm/components/shipments/ShipmentField.d.ts +1 -0
- package/lib/esm/components/shipments/ShipmentsCount.d.ts +1 -0
- package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +1 -0
- package/lib/esm/components/shipping_methods/ShippingMethodPrice.d.ts +1 -0
- package/lib/esm/components/shipping_methods/ShippingMethodRadioButton.d.ts +1 -0
- package/lib/esm/components/skus/AvailabilityContainer.d.ts +27 -1
- package/lib/esm/components/skus/AvailabilityContainer.js +1 -1
- package/lib/esm/components/skus/AvailabilityTemplate.d.ts +17 -3
- package/lib/esm/components/skus/DeliveryLeadTime.d.ts +1 -0
- package/lib/esm/components/skus/SkuField.d.ts +14 -2
- package/lib/esm/components/skus/Skus.d.ts +12 -0
- package/lib/esm/components/skus/SkusContainer.d.ts +14 -1
- package/lib/esm/components/stock_transfers/StockTransfer.d.ts +1 -0
- package/lib/esm/components/stock_transfers/StockTransferField.d.ts +1 -0
- package/lib/esm/components/utils/AddressCardsTemplate.d.ts +1 -0
- package/lib/esm/components/utils/BaseOrderPrice.d.ts +1 -0
- package/lib/esm/components/utils/GenericFieldComponent.d.ts +6 -0
- package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +1 -0
- package/lib/esm/components/utils/PriceTemplate.d.ts +1 -0
- package/lib/esm/components/utils/getAllErrors.d.ts +1 -0
- package/lib/esm/context/LineItemBundleChildrenContext.d.ts +11 -0
- package/lib/esm/context/LineItemBundleChildrenContext.js +2 -0
- package/lib/esm/context/LineItemBundleSkuChildrenContext.d.ts +9 -0
- package/lib/esm/context/LineItemBundleSkuChildrenContext.js +2 -0
- package/lib/esm/reducers/AddressReducer.js +1 -1
- package/lib/esm/reducers/AvailabilityReducer.d.ts +3 -2
- package/lib/esm/reducers/AvailabilityReducer.js +1 -1
- package/lib/esm/reducers/CustomerReducer.d.ts +1 -1
- package/lib/esm/reducers/CustomerReducer.js +1 -1
- package/lib/esm/reducers/LineItemReducer.d.ts +2 -1
- package/lib/esm/reducers/LineItemReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.d.ts +1 -1
- package/lib/esm/typings/globals.d.ts +1 -0
- package/lib/esm/utils/addressesManager.d.ts +5 -4
- package/lib/esm/utils/addressesManager.js +1 -1
- package/lib/esm/utils/countryStateCity.d.ts +798 -5
- package/lib/esm/utils/countryStateCity.js +1 -1
- package/lib/esm/utils/filterChildren.d.ts +1 -0
- package/lib/esm/utils/getLoaderComponent.d.ts +1 -0
- package/lib/esm/utils/getPrices.d.ts +1 -0
- package/lib/esm/utils/validateFormFields.d.ts +1 -1
- package/lib/esm/utils/validateFormFields.js +1 -1
- package/package.json +2 -4
- package/lib/cjs/utils/isEmptyStates.d.ts +0 -1
- package/lib/cjs/utils/isEmptyStates.js +0 -2
- package/lib/esm/utils/isEmptyStates.d.ts +0 -1
- package/lib/esm/utils/isEmptyStates.js +0 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { type ChildrenFunction } from '../../typings/index';
|
|
2
3
|
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
3
4
|
/**
|
|
@@ -35,5 +36,20 @@ interface Props extends Omit<JSX.IntrinsicElements['a'], 'children'> {
|
|
|
35
36
|
*/
|
|
36
37
|
customDomain?: string;
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* This component generates a link to the hosted mfe-identity application.
|
|
41
|
+
*
|
|
42
|
+
* In this way you can connect your shop application with our hosted micro-frontend and let your customers manage their account with zero code.
|
|
43
|
+
*
|
|
44
|
+
* <span title="Requirement" type="warning">
|
|
45
|
+
* Must be a child of the `<CommerceLayer>` component.
|
|
46
|
+
* </span>
|
|
47
|
+
*
|
|
48
|
+
* <span title="My Identity" type="info">
|
|
49
|
+
* The Commerce Layer Identity micro frontend (React) provides you with an application, powered by Commerce Layer APIs, handling customer login and sign-up functionalities
|
|
50
|
+
* </span>
|
|
51
|
+
*
|
|
52
|
+
* @link https://github.com/commercelayer/mfe-identity
|
|
53
|
+
*/
|
|
38
54
|
export declare function MyIdentityLink(props: Props): JSX.Element;
|
|
39
55
|
export default MyIdentityLink;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";export function MyIdentityLink(props){const{label,children,type,clientId,scope,returnUrl,customDomain,...p}=props,{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null||endpoint==null)throw new Error("Cannot use `MyIdentityLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint)
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";export function MyIdentityLink(props){const{label,children,type,clientId,scope,returnUrl,customDomain,...p}=props,{accessToken,endpoint}=useContext(CommerceLayerContext),[href,setHref]=useState(void 0);if(accessToken==null||endpoint==null)throw new Error("Cannot use `MyIdentityLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint);useEffect(()=>{const link=getApplicationLink({slug,accessToken,applicationType:"identity",domain,modeType:type,clientId,scope,returnUrl:returnUrl??window.location.href,customDomain});return setHref(link),()=>{setHref(void 0)}},[]);const parentProps={label,href,clientId,scope,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,children:label})}export default MyIdentityLink;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { CodeErrorType } from '../../typings/errors';
|
|
2
3
|
import { type ChildrenFunction } from '../../typings/index';
|
|
3
4
|
export type TResourceError = 'addresses' | 'billing_address' | 'gift_cards' | 'gift_card_or_coupon_code' | 'line_items' | 'orders' | 'payment_methods' | 'prices' | 'shipments' | 'shipping_address' | 'customer_address' | 'sku_options' | 'variant' | 'in_stock_subscriptions';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useMemo}from"react";import Parent from"../utils/Parent";import GiftCardContext from"../../context/GiftCardContext";import OrderContext from"../../context/OrderContext";import AddressContext from"../../context/AddressContext";import getAllErrors from"../utils/getAllErrors";import LineItemContext from"../../context/LineItemContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import CustomerContext from"../../context/CustomerContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import ShipmentContext from"../../context/ShipmentContext";import InStockSubscriptionContext from"../../context/InStockSubscriptionContext";export function Errors(props){const{children,messages=[],resource,field,...p}=props,{payment}=useContext(PaymentMethodChildrenContext),{errors:orderErrors}=useContext(OrderContext),{errors:giftCardErrors}=useContext(GiftCardContext),{errors:lineItemErrors}=useContext(LineItemContext),{errors:addressErrors}=useContext(AddressContext),{errors:customerErrors}=useContext(CustomerContext),{errors:shipmentErrors}=useContext(ShipmentContext),{errors:inStockSubscriptionErrors}=useContext(InStockSubscriptionContext),{errors:paymentMethodErrors,currentPaymentMethodType,currentPaymentMethodId}=useContext(PaymentMethodContext),{lineItem}=useContext(LineItemChildrenContext),allErrors=useMemo(()=>[...giftCardErrors||[],...orderErrors||[],...lineItemErrors||[],...
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useMemo}from"react";import Parent from"../utils/Parent";import GiftCardContext from"../../context/GiftCardContext";import OrderContext from"../../context/OrderContext";import AddressContext from"../../context/AddressContext";import getAllErrors from"../utils/getAllErrors";import LineItemContext from"../../context/LineItemContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import CustomerContext from"../../context/CustomerContext";import PaymentMethodContext from"../../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../../context/PaymentMethodChildrenContext";import ShipmentContext from"../../context/ShipmentContext";import InStockSubscriptionContext from"../../context/InStockSubscriptionContext";export function Errors(props){const{children,messages=[],resource,field,...p}=props,{payment}=useContext(PaymentMethodChildrenContext),{errors:orderErrors}=useContext(OrderContext),{errors:giftCardErrors}=useContext(GiftCardContext),{errors:lineItemErrors}=useContext(LineItemContext),{errors:addressErrors}=useContext(AddressContext),{errors:customerErrors}=useContext(CustomerContext),{errors:shipmentErrors}=useContext(ShipmentContext),{errors:inStockSubscriptionErrors}=useContext(InStockSubscriptionContext),{errors:paymentMethodErrors,currentPaymentMethodType,currentPaymentMethodId}=useContext(PaymentMethodContext),{lineItem}=useContext(LineItemChildrenContext),allErrors=useMemo(()=>[...giftCardErrors||[],...orderErrors||[],...lineItemErrors||[],...customerErrors||[],...shipmentErrors||[],...inStockSubscriptionErrors||[],...paymentMethodErrors?.filter(v=>v.field===currentPaymentMethodType&&payment?.id===currentPaymentMethodId)||[]],[giftCardErrors,orderErrors,lineItemErrors,customerErrors,shipmentErrors,inStockSubscriptionErrors,paymentMethodErrors]).filter((v,k,a)=>v?.code!==a[k-1]?.code),addressesErrors=useMemo(()=>[...addressErrors||[]],[addressErrors]),msgErrors=getAllErrors({allErrors:[...allErrors,...addressesErrors],field,messages,props:p,lineItem,resource,returnHtml:!children}),parentProps={messages,resource,field,errors:msgErrors,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx(_Fragment,{children:msgErrors})}export default Errors;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
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 ShipmentChildrenContext from"../../context/ShipmentChildrenContext";export function LineItem(props){const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),components=(shipmentLineItems&&shipmentLineItems?.length>0?shipmentLineItems:lineItems)?.filter(l=>l?.item_type===type).map(
|
|
2
|
+
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 ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItem(props){const{type="skus",children}=props,{lineItems}=useContext(LineItemContext),{lineItems:shipmentLineItems}=useContext(ShipmentChildrenContext),components=(shipmentLineItems&&shipmentLineItems?.length>0?shipmentLineItems:lineItems)?.filter(l=>l?.item_type===type).map(lineItem=>{if(lineItem?.item_type==="bundles"){const skuListItemsProps={skuListItems:lineItem?.bundle?.sku_list?.sku_list_items,lineItem};return _jsx(LineItemBundleChildrenContext.Provider,{value:skuListItemsProps,children},lineItem?.id)}if(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},lineItem?.id)});return _jsx(_Fragment,{children:components})}export default LineItem;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
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";export function LineItemAmount(props){const{format="formatted",type="total",...p}=props,{lineItem}=useContext(LineItemChildrenContext),[price,setPrice]=useState("");useEffect(()=>{if(
|
|
2
|
+
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 LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItemAmount(props){const{format="formatted",type="total",...p}=props,{lineItem}=useContext(LineItemChildrenContext),{lineItem:lineItemBundle}=useContext(LineItemBundleChildrenContext),[price,setPrice]=useState(""),item=lineItem??lineItemBundle;useEffect(()=>{if(item){const p2=getAmount({base:"amount",type,format,obj:item});setPrice(p2)}return()=>{setPrice("")}},[item]);const parentProps={price,...p};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("span",{...p,children:price})}export default LineItemAmount;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { LineItem, Sku, SkuListItem } from '@commercelayer/sdk';
|
|
3
|
+
import { type ChildrenFunction } from '../../typings/index';
|
|
4
|
+
type SkuAttribute = Extract<keyof Sku, 'code' | 'image_url' | 'description' | 'name' | 'pieces_per_pack' | 'weight' | 'unit_of_weight'>;
|
|
5
|
+
type SkuListItemAttribute = Extract<keyof SkuListItem, 'quantity'>;
|
|
6
|
+
type Attribute = SkuListItemAttribute | SkuAttribute;
|
|
7
|
+
type TagElementKey = Extract<keyof JSX.IntrinsicElements, 'p' | 'span' | 'div' | 'img'>;
|
|
8
|
+
export interface TLineItemBundleSkuField extends Omit<Props, 'children'> {
|
|
9
|
+
lineItem: LineItem;
|
|
10
|
+
skuListItem: SkuListItem;
|
|
11
|
+
}
|
|
12
|
+
type ImageElement = Omit<JSX.IntrinsicElements[Extract<TagElementKey, 'img'>], 'children' | 'ref'>;
|
|
13
|
+
type OtherElements = Omit<JSX.IntrinsicElements[Exclude<TagElementKey, 'img'>], 'children' | 'ref'>;
|
|
14
|
+
type Props = {
|
|
15
|
+
children?: ChildrenFunction<TLineItemBundleSkuField>;
|
|
16
|
+
} & (({
|
|
17
|
+
attribute: 'image_url';
|
|
18
|
+
tagElement: 'img';
|
|
19
|
+
} & ImageElement) | ({
|
|
20
|
+
attribute: Exclude<Attribute, 'image_url'>;
|
|
21
|
+
tagElement?: Exclude<TagElementKey, 'img'>;
|
|
22
|
+
} & OtherElements));
|
|
23
|
+
export declare function LineItemBundleSkuField({ tagElement, attribute, children, ...props }: Props): JSX.Element;
|
|
24
|
+
export default LineItemBundleSkuField;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import LineItemBundleSkuChildrenContext from"../../context/LineItemBundleSkuChildrenContext";export function LineItemBundleSkuField({tagElement="span",attribute,children,...props}){const{skuListItem}=useContext(LineItemBundleSkuChildrenContext),item=skuListItem;let attr=null;attribute==="quantity"?attr=item?.quantity:attr=item?.sku?.[attribute];const TagElement=tagElement,parentProps={attribute:attr,lineItem:item,...props};return attribute==="image_url"&&children==null?_jsx("img",{alt:"","data-testid":`line-item-bundle-sku-field-image-${item?.sku_code??""}`,src:`${attr}`??null,...props}):children?_jsx(Parent,{...parentProps,children}):_jsx(TagElement,{"data-testid":`line-item-bundle-sku-field-${item?.sku_code??""}`,...props,children:attr})}export default LineItemBundleSkuField;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext}from"react";import LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";import LineItemBundleSkuChildrenContext from"../../context/LineItemBundleSkuChildrenContext";export function LineItemBundleSkus({children}){const{lineItem,skuListItems}=useContext(LineItemBundleChildrenContext),components=skuListItems?.map(skuListItem=>{const quantity=skuListItem?.quantity!=null&&lineItem?.quantity?skuListItem?.quantity*lineItem?.quantity:0,skuListProps={skuListItem:{...skuListItem,quantity}};return _jsx(LineItemBundleSkuChildrenContext.Provider,{value:skuListProps,children},skuListItem.id)});return _jsx(_Fragment,{children:components})}export default LineItemBundleSkus;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function 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})}export default LineItemCode;
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";import LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItemCode({type="sku_code",children,...p}){const{lineItem}=useContext(LineItemChildrenContext),{lineItem:lineItemBundle}=useContext(LineItemBundleChildrenContext),labelName=lineItem?.[type]??lineItemBundle?.[type],parentProps={lineItem,skuCode:labelName,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("p",{...p,children:labelName})}export default LineItemCode;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { type ConditionalElement } from '../../typings/index';
|
|
2
3
|
import { type TGenericChildrenProps, type TResources } from '../utils/GenericFieldComponent';
|
|
3
4
|
type LineItemFieldChildrenProps = TGenericChildrenProps<TResources['LineItem']>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import{defaultGiftCardImgUrl,defaultImgUrl}from"../../utils/placeholderImages";import Parent from"../utils/Parent";export function LineItemImage(props){const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),itemType=
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import{defaultGiftCardImgUrl,defaultImgUrl}from"../../utils/placeholderImages";import Parent from"../utils/Parent";import LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItemImage(props){const{placeholder,children,...p}=props,{lineItem}=useContext(LineItemChildrenContext),{lineItem:lineItemBundle}=useContext(LineItemBundleChildrenContext),item=lineItem??lineItemBundle,itemType=item?.item_type;let src=item?.image_url;src||(placeholder?.[itemType]?src=placeholder?.[itemType]:src=itemType==="gift_cards"?defaultGiftCardImgUrl:defaultImgUrl);const parenProps={lineItem:item,src,placeholder,...p};return children?_jsx(Parent,{...parenProps,children}):src?_jsx("img",{"data-testid":`line-item-image-${item?.sku_code??""}`,alt:item?.name??"",src,...p}):null}export default LineItemImage;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";export function LineItemName(props){const{lineItem}=useContext(LineItemChildrenContext),label=
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import Parent from"../utils/Parent";import LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItemName(props){const{lineItem}=useContext(LineItemChildrenContext),{lineItem:listItemBundle}=useContext(LineItemBundleChildrenContext),item=lineItem??listItemBundle,label=item?.name,parentProps={label,lineItem:item,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("p",{"data-testid":`line-item-name-${item?.sku_code??""}`,...props,children:label})}export default LineItemName;
|
|
@@ -11,6 +11,11 @@ type Props = {
|
|
|
11
11
|
max?: number;
|
|
12
12
|
disabled?: boolean;
|
|
13
13
|
readonly?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* force the update of the line item price using `_external_price: true` attribute
|
|
16
|
+
* @link https://docs.commercelayer.io/core/external-resources/external-prices
|
|
17
|
+
*/
|
|
18
|
+
hasExternalPrice?: boolean;
|
|
14
19
|
} & (Omit<JSX.IntrinsicElements['select'], 'children'> & Omit<JSX.IntrinsicElements['span'], 'children'>);
|
|
15
20
|
export declare function LineItemQuantity(props: Props): JSX.Element;
|
|
16
21
|
export default LineItemQuantity;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
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";export function 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&&
|
|
2
|
+
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 LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItemQuantity(props){const{max=50,readonly=!1,hasExternalPrice,...p}=props,{lineItem}=useContext(LineItemChildrenContext),{lineItem:lineItemBundle}=useContext(LineItemBundleChildrenContext),{updateLineItem}=useContext(LineItemContext),item=lineItem??lineItemBundle,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&&item&&updateLineItem(item.id,quantity2,hasExternalPrice)},quantity=item?.quantity,parentProps={handleChange,quantity,lineItem:item,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):readonly?_jsx("span",{...p,children:quantity}):_jsx("select",{"data-testid":item?.sku_code,title:item?.name??"",value:quantity,onChange:handleChange,...p,children:options})}export default LineItemQuantity;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
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 useCustomContext from"../../utils/hooks/useCustomContext";export function LineItemRemoveLink(props){const{label="Remove",onClick}=props,{lineItem}=useCustomContext({context:LineItemChildrenContext,contextComponentName:"LineItem",currentComponentName:"LineItemRemoveLink",key:"lineItem"}),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem!=null&&
|
|
2
|
+
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 useCustomContext from"../../utils/hooks/useCustomContext";import LineItemBundleChildrenContext from"../../context/LineItemBundleChildrenContext";export function LineItemRemoveLink(props){const{label="Remove",onClick}=props,{lineItem}=useCustomContext({context:LineItemChildrenContext,contextComponentName:"LineItem",currentComponentName:"LineItemRemoveLink",key:"lineItem"}),{lineItem:lineItemBundle}=useContext(LineItemBundleChildrenContext),{deleteLineItem}=useContext(LineItemContext),item=lineItem??lineItemBundle,lineItemId=item?.id,handleRemove=e=>{e.preventDefault(),deleteLineItem!=null&&lineItemId!=null&&deleteLineItem(lineItemId),onClick?.(e)},parentProps={handleRemove,lineItem:item,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("a",{"data-testid":`line-item-remove-link-${item?.sku_code??""}`,...props,href:"#",onClick:handleRemove,children:label})}export default LineItemRemoveLink;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
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";export function 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:async(lineItemId,quantity=1)=>{await updateLineItem({lineItemId,quantity,dispatch,config,getOrder,orderId,errors:state.errors})},deleteLineItem:async lineItemId=>{await deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})}};return _jsx(LineItemContext.Provider,{value:lineItemValue,children:state.loading?loader:children})}export default LineItemsContainer;
|
|
2
|
+
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";export function 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?.includes("line_items.bundle.sku_list.sku_list_items")?includeLoaded?.["line_items.bundle.sku_list.sku_list_items"]||addResourceToInclude({newResourceLoaded:{"line_items.bundle.sku_list.sku_list_items":!0,"line_items.bundle.sku_list.sku_list_items.sku":!0}}):addResourceToInclude({newResource:["line_items.bundle.sku_list.sku_list_items","line_items.bundle.sku_list.sku_list_items.sku"]})},[include,includeLoaded]),useEffect(()=>{order?.line_items&&dispatch({type:"setLineItems",payload:{lineItems:order.line_items}})},[order?.line_items]);const lineItemValue={...state,loader,updateLineItem:async(lineItemId,quantity=1,hasExternalPrice)=>{await updateLineItem({lineItemId,quantity,hasExternalPrice,dispatch,config,getOrder,orderId,errors:state.errors})},deleteLineItem:async lineItemId=>{await deleteLineItem({lineItemId,dispatch,config,getOrder,orderId,errors:state.errors})}};return _jsx(LineItemContext.Provider,{value:lineItemValue,children:state.loading?loader:children})}export default LineItemsContainer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function LineItemsCount(props){const{children,typeAccepted,...p}=props,{lineItems}=useCustomContext({context:LineItemContext,contextComponentName:"LineItemsContainer",currentComponentName:"LineItemsCount",key:"lineItems"}),[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})}export default LineItemsCount;
|
|
@@ -5,14 +5,26 @@ interface TAddToCartButton extends Omit<Props, 'children'> {
|
|
|
5
5
|
handleClick: () => AddToCartReturn;
|
|
6
6
|
}
|
|
7
7
|
type BuyNowMode = {
|
|
8
|
+
/**
|
|
9
|
+
* Once item has been added, it redirects to the hosted checkout micro-frontend.
|
|
10
|
+
*/
|
|
8
11
|
buyNowMode: true;
|
|
12
|
+
/**
|
|
13
|
+
* If you have a self-hosted checkout, you can pass the url to redirect to it.
|
|
14
|
+
*/
|
|
9
15
|
checkoutUrl?: string;
|
|
10
16
|
} | {
|
|
11
17
|
buyNowMode?: false;
|
|
12
18
|
checkoutUrl?: never;
|
|
13
19
|
};
|
|
14
20
|
type THostedCart = {
|
|
21
|
+
/**
|
|
22
|
+
* Once item has been added, it redirects to the hosted cart micro-frontend.
|
|
23
|
+
*/
|
|
15
24
|
redirectToHostedCart: true;
|
|
25
|
+
/**
|
|
26
|
+
* If you have a self-hosted cart, you can pass the url to redirect to it.
|
|
27
|
+
*/
|
|
16
28
|
hostedCartUrl?: string;
|
|
17
29
|
} | {
|
|
18
30
|
redirectToHostedCart?: false;
|
|
@@ -54,5 +66,25 @@ type Props = {
|
|
|
54
66
|
*/
|
|
55
67
|
skuListId?: string;
|
|
56
68
|
} & TButton & BuyNowMode & THostedCart;
|
|
69
|
+
/**
|
|
70
|
+
* This component adds `line_items` to the cart (aka draft order), see the [how to create a shopping cart](https://docs.commercelayer.io/core/v/how-tos/placing-orders/shopping-cart/create-a-shopping-cart) documentation,
|
|
71
|
+
* for a general understanding of the process.
|
|
72
|
+
*
|
|
73
|
+
* It can be used to add `skus` or `bundle` by receiving `skuCode` or `bundleCode` from props.
|
|
74
|
+
* When `skuListId` is passed as prop , it will add all the `skus` in the `sku_list` to the cart.
|
|
75
|
+
*
|
|
76
|
+
* It's possible to select the quantity of the item to add to cart by passing the `quantity` prop.
|
|
77
|
+
*
|
|
78
|
+
* When this component is used inside a `<Skus>` or `<SkuList>` component, it will automatically get the `skuCode` and quantity from the context,
|
|
79
|
+
* so you don't need to pass it as prop.
|
|
80
|
+
*
|
|
81
|
+
* It can automatically redirect to the cart page of the application using the `redirectToHostedCart` prop and optionally a `hostedCartUrl`.
|
|
82
|
+
*
|
|
83
|
+
* With a similar logic, you can enable a "Buy Now" experience and automatically redirect the customer to the checkout page using the `buyNowMode` prop and optionally a `checkoutUrl`.
|
|
84
|
+
*
|
|
85
|
+
* <span title="Requirement" type="warning">
|
|
86
|
+
* Must be a child of the `<OrderContainer>` component.
|
|
87
|
+
* </span>
|
|
88
|
+
*/
|
|
57
89
|
export declare function AddToCartButton(props: Props): JSX.Element;
|
|
58
90
|
export default AddToCartButton;
|
|
@@ -35,5 +35,13 @@ interface Props extends Omit<JSX.IntrinsicElements['a'], 'children'> {
|
|
|
35
35
|
*/
|
|
36
36
|
customDomain?: string;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* This component generates a link to the hosted mfe-cart application.
|
|
40
|
+
* In this way you can connect your shop application with our hosted micro-frontend.
|
|
41
|
+
*
|
|
42
|
+
* <span title="Requirement" type="warning">
|
|
43
|
+
* Must be a child of the `<OrderContainer>` component. <br />
|
|
44
|
+
* </span>
|
|
45
|
+
*/
|
|
38
46
|
export declare function CartLink(props: Props): JSX.Element | null;
|
|
39
47
|
export default CartLink;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function CartLink(props){const{label,children,type,customDomain,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");if(endpoint==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=slug&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,domain,applicationType:"cart",customDomain}):
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import{publish}from"../../utils/events";export function CartLink(props){const{label,children,type,customDomain,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext);if(accessToken==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");if(endpoint==null)throw new Error("Cannot use `CartLink` outside of `CommerceLayer`");const{domain,slug}=getDomain(endpoint),href=slug&&order?.id?getApplicationLink({slug,orderId:order?.id,accessToken,domain,applicationType:"cart",customDomain}):void 0,handleClick=async event=>{if(event.preventDefault(),type!=="mini")if(order?.id)location.href=href??"";else{const orderId=await createOrder({});slug&&(location.href=getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart",customDomain}))}else publish("open-cart")},parentProps={handleClick,label,href,orderId:order?.id,accessToken,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,onClick:e=>{handleClick(e)},...p,children:label}):null}export default CartLink;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { type ChildrenFunction } from '../../typings/index';
|
|
2
3
|
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
3
4
|
checkoutUrl: string;
|
|
@@ -5,8 +6,23 @@ interface ChildrenProps extends Omit<Props, 'children'> {
|
|
|
5
6
|
}
|
|
6
7
|
interface Props extends Omit<JSX.IntrinsicElements['a'], 'children'> {
|
|
7
8
|
children?: ChildrenFunction<ChildrenProps>;
|
|
9
|
+
/**
|
|
10
|
+
* Label for the checkout link
|
|
11
|
+
*/
|
|
8
12
|
label?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Ignores `order.checkout_url` and redirects to the hosted checkout micro-frontend.
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
9
17
|
hostedCheckout?: boolean;
|
|
10
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* This component generates a link to the hosted mfe-checkout application.
|
|
21
|
+
* In this way you can connect your shop application with our hosted micro-frontend.
|
|
22
|
+
*
|
|
23
|
+
* By default it will takes the customer to our hosted checkout micro-frontend,
|
|
24
|
+
* but if `hostedCheckout` is set as `false` it will use the `checkout_url` attribute
|
|
25
|
+
* found in the `order` object.
|
|
26
|
+
*/
|
|
11
27
|
export declare function CheckoutLink(props: Props): JSX.Element;
|
|
12
28
|
export default CheckoutLink;
|
|
@@ -7,30 +7,52 @@ interface Styles {
|
|
|
7
7
|
iconContainer?: CSSProperties;
|
|
8
8
|
}
|
|
9
9
|
interface Props extends Omit<JSX.IntrinsicElements['div'], 'children' | 'style'> {
|
|
10
|
+
/**
|
|
11
|
+
* The style of the cart.
|
|
12
|
+
*/
|
|
13
|
+
style?: Styles;
|
|
14
|
+
/**
|
|
15
|
+
* The domain of your forked application.
|
|
16
|
+
*/
|
|
17
|
+
customDomain?: string;
|
|
10
18
|
/**
|
|
11
19
|
* The type of the cart. Defaults to undefined.
|
|
12
20
|
*/
|
|
13
21
|
type?: 'mini';
|
|
14
22
|
/**
|
|
15
23
|
* If true, the cart will open when a line item is added to the order clicking the add to cart button. Defaults to false.
|
|
24
|
+
* Works only with the `type` prop set to `mini`.
|
|
16
25
|
*/
|
|
17
26
|
openAdd?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* The style of the cart.
|
|
20
|
-
*/
|
|
21
|
-
style?: Styles;
|
|
22
27
|
/**
|
|
23
28
|
* If true, the cart will be open. Defaults to false.
|
|
29
|
+
* Works only with the `type` prop set to `mini`.
|
|
24
30
|
*/
|
|
25
31
|
open?: boolean;
|
|
26
32
|
/**
|
|
27
33
|
* A function that will be called when the cart is open and the background is clicked.
|
|
34
|
+
* Works only with the `type` prop set to `mini`.
|
|
28
35
|
*/
|
|
29
36
|
handleOpen?: () => void;
|
|
30
|
-
/**
|
|
31
|
-
* The domain of your forked application.
|
|
32
|
-
*/
|
|
33
|
-
customDomain?: string;
|
|
34
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* This component allows to embed the cart application in your page as an `<iframe>`.
|
|
40
|
+
*
|
|
41
|
+
* By default, it will be rendered as inline cart and its content will fit the available container width
|
|
42
|
+
* while the height will be automatically adjusted to the content.
|
|
43
|
+
*
|
|
44
|
+
* Or it can work as mini cart - when `type` prop is set to `mini` - and it will be opened in a modal (popup).
|
|
45
|
+
*
|
|
46
|
+
* <span title="Requirement" type="warning">
|
|
47
|
+
* Must be a child of the `<OrderContainer>` component.
|
|
48
|
+
* </span>
|
|
49
|
+
*
|
|
50
|
+
* <span title="Mini cart" type="info">
|
|
51
|
+
* When set as `mini` cart, it requires the `<CartLink type='mini' />` component to be on the same page,
|
|
52
|
+
* to show the cart when clicked. <br />
|
|
53
|
+
* View the `<CartLink />` component documentation for more details and examples.
|
|
54
|
+
* </span>
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
35
57
|
export declare function HostedCart({ type, openAdd, style, open, handleOpen, customDomain, ...props }: Props): JSX.Element | null;
|
|
36
58
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import useCustomContext from"../../utils/hooks/useCustomContext";import{useContext,useEffect,useState,useRef}from"react";import{iframeResizer}from"iframe-resizer";import{subscribe,unsubscribe}from"../../utils/events";const defaultIframeStyle={width:"1px",minWidth:"100%",minHeight:"100%",border:"none"},defaultContainerStyle={position:"fixed",top:"0",right:"-25rem",height:"100%",width:"23rem",transition:"right 0.5s ease-in-out",
|
|
2
|
+
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import{getApplicationLink}from"../../utils/getApplicationLink";import{getDomain}from"../../utils/getDomain";import useCustomContext from"../../utils/hooks/useCustomContext";import{useContext,useEffect,useState,useRef}from"react";import{iframeResizer}from"iframe-resizer";import{subscribe,unsubscribe}from"../../utils/events";const defaultIframeStyle={width:"1px",minWidth:"100%",minHeight:"100%",border:"none"},defaultContainerStyle={position:"fixed",top:"0",right:"-25rem",height:"100%",width:"23rem",transition:"right 0.5s ease-in-out",pointerEvents:"none",overflow:"auto"},defaultBackgroundStyle={opacity:"0",position:"fixed",top:"0",left:"0",height:"100%",width:"100vw",transition:"opacity 0.5s ease-in-out",pointerEvents:"none",backgroundColor:"black"},defaultIconStyle={width:"1.25rem",height:"1.25rem"},defaultIconContainer={textAlign:"left",paddingLeft:"20px",paddingTop:"20px",background:"#ffffff",color:"#686E6E"},defaultStyle={cart:defaultIframeStyle,container:defaultContainerStyle,background:defaultBackgroundStyle,icon:defaultIconStyle,iconContainer:defaultIconContainer};export function HostedCart({type,openAdd=!1,style,open=!1,handleOpen,customDomain,...props}){const[isOpen,setOpen]=useState(!1),ref=useRef(null),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"HostedCart",key:"accessToken"}),[src,setSrc]=useState();if(accessToken==null||endpoint==null)return null;const{order,createOrder,getOrder}=useContext(OrderContext),{persistKey}=useContext(OrderStorageContext),{domain,slug}=getDomain(endpoint);async function setOrder(openCart){const orderId=localStorage.getItem(persistKey)??await createOrder({});orderId!=null&&accessToken&&(setSrc(getApplicationLink({slug,orderId,accessToken,domain,applicationType:"cart",customDomain})),openCart&&setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300))}function onMessage(data){switch(data.message.type){case"update":data.message.payload!=null&&getOrder(data.message.payload.id);break;case"close":type==="mini"&&(handleOpen!=null?handleOpen():setOpen(!1));break;case"blur":type==="mini"&&isOpen&&ref.current?.focus();break}}useEffect(()=>{const orderId=localStorage.getItem(persistKey);let ignore=!1;return open!=null&&open!==isOpen&&setOpen(open),openAdd&&type==="mini"&&subscribe("open-cart",()=>{window.document.body.style.overflow="hidden",src==null&&order?.id==null&&orderId==null?setOrder(!0):(src!=null&&ref.current!=null&&(ref.current.src=src),setTimeout(()=>{handleOpen!=null?handleOpen():setOpen(!0)},300))}),src==null&&order?.id==null&&orderId==null&&accessToken!=null&&!ignore&&isOpen?setOrder():src==null&&(order?.id!=null||orderId!=null)&&accessToken&&setSrc(getApplicationLink({slug,orderId:order?.id??orderId,accessToken,domain,applicationType:"cart"})),src!=null&&ref.current!=null&&(ref.current.src=src),()=>{ignore=!0,openAdd&&type==="mini"&&unsubscribe("open-cart",()=>{})}},[src,open,order?.id,accessToken]),useEffect(()=>{ref.current!=null&&iframeResizer({checkOrigin:!1,bodyPadding:"20px",onMessage},ref.current)},[ref.current!=null]);function onCloseCart(){window.document.body.style.removeProperty("overflow"),handleOpen!=null?handleOpen():setOpen(!1)}return src==null?null:type==="mini"?_jsxs(_Fragment,{children:[_jsx("div",{"aria-hidden":"true",style:{...defaultStyle.background,...style?.background,opacity:isOpen?"0.5":defaultStyle.background?.opacity,pointerEvents:isOpen?"initial":defaultStyle.background?.pointerEvents},onClick:onCloseCart}),_jsxs("div",{style:{...defaultStyle.container,...style?.container,right:isOpen?"0":defaultStyle.container?.right,pointerEvents:isOpen?"initial":defaultStyle.container?.pointerEvents},...props,children:[_jsx("div",{style:{...defaultStyle.iconContainer,...style?.iconContainer},children:_jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor",style:{...defaultStyle.icon,...style?.icon},onClick:onCloseCart,children:_jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})}),_jsx("iframe",{title:"Cart",ref,style:{...defaultStyle.cart,...style?.cart},src,width:"100%",height:"100%"})]})]}):_jsx("iframe",{title:"Cart",ref,style:{...defaultStyle.cart,...style?.cart},src,width:"100%",height:"100%"})}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { type BaseMetadataObject } from '../../typings/index';
|
|
2
3
|
import type { OrderCreate, Order } from '@commercelayer/sdk';
|
|
3
4
|
import type { DefaultChildrenType } from '../../typings/globals';
|
|
@@ -20,5 +21,38 @@ interface Props {
|
|
|
20
21
|
*/
|
|
21
22
|
fetchOrder?: (order: Order) => void;
|
|
22
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* This component is responsible for fetching the order and store it in its context.
|
|
26
|
+
* It also provides the `fetchOrder` callback that is triggered every time the order is updated (it returns the updated order object as argument).
|
|
27
|
+
* When the order is not placed yet, its possible to pass the `metadata` and `attributes` props to update the order.
|
|
28
|
+
*
|
|
29
|
+
* <span title="Requirement" type="warning">
|
|
30
|
+
* Must be a child of the `<CommerceLayer>` component. <br />
|
|
31
|
+
* Can be a child of the `<OrderStorage>` component and receive the `orderId` from it.
|
|
32
|
+
* </span>
|
|
33
|
+
*
|
|
34
|
+
* <span title="Children" type="info">
|
|
35
|
+
* `<AddToCartButton>`,
|
|
36
|
+
* `<AdjustmentAmount>`,
|
|
37
|
+
* `<CartLink>`,
|
|
38
|
+
* `<CheckoutLink>`,
|
|
39
|
+
* `<DiscountAmount>`,
|
|
40
|
+
* `<GiftCardAmount>`,
|
|
41
|
+
* `<HostedCart>`,
|
|
42
|
+
* `<OrderNumber>`,
|
|
43
|
+
* `<PaymentMethodAmount>`,
|
|
44
|
+
* `<PlaceOrderButton>`,
|
|
45
|
+
* `<PlaceOrderContainer>`,
|
|
46
|
+
* `<PrivacyAndTermsCheckbox>`,
|
|
47
|
+
* `<Shipping Amount>`,
|
|
48
|
+
* `<SubTotalAmount>`,
|
|
49
|
+
* `<TaxesAmount>`,
|
|
50
|
+
* `<TotalAmount>`,
|
|
51
|
+
* </span>
|
|
52
|
+
*
|
|
53
|
+
* <span title="Core API" type="info">
|
|
54
|
+
* Check the `orders` resource from our [Core API documentation](https://docs.commercelayer.io/core/v/api-reference/orders/object).
|
|
55
|
+
* </span>
|
|
56
|
+
*/
|
|
23
57
|
export declare function OrderContainer(props: Props): JSX.Element;
|
|
24
58
|
export default OrderContainer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder,addToCart}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import compareObjAttribute from"../../utils/compareObjAttribute";import useCustomContext from"../../utils/hooks/useCustomContext";export function OrderContainer(props){const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"OrderContainer",key:"accessToken"}),{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext),
|
|
2
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder,addToCart}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import compareObjAttribute from"../../utils/compareObjAttribute";import useCustomContext from"../../utils/hooks/useCustomContext";export function OrderContainer(props){const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"OrderContainer",key:"accessToken"}),{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext),getOrder=async localOrder=>{localOrder&&await getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state})};useEffect(()=>{const localOrder=persistKey?getLocalOrder(persistKey):orderId;state?.orderId&&(localOrder!=null&&state.orderId!==localOrder?getOrder(localOrder):dispatch({type:"setOrderId",payload:{orderId:void 0,order:void 0}}))},[persistKey]),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);return config.accessToken&&state.loading===!1&&state?.order==null?(localOrder&&!state.order&&state.include?.length===startRequest.length&&!state.withoutIncludes&&!lockOrder||state.withoutIncludes&&!state.include?.length&&startRequest.length===0)&&getOrder(localOrder):[config.accessToken,state.order==null,state.loading,state.withoutIncludes].every(Boolean)?dispatch({type:"setLoading",payload:{loading:!1}}):[config.accessToken,state.order==null,state.loading,state.withoutIncludes===!1].every(Boolean)&&dispatch({type:"setLoading",payload:{loading:!1}}),()=>{state.order==null&&state.loading&&state.withoutIncludes===!1&&(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,Object.keys(state.includeLoaded??{}).length,state.include?.length,orderId,Object.keys(state?.order??{}).length,state.loading,state.withoutIncludes,lockOrder]);const orderValue=useMemo(()=>(fetchOrder!=null&&state?.order!=null&&fetchOrder(state.order),{...state,setOrder:order=>{setOrder(order,dispatch)},getOrder:async id=>await getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:async()=>await createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:async params=>await addToCart({...params,persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder}),saveAddressToCustomerAddressBook:args=>{defaultOrderContext.saveAddressToCustomerAddressBook({...args,dispatch})},setGiftCardOrCouponCode:async({code,codeType})=>await defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:async({codeType})=>await 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,persistKey]);return _jsx(OrderContext.Provider,{value:orderValue,children})}export default OrderContainer;
|