@commercelayer/react-components 4.0.0-alpha.11 → 4.0.0-alpha.13
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/line_items/LineItem.d.ts +4 -11
- package/lib/cjs/components/line_items/LineItem.js +1 -1
- package/lib/cjs/components/line_items/LineItemAmount.d.ts +0 -13
- package/lib/cjs/components/line_items/LineItemAmount.js +1 -1
- package/lib/cjs/components/line_items/LineItemCode.d.ts +6 -11
- package/lib/cjs/components/line_items/LineItemCode.js +1 -1
- package/lib/cjs/components/line_items/LineItemField.d.ts +14 -0
- package/lib/cjs/components/line_items/LineItemField.js +1 -0
- package/lib/cjs/components/line_items/LineItemImage.d.ts +4 -11
- package/lib/cjs/components/line_items/LineItemImage.js +1 -1
- package/lib/cjs/components/line_items/LineItemName.d.ts +6 -11
- package/lib/cjs/components/line_items/LineItemName.js +1 -1
- package/lib/cjs/components/line_items/LineItemOption.d.ts +5 -16
- package/lib/cjs/components/line_items/LineItemOption.js +1 -1
- package/lib/cjs/components/line_items/LineItemOptions.d.ts +2 -5
- package/lib/cjs/components/line_items/LineItemOptions.js +1 -1
- package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
- package/lib/cjs/components/line_items/LineItemsContainer.d.ts +2 -14
- package/lib/cjs/components/line_items/LineItemsContainer.js +1 -1
- package/lib/cjs/components/orders/AddToCartButton.d.ts +29 -6
- package/lib/cjs/components/orders/AddToCartButton.js +1 -1
- package/lib/cjs/components/orders/AdjustmentAmount.d.ts +2 -2
- package/lib/cjs/components/orders/AdjustmentAmount.js +1 -1
- package/lib/cjs/components/orders/DiscountAmount.d.ts +0 -14
- package/lib/cjs/components/orders/DiscountAmount.js +1 -1
- package/lib/cjs/components/orders/GiftCardAmount.d.ts +0 -11
- package/lib/cjs/components/orders/GiftCardAmount.js +1 -1
- package/lib/cjs/components/orders/OrderContainer.d.ts +0 -1
- package/lib/cjs/components/orders/OrderContainer.js +1 -1
- package/lib/cjs/components/orders/PaymentMethodAmount.d.ts +4 -0
- package/lib/cjs/components/orders/PaymentMethodAmount.js +1 -0
- package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
- package/lib/cjs/components/orders/PlaceOrderContainer.d.ts +2 -8
- package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
- package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -6
- package/lib/cjs/components/orders/PrivacyAndTermsCheckbox.js +1 -1
- package/lib/cjs/components/orders/ShippingAmount.d.ts +0 -11
- package/lib/cjs/components/orders/ShippingAmount.js +1 -1
- package/lib/cjs/components/orders/SubTotalAmount.d.ts +0 -14
- package/lib/cjs/components/orders/SubTotalAmount.js +1 -1
- package/lib/cjs/components/orders/TaxesAmount.d.ts +0 -14
- package/lib/cjs/components/orders/TaxesAmount.js +1 -1
- package/lib/cjs/components/orders/TotalAmount.d.ts +0 -14
- package/lib/cjs/components/orders/TotalAmount.js +1 -1
- package/lib/cjs/components/parcels/ParcelLineItemsCount.js +1 -1
- package/lib/cjs/components/parcels/ParcelsCount.js +1 -1
- package/lib/cjs/components/payment_methods/PaymentMethod.d.ts +1 -7
- package/lib/cjs/components/payment_methods/PaymentMethod.js +1 -1
- package/lib/cjs/components/payment_methods/PaymentMethodName.d.ts +6 -11
- package/lib/cjs/components/payment_methods/PaymentMethodName.js +1 -1
- package/lib/cjs/components/payment_methods/PaymentMethodPrice.d.ts +2 -14
- package/lib/cjs/components/payment_methods/PaymentMethodPrice.js +1 -1
- package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.d.ts +4 -9
- package/lib/cjs/components/payment_methods/PaymentMethodRadioButton.js +1 -1
- package/lib/cjs/components/payment_methods/PaymentMethodsContainer.js +1 -1
- package/lib/cjs/components/payment_source/AdyenPayment.d.ts +5 -5
- package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
- package/lib/cjs/components/prices/Price.js +1 -1
- package/lib/cjs/components/prices/PricesContainer.js +1 -1
- package/lib/cjs/components/shipments/ShipmentsCount.js +1 -1
- package/lib/cjs/components/skus/AvailabilityContainer.d.ts +3 -9
- package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
- package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +23 -4
- package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
- package/lib/cjs/components/skus/SkuField.js +1 -1
- package/lib/cjs/components/skus/SkusContainer.d.ts +2 -2
- package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +3 -4
- package/lib/cjs/components/utils/BaseInput.d.ts +1 -1
- package/lib/cjs/components/utils/BaseOrderPrice.d.ts +3 -3
- package/lib/cjs/components/utils/BaseOrderPrice.js +1 -1
- package/lib/cjs/components/utils/GenericFieldComponent.d.ts +4 -4
- package/lib/cjs/components/utils/GenericFieldComponent.js +1 -1
- package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +3 -3
- package/lib/cjs/context/ExternalFunctionContext.d.ts +2 -2
- package/lib/cjs/context/ExternalFunctionContext.js +1 -1
- package/lib/cjs/context/LineItemContext.d.ts +1 -1
- package/lib/cjs/context/OrderContext.d.ts +2 -2
- package/lib/cjs/context/PaymentMethodContext.d.ts +2 -11
- package/lib/cjs/context/PaymentMethodContext.js +1 -1
- package/lib/cjs/index.d.ts +3 -16
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/reducers/AvailabilityReducer.d.ts +4 -14
- package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.d.ts +36 -22
- package/lib/cjs/reducers/OrderReducer.js +1 -1
- package/lib/cjs/reducers/PaymentMethodReducer.d.ts +9 -11
- package/lib/cjs/reducers/PaymentMethodReducer.js +1 -1
- package/lib/cjs/reducers/PriceReducer.d.ts +12 -19
- package/lib/cjs/reducers/PriceReducer.js +1 -1
- package/lib/cjs/reducers/SkuReducer.d.ts +3 -3
- package/lib/cjs/typings/errors.d.ts +4 -4
- package/lib/cjs/typings/index.d.ts +3 -3
- package/lib/cjs/utils/browserInfo.d.ts +5 -2
- package/lib/cjs/utils/browserInfo.js +1 -1
- package/lib/cjs/utils/hooks/useCustomContext.d.ts +21 -0
- package/lib/cjs/utils/hooks/useCustomContext.js +1 -0
- package/lib/esm/components/line_items/LineItem.d.ts +4 -11
- package/lib/esm/components/line_items/LineItem.js +1 -1
- package/lib/esm/components/line_items/LineItemAmount.d.ts +0 -13
- package/lib/esm/components/line_items/LineItemAmount.js +1 -1
- package/lib/esm/components/line_items/LineItemCode.d.ts +6 -11
- package/lib/esm/components/line_items/LineItemCode.js +1 -1
- package/lib/esm/components/line_items/LineItemField.d.ts +14 -0
- package/lib/esm/components/line_items/LineItemField.js +1 -0
- package/lib/esm/components/line_items/LineItemImage.d.ts +4 -11
- package/lib/esm/components/line_items/LineItemImage.js +1 -1
- package/lib/esm/components/line_items/LineItemName.d.ts +6 -11
- package/lib/esm/components/line_items/LineItemName.js +1 -1
- package/lib/esm/components/line_items/LineItemOption.d.ts +5 -16
- package/lib/esm/components/line_items/LineItemOption.js +1 -1
- package/lib/esm/components/line_items/LineItemOptions.d.ts +2 -5
- package/lib/esm/components/line_items/LineItemOptions.js +1 -1
- package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -1
- package/lib/esm/components/line_items/LineItemsContainer.d.ts +2 -14
- package/lib/esm/components/line_items/LineItemsContainer.js +1 -1
- package/lib/esm/components/orders/AddToCartButton.d.ts +29 -6
- package/lib/esm/components/orders/AddToCartButton.js +1 -1
- package/lib/esm/components/orders/AdjustmentAmount.d.ts +2 -2
- package/lib/esm/components/orders/AdjustmentAmount.js +1 -1
- package/lib/esm/components/orders/DiscountAmount.d.ts +0 -14
- package/lib/esm/components/orders/DiscountAmount.js +1 -1
- package/lib/esm/components/orders/GiftCardAmount.d.ts +0 -11
- package/lib/esm/components/orders/GiftCardAmount.js +1 -1
- package/lib/esm/components/orders/OrderContainer.d.ts +0 -1
- package/lib/esm/components/orders/OrderContainer.js +1 -1
- package/lib/esm/components/orders/PaymentMethodAmount.d.ts +4 -0
- package/lib/esm/components/orders/PaymentMethodAmount.js +1 -0
- package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
- package/lib/esm/components/orders/PlaceOrderContainer.d.ts +2 -8
- package/lib/esm/components/orders/PlaceOrderContainer.js +1 -1
- package/lib/esm/components/orders/PrivacyAndTermsCheckbox.d.ts +0 -6
- package/lib/esm/components/orders/PrivacyAndTermsCheckbox.js +1 -1
- package/lib/esm/components/orders/ShippingAmount.d.ts +0 -11
- package/lib/esm/components/orders/ShippingAmount.js +1 -1
- package/lib/esm/components/orders/SubTotalAmount.d.ts +0 -14
- package/lib/esm/components/orders/SubTotalAmount.js +1 -1
- package/lib/esm/components/orders/TaxesAmount.d.ts +0 -14
- package/lib/esm/components/orders/TaxesAmount.js +1 -1
- package/lib/esm/components/orders/TotalAmount.d.ts +0 -14
- package/lib/esm/components/orders/TotalAmount.js +1 -1
- package/lib/esm/components/parcels/ParcelLineItemsCount.js +1 -1
- package/lib/esm/components/parcels/ParcelsCount.js +1 -1
- package/lib/esm/components/payment_methods/PaymentMethod.d.ts +1 -7
- package/lib/esm/components/payment_methods/PaymentMethod.js +1 -1
- package/lib/esm/components/payment_methods/PaymentMethodName.d.ts +6 -11
- package/lib/esm/components/payment_methods/PaymentMethodName.js +1 -1
- package/lib/esm/components/payment_methods/PaymentMethodPrice.d.ts +2 -14
- package/lib/esm/components/payment_methods/PaymentMethodPrice.js +1 -1
- package/lib/esm/components/payment_methods/PaymentMethodRadioButton.d.ts +4 -9
- package/lib/esm/components/payment_methods/PaymentMethodRadioButton.js +1 -1
- package/lib/esm/components/payment_methods/PaymentMethodsContainer.js +1 -1
- package/lib/esm/components/payment_source/AdyenPayment.d.ts +5 -5
- package/lib/esm/components/payment_source/AdyenPayment.js +1 -1
- package/lib/esm/components/prices/Price.js +1 -1
- package/lib/esm/components/prices/PricesContainer.js +1 -1
- package/lib/esm/components/shipments/ShipmentsCount.js +1 -1
- package/lib/esm/components/skus/AvailabilityContainer.d.ts +3 -9
- package/lib/esm/components/skus/AvailabilityContainer.js +1 -1
- package/lib/esm/components/skus/AvailabilityTemplate.d.ts +23 -4
- package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
- package/lib/esm/components/skus/SkuField.js +1 -1
- package/lib/esm/components/skus/SkusContainer.d.ts +2 -2
- package/lib/esm/components/utils/AddressCardsTemplate.d.ts +3 -4
- package/lib/esm/components/utils/BaseInput.d.ts +1 -1
- package/lib/esm/components/utils/BaseOrderPrice.d.ts +3 -3
- package/lib/esm/components/utils/BaseOrderPrice.js +1 -1
- package/lib/esm/components/utils/GenericFieldComponent.d.ts +4 -4
- package/lib/esm/components/utils/GenericFieldComponent.js +1 -1
- package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +3 -3
- package/lib/esm/context/ExternalFunctionContext.d.ts +2 -2
- package/lib/esm/context/ExternalFunctionContext.js +1 -1
- package/lib/esm/context/LineItemContext.d.ts +1 -1
- package/lib/esm/context/OrderContext.d.ts +2 -2
- package/lib/esm/context/PaymentMethodContext.d.ts +2 -11
- package/lib/esm/context/PaymentMethodContext.js +1 -1
- package/lib/esm/index.d.ts +3 -16
- package/lib/esm/index.js +1 -1
- package/lib/esm/reducers/AvailabilityReducer.d.ts +4 -14
- package/lib/esm/reducers/AvailabilityReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.d.ts +36 -22
- package/lib/esm/reducers/OrderReducer.js +1 -1
- package/lib/esm/reducers/PaymentMethodReducer.d.ts +9 -11
- package/lib/esm/reducers/PaymentMethodReducer.js +1 -1
- package/lib/esm/reducers/PriceReducer.d.ts +12 -19
- package/lib/esm/reducers/PriceReducer.js +1 -1
- package/lib/esm/reducers/SkuReducer.d.ts +3 -3
- package/lib/esm/typings/errors.d.ts +4 -4
- package/lib/esm/typings/index.d.ts +3 -3
- package/lib/esm/utils/browserInfo.d.ts +5 -2
- package/lib/esm/utils/browserInfo.js +1 -1
- package/lib/esm/utils/hooks/useCustomContext.d.ts +21 -0
- package/lib/esm/utils/hooks/useCustomContext.js +1 -0
- package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/lib/cjs/components/orders/ItemContainer.d.ts +0 -11
- package/lib/cjs/components/orders/ItemContainer.js +0 -1
- package/lib/cjs/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
- package/lib/cjs/components/payment_methods/PaymentMethodAmount.js +0 -1
- package/lib/cjs/components/skus/QuantitySelector.d.ts +0 -17
- package/lib/cjs/components/skus/QuantitySelector.js +0 -1
- package/lib/cjs/components/skus/SkuOption.d.ts +0 -14
- package/lib/cjs/components/skus/SkuOption.js +0 -1
- package/lib/cjs/components/skus/SkuOptionInput.d.ts +0 -15
- package/lib/cjs/components/skus/SkuOptionInput.js +0 -1
- package/lib/cjs/components/skus/SkuOptionsContainer.d.ts +0 -14
- package/lib/cjs/components/skus/SkuOptionsContainer.js +0 -1
- package/lib/cjs/components/skus/VariantSelector.d.ts +0 -29
- package/lib/cjs/components/skus/VariantSelector.js +0 -1
- package/lib/cjs/components/skus/VariantsContainer.d.ts +0 -20
- package/lib/cjs/components/skus/VariantsContainer.js +0 -1
- package/lib/cjs/components/utils/VariantTemplate.d.ts +0 -36
- package/lib/cjs/components/utils/VariantTemplate.js +0 -1
- package/lib/cjs/context/ItemContext.d.ts +0 -13
- package/lib/cjs/context/ItemContext.js +0 -1
- package/lib/cjs/context/SkuOptionChildrenContext.d.ts +0 -8
- package/lib/cjs/context/SkuOptionChildrenContext.js +0 -1
- package/lib/cjs/context/SkuOptionsContext.d.ts +0 -3
- package/lib/cjs/context/SkuOptionsContext.js +0 -1
- package/lib/cjs/context/VariantsContext.d.ts +0 -3
- package/lib/cjs/context/VariantsContext.js +0 -1
- package/lib/cjs/reducers/ItemReducer.d.ts +0 -69
- package/lib/cjs/reducers/ItemReducer.js +0 -1
- package/lib/cjs/reducers/SkuOptionsReducer.d.ts +0 -26
- package/lib/cjs/reducers/SkuOptionsReducer.js +0 -1
- package/lib/cjs/reducers/VariantReducer.d.ts +0 -72
- package/lib/cjs/reducers/VariantReducer.js +0 -1
- package/lib/cjs/utils/getCurrentItemKey.d.ts +0 -6
- package/lib/cjs/utils/getCurrentItemKey.js +0 -1
- package/lib/esm/components/orders/ItemContainer.d.ts +0 -11
- package/lib/esm/components/orders/ItemContainer.js +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
- package/lib/esm/components/payment_methods/PaymentMethodAmount.js +0 -1
- package/lib/esm/components/skus/QuantitySelector.d.ts +0 -17
- package/lib/esm/components/skus/QuantitySelector.js +0 -1
- package/lib/esm/components/skus/SkuOption.d.ts +0 -14
- package/lib/esm/components/skus/SkuOption.js +0 -1
- package/lib/esm/components/skus/SkuOptionInput.d.ts +0 -15
- package/lib/esm/components/skus/SkuOptionInput.js +0 -1
- package/lib/esm/components/skus/SkuOptionsContainer.d.ts +0 -14
- package/lib/esm/components/skus/SkuOptionsContainer.js +0 -1
- package/lib/esm/components/skus/VariantSelector.d.ts +0 -29
- package/lib/esm/components/skus/VariantSelector.js +0 -1
- package/lib/esm/components/skus/VariantsContainer.d.ts +0 -20
- package/lib/esm/components/skus/VariantsContainer.js +0 -1
- package/lib/esm/components/utils/VariantTemplate.d.ts +0 -36
- package/lib/esm/components/utils/VariantTemplate.js +0 -1
- package/lib/esm/context/ItemContext.d.ts +0 -13
- package/lib/esm/context/ItemContext.js +0 -1
- package/lib/esm/context/SkuOptionChildrenContext.d.ts +0 -8
- package/lib/esm/context/SkuOptionChildrenContext.js +0 -1
- package/lib/esm/context/SkuOptionsContext.d.ts +0 -3
- package/lib/esm/context/SkuOptionsContext.js +0 -1
- package/lib/esm/context/VariantsContext.d.ts +0 -3
- package/lib/esm/context/VariantsContext.js +0 -1
- package/lib/esm/reducers/ItemReducer.d.ts +0 -69
- package/lib/esm/reducers/ItemReducer.js +0 -1
- package/lib/esm/reducers/SkuOptionsReducer.d.ts +0 -26
- package/lib/esm/reducers/SkuOptionsReducer.js +0 -1
- package/lib/esm/reducers/VariantReducer.d.ts +0 -72
- package/lib/esm/reducers/VariantReducer.js +0 -1
- package/lib/esm/utils/getCurrentItemKey.d.ts +0 -6
- package/lib/esm/utils/getCurrentItemKey.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import getAmount from"../../utils/getAmount";import Parent from"./Parent";import{useState,useEffect,useContext}from"react";import isEmpty from"lodash/isEmpty";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../../context/OrderContext";import getAmount from"../../utils/getAmount";import Parent from"./Parent";import{useState,useEffect,useContext}from"react";import isEmpty from"lodash/isEmpty";export function BaseOrderPrice(props){const{format="formatted",base,type,children,...p}=props,{order}=useContext(OrderContext),[price,setPrice]=useState(""),[cents,setCents]=useState(0);useEffect(()=>{const p2=getAmount({base,type,format,obj:order||{}}),c=getAmount({base,type,format:"cents",obj:order||{}});return setPrice(p2),setCents(c),()=>{isEmpty(order)&&setPrice("")}},[order]);const parentProps={priceCents:cents,price,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:price})}export default BaseOrderPrice;
|
|
@@ -11,10 +11,10 @@ export interface TResources {
|
|
|
11
11
|
resource: 'stock_transfers';
|
|
12
12
|
};
|
|
13
13
|
Sku: Sku & {
|
|
14
|
-
resource: '
|
|
14
|
+
resource: 'sku';
|
|
15
15
|
};
|
|
16
16
|
LineItem: LineItem & {
|
|
17
|
-
resource: '
|
|
17
|
+
resource: 'lineItem';
|
|
18
18
|
};
|
|
19
19
|
Customer: Customer & {
|
|
20
20
|
resource: 'customers';
|
|
@@ -34,8 +34,8 @@ export declare type TGenericChildrenProps<E extends TResources[keyof TResources]
|
|
|
34
34
|
};
|
|
35
35
|
interface ResourceContext {
|
|
36
36
|
stock_transfers: InitialStockTransferContext;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
sku: InitialSkuContext;
|
|
38
|
+
lineItem: InitialLineItemContext;
|
|
39
39
|
customers: InitialCustomerContext;
|
|
40
40
|
parcel: InitialParcelContext;
|
|
41
41
|
parcelLineItem: InitialParcelLineItemContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./Parent";import{useContext}from"react";import{defaultImgUrl}from"../../utils/placeholderImages";export default function GenericFieldComponent(props){const{children,tagElement,attribute,context,...p}=props,resourceContext=useContext(context);let attributeValue="";const keysContext=Object.keys(resourceContext).filter(key=>key===p.resource);if(keysContext.length===1){const[keyResource]=keysContext;keyResource&&attribute&&(attributeValue=resourceContext[keyResource][attribute])}const Tag=tagElement||"span";if(Tag==="img"&&!children)return _jsx("img",{alt:"",src:attributeValue||defaultImgUrl,...p});const parentProps={attributeValue,tagElement,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx(Tag,{...p,children:attributeValue})}
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./Parent";import{useContext}from"react";import{defaultImgUrl}from"../../utils/placeholderImages";export default function GenericFieldComponent(props){const{children,tagElement,attribute,context,...p}=props,resourceContext=useContext(context);let attributeValue="";const keysContext=Object.keys(resourceContext).filter(key=>key===p.resource);if(console.log("keys",Object.keys(resourceContext)),console.log("p.resource",p.resource),console.log("keyContext",keysContext),keysContext.length===1){const[keyResource]=keysContext;keyResource&&attribute&&(attributeValue=resourceContext[keyResource][attribute])}const Tag=tagElement||"span";if(Tag==="img"&&!children)return _jsx("img",{alt:"",src:attributeValue||defaultImgUrl,...p});const parentProps={attributeValue,tagElement,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx(Tag,{...p,children:attributeValue})}
|
|
@@ -14,10 +14,10 @@ declare type CustomerPayment = PaymentSourceType & {
|
|
|
14
14
|
};
|
|
15
15
|
export declare type CustomerCardsTemplateChildren = ChildrenFunction<ChildrenProps>;
|
|
16
16
|
export declare type CustomerCardsType = ChildrenProps;
|
|
17
|
-
|
|
17
|
+
interface Props {
|
|
18
18
|
customerPayments: CustomerPayment[];
|
|
19
19
|
children: CustomerCardsTemplateChildren;
|
|
20
20
|
paymentResource: PaymentResource;
|
|
21
|
-
}
|
|
22
|
-
export default function PaymentCardsTemplate({ customerPayments, children, paymentResource
|
|
21
|
+
}
|
|
22
|
+
export default function PaymentCardsTemplate({ customerPayments, children, paymentResource }: Props): JSX.Element;
|
|
23
23
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext}from"react";import axios from"axios";export const callExternalFunction=async({url,data})=>axios.post(url,data);const ExternalFunctionContext=createContext({url:null,callExternalFunction});export default ExternalFunctionContext;
|
|
1
|
+
import{createContext}from"react";import axios from"axios";export const callExternalFunction=async({url,data})=>await axios.post(url,data);const ExternalFunctionContext=createContext({url:null,callExternalFunction});export default ExternalFunctionContext;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { LineItemState } from '../reducers/LineItemReducer';
|
|
3
3
|
import { LineItem } from '@commercelayer/sdk';
|
|
4
4
|
export interface LineItemContextValue extends LineItemState {
|
|
5
|
-
lineItems
|
|
5
|
+
lineItems?: LineItem[] | undefined;
|
|
6
6
|
}
|
|
7
7
|
declare const LineItemContext: import("react").Context<LineItemContextValue>;
|
|
8
8
|
export default LineItemContext;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Order } from '@commercelayer/sdk';
|
|
3
|
-
import {
|
|
3
|
+
import { OrderState, CreateOrder, SetGiftCardOrCouponCode, RemoveGiftCardOrCouponCode, SaveAddressToCustomerAddressBook, addResourceToInclude, updateOrder, getOrderContext, addToCart } from '../reducers/OrderReducer';
|
|
4
4
|
import { BaseError } from '../typings/errors';
|
|
5
5
|
interface DefaultContext extends OrderState {
|
|
6
6
|
createOrder: CreateOrder;
|
|
7
|
-
addToCart?:
|
|
7
|
+
addToCart?: typeof addToCart;
|
|
8
8
|
setOrderErrors: (errors: BaseError[]) => void;
|
|
9
9
|
setGiftCardOrCouponCode: SetGiftCardOrCouponCode;
|
|
10
10
|
removeGiftCardOrCouponCode: RemoveGiftCardOrCouponCode;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { UpdatePaymentSource } from '../reducers/PaymentMethodReducer';
|
|
3
|
-
import { PaymentMethodState, SetPaymentMethodErrors, SetPaymentSource, SetPaymentMethod, DestroyPaymentSource, SetPaymentRef, setLoading } from '../reducers/PaymentMethodReducer';
|
|
2
|
+
import { UpdatePaymentSource, PaymentMethodState, SetPaymentMethodErrors, SetPaymentSource, SetPaymentMethod, DestroyPaymentSource, SetPaymentRef, setLoading } from '../reducers/PaymentMethodReducer';
|
|
4
3
|
declare type DefaultContext = {
|
|
5
4
|
setPaymentMethodErrors: SetPaymentMethodErrors;
|
|
6
5
|
setPaymentMethod: SetPaymentMethod;
|
|
@@ -10,14 +9,6 @@ declare type DefaultContext = {
|
|
|
10
9
|
updatePaymentSource: UpdatePaymentSource;
|
|
11
10
|
setLoading: typeof setLoading;
|
|
12
11
|
} & PaymentMethodState;
|
|
13
|
-
export declare const defaultPaymentMethodContext:
|
|
14
|
-
setPaymentMethodErrors: SetPaymentMethodErrors;
|
|
15
|
-
setPaymentMethod: SetPaymentMethod;
|
|
16
|
-
setPaymentSource: SetPaymentSource;
|
|
17
|
-
setPaymentRef: SetPaymentRef;
|
|
18
|
-
destroyPaymentSource: DestroyPaymentSource;
|
|
19
|
-
updatePaymentSource: UpdatePaymentSource;
|
|
20
|
-
setLoading: typeof setLoading;
|
|
21
|
-
};
|
|
12
|
+
export declare const defaultPaymentMethodContext: DefaultContext;
|
|
22
13
|
declare const PaymentMethodContext: import("react").Context<DefaultContext>;
|
|
23
14
|
export default PaymentMethodContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext}from"react";import{updatePaymentSource
|
|
1
|
+
import{createContext}from"react";import{updatePaymentSource,setPaymentMethodErrors,setPaymentSource,setPaymentMethod,destroyPaymentSource,setPaymentRef,setLoading}from"../reducers/PaymentMethodReducer";export const defaultPaymentMethodContext={setPaymentMethodErrors,setPaymentMethod,setPaymentSource,setPaymentRef,destroyPaymentSource,updatePaymentSource,setLoading};const PaymentMethodContext=createContext(defaultPaymentMethodContext);export default PaymentMethodContext;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -32,13 +32,13 @@ export * from './components/gift_cards/GiftCardOrCouponSubmit';
|
|
|
32
32
|
export * from './components/line_items/LineItem';
|
|
33
33
|
export * from './components/line_items/LineItemAmount';
|
|
34
34
|
export * from './components/line_items/LineItemCode';
|
|
35
|
+
export * from './components/line_items/LineItemField';
|
|
35
36
|
export * from './components/line_items/LineItemImage';
|
|
36
37
|
export * from './components/line_items/LineItemName';
|
|
37
38
|
export * from './components/line_items/LineItemOption';
|
|
38
39
|
export * from './components/line_items/LineItemOptions';
|
|
39
40
|
export * from './components/line_items/LineItemQuantity';
|
|
40
41
|
export * from './components/line_items/LineItemRemoveLink';
|
|
41
|
-
export * from './components/line_items/LineItemsContainer';
|
|
42
42
|
export * from './components/line_items/LineItemsCount';
|
|
43
43
|
export * from './components/line_items/LineItemsEmpty';
|
|
44
44
|
export * from './components/orders/AddToCartButton';
|
|
@@ -47,13 +47,13 @@ export * from './components/orders/CartLink';
|
|
|
47
47
|
export * from './components/orders/CheckoutLink';
|
|
48
48
|
export * from './components/orders/DiscountAmount';
|
|
49
49
|
export * from './components/orders/GiftCardAmount';
|
|
50
|
-
export * from './components/orders/ItemContainer';
|
|
51
50
|
export * from './components/orders/OrderContainer';
|
|
52
51
|
export * from './components/orders/OrderList';
|
|
53
52
|
export * from './components/orders/OrderListEmpty';
|
|
54
53
|
export * from './components/orders/OrderListRow';
|
|
55
54
|
export * from './components/orders/OrderNumber';
|
|
56
55
|
export * from './components/orders/OrderStorage';
|
|
56
|
+
export * from './components/orders/PaymentMethodAmount';
|
|
57
57
|
export * from './components/orders/PlaceOrderButton';
|
|
58
58
|
export * from './components/orders/PlaceOrderContainer';
|
|
59
59
|
export * from './components/orders/PrivacyAndTermsCheckbox';
|
|
@@ -68,7 +68,6 @@ export * from './components/parcels/ParcelLineItemsCount';
|
|
|
68
68
|
export * from './components/parcels/Parcels';
|
|
69
69
|
export * from './components/parcels/ParcelsCount';
|
|
70
70
|
export * from './components/payment_methods/PaymentMethod';
|
|
71
|
-
export * from './components/payment_methods/PaymentMethodAmount';
|
|
72
71
|
export * from './components/payment_methods/PaymentMethodName';
|
|
73
72
|
export * from './components/payment_methods/PaymentMethodPrice';
|
|
74
73
|
export * from './components/payment_methods/PaymentMethodRadioButton';
|
|
@@ -91,26 +90,14 @@ export * from './components/shipping_methods/ShippingMethodRadioButton';
|
|
|
91
90
|
export * from './components/skus/AvailabilityContainer';
|
|
92
91
|
export * from './components/skus/AvailabilityTemplate';
|
|
93
92
|
export * from './components/skus/DeliveryLeadTime';
|
|
94
|
-
export * from './components/skus/QuantitySelector';
|
|
95
93
|
export * from './components/skus/SkuField';
|
|
96
94
|
export * from './components/skus/SkuList';
|
|
97
95
|
export * from './components/skus/SkuListsContainer';
|
|
98
|
-
export * from './components/skus/SkuOption';
|
|
99
|
-
export * from './components/skus/SkuOptionInput';
|
|
100
|
-
export * from './components/skus/SkuOptionsContainer';
|
|
101
96
|
export * from './components/skus/Skus';
|
|
102
97
|
export * from './components/skus/SkusContainer';
|
|
103
|
-
export * from './components/skus/VariantSelector';
|
|
104
|
-
export * from './components/skus/VariantsContainer';
|
|
105
98
|
export * from './components/stock_transfers/StockTransfer';
|
|
106
99
|
export * from './components/stock_transfers/StockTransferField';
|
|
107
100
|
export type { CustomerCardsType } from './components/utils/PaymentCardsTemplate';
|
|
108
|
-
export type { AddressCardsType } from './components/utils/AddressCardsTemplate';
|
|
109
|
-
export type { AddToCartButtonType } from './components/orders/AddToCartButton';
|
|
110
101
|
export type { ShippingMethodRadioButtonType, ShippingMethodRadioButtonOnChangeType } from './components/shipping_methods/ShippingMethodRadioButton';
|
|
111
|
-
export type { LineItemCodeType } from './components/line_items/LineItemCode';
|
|
112
|
-
export type { LineItemNameType } from './components/line_items/LineItemName';
|
|
113
|
-
export type { LineItemImageType } from './components/line_items/LineItemImage';
|
|
114
|
-
export type { LineItemType } from './typings/index';
|
|
115
102
|
export type { ErrorComponentProps, ResourceErrorType } from './typings/errors';
|
|
116
|
-
export type { AddressCountrySelectName, AddressInputName, AddressStateSelectName, BaseInputType } from './typings/index';
|
|
103
|
+
export type { AddressCountrySelectName, AddressInputName, AddressStateSelectName, BaseInputType, LineItemType } from './typings/index';
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./components/Errors";export*from"./components/ExternalFunction";export*from"./components/MetadataInput";export*from"./components/SubmitButton";export*from"./components/addresses/Address";export*from"./components/addresses/AddressCountrySelector";export*from"./components/addresses/AddressField";export*from"./components/addresses/AddressInput";export*from"./components/addresses/AddressStateSelector";export*from"./components/addresses/AddressesContainer";export*from"./components/addresses/AddressesEmpty";export*from"./components/addresses/BillingAddressContainer";export*from"./components/addresses/BillingAddressForm";export*from"./components/addresses/SaveAddressesButton";export*from"./components/addresses/ShippingAddressContainer";export*from"./components/addresses/ShippingAddressForm";export*from"./components/auth/CommerceLayer";export*from"./components/customers/CustomerAddressForm";export*from"./components/customers/CustomerContainer";export*from"./components/customers/CustomerField";export*from"./components/customers/CustomerInput";export*from"./components/customers/SaveCustomerButton";export*from"./components/gift_cards/GiftCard";export*from"./components/gift_cards/GiftCardContainer";export*from"./components/gift_cards/GiftCardCurrencySelector";export*from"./components/gift_cards/GiftCardInput";export*from"./components/gift_cards/GiftCardOrCouponCode";export*from"./components/gift_cards/GiftCardOrCouponForm";export*from"./components/gift_cards/GiftCardOrCouponInput";export*from"./components/gift_cards/GiftCardOrCouponRemoveButton";export*from"./components/gift_cards/GiftCardOrCouponSubmit";export*from"./components/line_items/LineItem";export*from"./components/line_items/LineItemAmount";export*from"./components/line_items/LineItemCode";export*from"./components/line_items/
|
|
1
|
+
export*from"./components/Errors";export*from"./components/ExternalFunction";export*from"./components/MetadataInput";export*from"./components/SubmitButton";export*from"./components/addresses/Address";export*from"./components/addresses/AddressCountrySelector";export*from"./components/addresses/AddressField";export*from"./components/addresses/AddressInput";export*from"./components/addresses/AddressStateSelector";export*from"./components/addresses/AddressesContainer";export*from"./components/addresses/AddressesEmpty";export*from"./components/addresses/BillingAddressContainer";export*from"./components/addresses/BillingAddressForm";export*from"./components/addresses/SaveAddressesButton";export*from"./components/addresses/ShippingAddressContainer";export*from"./components/addresses/ShippingAddressForm";export*from"./components/auth/CommerceLayer";export*from"./components/customers/CustomerAddressForm";export*from"./components/customers/CustomerContainer";export*from"./components/customers/CustomerField";export*from"./components/customers/CustomerInput";export*from"./components/customers/SaveCustomerButton";export*from"./components/gift_cards/GiftCard";export*from"./components/gift_cards/GiftCardContainer";export*from"./components/gift_cards/GiftCardCurrencySelector";export*from"./components/gift_cards/GiftCardInput";export*from"./components/gift_cards/GiftCardOrCouponCode";export*from"./components/gift_cards/GiftCardOrCouponForm";export*from"./components/gift_cards/GiftCardOrCouponInput";export*from"./components/gift_cards/GiftCardOrCouponRemoveButton";export*from"./components/gift_cards/GiftCardOrCouponSubmit";export*from"./components/line_items/LineItem";export*from"./components/line_items/LineItemAmount";export*from"./components/line_items/LineItemCode";export*from"./components/line_items/LineItemField";export*from"./components/line_items/LineItemImage";export*from"./components/line_items/LineItemName";export*from"./components/line_items/LineItemOption";export*from"./components/line_items/LineItemOptions";export*from"./components/line_items/LineItemQuantity";export*from"./components/line_items/LineItemRemoveLink";export*from"./components/line_items/LineItemsCount";export*from"./components/line_items/LineItemsEmpty";export*from"./components/orders/AddToCartButton";export*from"./components/orders/AdjustmentAmount";export*from"./components/orders/CartLink";export*from"./components/orders/CheckoutLink";export*from"./components/orders/DiscountAmount";export*from"./components/orders/GiftCardAmount";export*from"./components/orders/OrderContainer";export*from"./components/orders/OrderList";export*from"./components/orders/OrderListEmpty";export*from"./components/orders/OrderListRow";export*from"./components/orders/OrderNumber";export*from"./components/orders/OrderStorage";export*from"./components/orders/PaymentMethodAmount";export*from"./components/orders/PlaceOrderButton";export*from"./components/orders/PlaceOrderContainer";export*from"./components/orders/PrivacyAndTermsCheckbox";export*from"./components/orders/ShippingAmount";export*from"./components/orders/SubTotalAmount";export*from"./components/orders/TaxesAmount";export*from"./components/orders/TotalAmount";export*from"./components/parcels/ParcelField";export*from"./components/parcels/ParcelLineItem";export*from"./components/parcels/ParcelLineItemField";export*from"./components/parcels/ParcelLineItemsCount";export*from"./components/parcels/Parcels";export*from"./components/parcels/ParcelsCount";export*from"./components/payment_methods/PaymentMethod";export*from"./components/payment_methods/PaymentMethodName";export*from"./components/payment_methods/PaymentMethodPrice";export*from"./components/payment_methods/PaymentMethodRadioButton";export*from"./components/payment_methods/PaymentMethodsContainer";export*from"./components/payment_source/PaymentSource";export*from"./components/payment_source/PaymentSourceBrandIcon";export*from"./components/payment_source/PaymentSourceBrandName";export*from"./components/payment_source/PaymentSourceDetail";export*from"./components/payment_source/PaymentSourceEditButton";export*from"./components/prices/Price";export*from"./components/prices/PricesContainer";export*from"./components/shipments/Shipment";export*from"./components/shipments/ShipmentField";export*from"./components/shipments/ShipmentsContainer";export*from"./components/shipments/ShipmentsCount";export*from"./components/shipping_methods/ShippingMethod";export*from"./components/shipping_methods/ShippingMethodName";export*from"./components/shipping_methods/ShippingMethodPrice";export*from"./components/shipping_methods/ShippingMethodRadioButton";export*from"./components/skus/AvailabilityContainer";export*from"./components/skus/AvailabilityTemplate";export*from"./components/skus/DeliveryLeadTime";export*from"./components/skus/SkuField";export*from"./components/skus/SkuList";export*from"./components/skus/SkuListsContainer";export*from"./components/skus/Skus";export*from"./components/skus/SkusContainer";export*from"./components/stock_transfers/StockTransfer";export*from"./components/stock_transfers/StockTransferField";
|
|
@@ -2,7 +2,6 @@ import { BaseError } from '../typings/errors';
|
|
|
2
2
|
import { Sku } from '@commercelayer/sdk';
|
|
3
3
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
4
4
|
import { Dispatch } from 'react';
|
|
5
|
-
import { Items } from './ItemReducer';
|
|
6
5
|
export interface DeliveryLeadTime {
|
|
7
6
|
shipping_method: {
|
|
8
7
|
name: string;
|
|
@@ -32,8 +31,9 @@ export interface LeadTimes {
|
|
|
32
31
|
days: number;
|
|
33
32
|
}
|
|
34
33
|
export declare type AvailabilityPayload = {
|
|
35
|
-
quantity?: number
|
|
34
|
+
quantity?: number;
|
|
36
35
|
errors?: BaseError[];
|
|
36
|
+
parent?: boolean;
|
|
37
37
|
} & Partial<DeliveryLeadTime>;
|
|
38
38
|
export declare type AvailabilityState = AvailabilityPayload;
|
|
39
39
|
export interface AvailabilityAction {
|
|
@@ -41,21 +41,11 @@ export interface AvailabilityAction {
|
|
|
41
41
|
payload: AvailabilityPayload;
|
|
42
42
|
}
|
|
43
43
|
export declare const availabilityInitialState: AvailabilityState;
|
|
44
|
-
declare
|
|
44
|
+
export declare function getAvailability({ skuCode, dispatch, config }: {
|
|
45
45
|
skuCode: string;
|
|
46
46
|
dispatch: Dispatch<AvailabilityAction>;
|
|
47
47
|
config: CommerceLayerConfig;
|
|
48
|
-
|
|
49
|
-
item?: Items;
|
|
50
|
-
}) => void;
|
|
51
|
-
export declare const getAvailability: GetAvailability;
|
|
52
|
-
interface GetAvailabilityArgs {
|
|
53
|
-
skusIds: string[];
|
|
54
|
-
dispatch: Dispatch<AvailabilityAction>;
|
|
55
|
-
config: CommerceLayerConfig;
|
|
56
|
-
setItem?: (item: Items) => void;
|
|
57
|
-
}
|
|
58
|
-
export declare function getAvailabilityByIds({ skusIds, config, setItem }: GetAvailabilityArgs): Promise<void>;
|
|
48
|
+
}): Promise<void>;
|
|
59
49
|
export declare type AvailabilityActionType = 'setAvailability' | 'setErrors';
|
|
60
50
|
declare const availabilityReducer: (state: AvailabilityState, reducer: AvailabilityAction) => AvailabilityState;
|
|
61
51
|
export default availabilityReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const availabilityInitialState={
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";export const availabilityInitialState={};export async function getAvailability({skuCode,dispatch,config}){const sdk=getSdk(config);try{const[sku]=await sdk.skus.list({fields:{skus:["id"]},filters:{code_in:skuCode}});if(sku){const skuInventory=await sdk.skus.retrieve(sku.id,{fields:{skus:["inventory"]}}),[level]=skuInventory.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];dispatch({type:"setAvailability",payload:{...delivery,quantity:skuInventory.inventory.quantity}})}}catch(error){console.error("Get SKU availability",error)}}const typeAction=["setAvailability","setErrors"],availabilityReducer=(state,reducer)=>baseReducer(state,reducer,typeAction);export default availabilityReducer;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Dispatch } from 'react';
|
|
2
2
|
import { SetLocalOrder, DeleteLocalOrder } from '../utils/localStorage';
|
|
3
3
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
4
|
-
import { ItemOption, CustomLineItem } from './ItemReducer';
|
|
5
4
|
import { BaseMetadataObject } from '../typings/index';
|
|
6
5
|
import { BaseError } from '../typings/errors';
|
|
7
6
|
import { AddressResource } from './AddressReducer';
|
|
@@ -18,24 +17,6 @@ export declare type GetOrderParams = Partial<{
|
|
|
18
17
|
export declare type GetOrder = (params: GetOrderParams) => Promise<undefined | Order>;
|
|
19
18
|
declare type CreateOrderParams = Pick<AddToCartParams, 'config' | 'dispatch' | 'persistKey' | 'state' | 'orderMetadata' | 'orderAttributes' | 'setLocalOrder'>;
|
|
20
19
|
export declare type CreateOrder = (params?: CreateOrderParams) => Promise<string>;
|
|
21
|
-
export declare type AddToCartParams = Partial<{
|
|
22
|
-
bundleCode: string;
|
|
23
|
-
skuCode: string;
|
|
24
|
-
persistKey: string;
|
|
25
|
-
config: CommerceLayerConfig;
|
|
26
|
-
dispatch: Dispatch<OrderActions>;
|
|
27
|
-
state: Partial<OrderState>;
|
|
28
|
-
skuId: string;
|
|
29
|
-
quantity: number;
|
|
30
|
-
option: ItemOption;
|
|
31
|
-
lineItem: CustomLineItem;
|
|
32
|
-
orderMetadata: BaseMetadataObject;
|
|
33
|
-
orderAttributes: Record<string, any>;
|
|
34
|
-
errors: BaseError[];
|
|
35
|
-
setLocalOrder: SetLocalOrder;
|
|
36
|
-
buyNowMode: boolean;
|
|
37
|
-
checkoutUrl: string;
|
|
38
|
-
}>;
|
|
39
20
|
export interface AddToCartImportParams extends Omit<AddToCartParams, 'skuCode' | 'skuId' | 'quantity' | 'option' | 'lineItem'> {
|
|
40
21
|
lineItems: CustomLineItem[];
|
|
41
22
|
}
|
|
@@ -43,7 +24,6 @@ export declare type AddToCartReturn = Promise<{
|
|
|
43
24
|
success: boolean;
|
|
44
25
|
orderId: string | undefined;
|
|
45
26
|
}>;
|
|
46
|
-
export declare type AddToCart = (params: AddToCartParams) => AddToCartReturn;
|
|
47
27
|
export declare type AddToCartImport = (params: AddToCartImportParams) => AddToCartReturn;
|
|
48
28
|
export declare type UnsetOrderState = (dispatch: Dispatch<OrderActions>) => void;
|
|
49
29
|
export declare type ResourceIncluded = 'billing_address' | 'shipping_address' | 'line_items.line_item_options.sku_option' | 'line_items.item' | 'available_customer_payment_sources.payment_source' | 'shipments.available_shipping_methods' | 'shipments.stock_transfers' | 'shipments.stock_transfers.line_item' | 'shipments.shipment_line_items.line_item' | 'shipments.shipping_method' | 'shipments.stock_location' | 'shipments.parcels' | 'shipments.parcels.parcel_line_items' | 'payment_source' | 'available_payment_methods' | 'payment_method';
|
|
@@ -57,7 +37,6 @@ export interface OrderPayload {
|
|
|
57
37
|
includeLoaded?: ResourceIncludedLoaded;
|
|
58
38
|
withoutIncludes?: boolean;
|
|
59
39
|
}
|
|
60
|
-
export declare type AddToCartValues = Pick<AddToCartParams, 'bundleCode' | 'lineItem' | 'quantity' | 'skuCode' | 'skuId' | 'option' | 'buyNowMode' | 'checkoutUrl'>;
|
|
61
40
|
export declare type AddToCartImportValues = Pick<AddToCartImportParams, 'lineItems'>;
|
|
62
41
|
export declare type getOrderContext = (id: string) => Promise<undefined | Order>;
|
|
63
42
|
export declare type OrderState = Partial<OrderPayload>;
|
|
@@ -89,7 +68,42 @@ export interface AddResourceToInclude {
|
|
|
89
68
|
newResourceLoaded?: ResourceIncludedLoaded;
|
|
90
69
|
}
|
|
91
70
|
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, newResourceLoaded, resourceIncludedLoaded }: AddResourceToInclude): void;
|
|
92
|
-
export
|
|
71
|
+
export interface LineItemOption {
|
|
72
|
+
/**
|
|
73
|
+
* SKU Option ID. Ex: mNJEgsJwBn
|
|
74
|
+
*/
|
|
75
|
+
skuOptionId: string;
|
|
76
|
+
/**
|
|
77
|
+
* Set of key-value pairs that represent the selected options. Ex: { message: 'This is a option message' }
|
|
78
|
+
*/
|
|
79
|
+
options: Record<string, string>;
|
|
80
|
+
quantity?: number;
|
|
81
|
+
}
|
|
82
|
+
export interface CustomLineItem {
|
|
83
|
+
name?: string;
|
|
84
|
+
imageUrl?: string | null;
|
|
85
|
+
}
|
|
86
|
+
export declare type AddToCartParams = Partial<{
|
|
87
|
+
bundleCode: string;
|
|
88
|
+
skuCode: string;
|
|
89
|
+
persistKey: string;
|
|
90
|
+
config: CommerceLayerConfig;
|
|
91
|
+
dispatch: Dispatch<OrderActions>;
|
|
92
|
+
state: Partial<OrderState>;
|
|
93
|
+
quantity: number;
|
|
94
|
+
lineItemOption: LineItemOption;
|
|
95
|
+
lineItem: CustomLineItem;
|
|
96
|
+
orderMetadata: BaseMetadataObject;
|
|
97
|
+
orderAttributes: Record<string, any>;
|
|
98
|
+
errors: BaseError[];
|
|
99
|
+
setLocalOrder: SetLocalOrder;
|
|
100
|
+
buyNowMode: boolean;
|
|
101
|
+
checkoutUrl: string;
|
|
102
|
+
}>;
|
|
103
|
+
export declare function addToCart(params: AddToCartParams): Promise<{
|
|
104
|
+
success: boolean;
|
|
105
|
+
orderId?: string;
|
|
106
|
+
}>;
|
|
93
107
|
export declare const unsetOrderState: UnsetOrderState;
|
|
94
108
|
interface OrderErrors {
|
|
95
109
|
dispatch?: Dispatch<OrderActions>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import
|
|
1
|
+
import{setCustomerOrderParam}from"../utils/localStorage";import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import getErrors,{setErrors}from"../utils/getErrors";import getOrganizationSlug from"../utils/organization";const actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"];export const createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=getSdk(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=getErrors(error,"orders");console.error("Create order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""},getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=getSdk(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.status==="placed"||clearWhenPlaced&&order.status==="approved"||clearWhenPlaced&&order.status==="cancelled"?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=getErrors(error,"orders");console.error("Retrieve order",errors),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors,dispatch});return}};export async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=getSdk(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await getApiOrder({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0}}catch(error){const errors=getErrors(error,"orders");return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}export const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};export function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...resourcesIncluded,...resources],resources.forEach(resource=>{const includeLoaded={...payload.includeLoaded,[resource]:!0};payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded};payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}export async function addToCart(params){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=getSdk(config),id=await createOrder(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items:lineItems}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&await Promise.all(lineItems.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity??1,_update_quantity:!0,bundle_code:bundleCode},newLineItem=await sdk.line_items.create(attrs);if(lineItemOption!=null){const{skuOptionId,options,quantity:quantity2}=lineItemOption,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:quantity2??1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),await getApiOrder({id,...params})}else await getApiOrder({id,...params,state});if(!isEmpty(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=getOrganizationSlug(config.endpoint??""),params2=`${id}?accessToken=${config.accessToken??""}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}}return{success:!1}}catch(error){const errors2=getErrors(error,"orders");return console.error("Add to cart",errors2),dispatch&&setErrors({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}}export const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};export function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}export const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;setCustomerOrderParam(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})},setGiftCardOrCouponCode=async({code,codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},removeGiftCardOrCouponCode=async({codeType,dispatch,config,order,include,state})=>{try{if(config&&order&&dispatch){const attributes={[codeType]:""};return await updateOrder({id:order.id,attributes,config,include,dispatch,state}),dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0}}return{success:!1}}catch(error){const errors=getErrors(error,"orders",codeType);return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}},orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default orderReducer;
|
|
@@ -10,14 +10,14 @@ import { Order, PaymentMethod, StripePayment, WireTransfer, AdyenPayment, Braint
|
|
|
10
10
|
import { Dispatch, MutableRefObject } from 'react';
|
|
11
11
|
import { CheckoutComConfig } from '../components/payment_source/CheckoutComPayment';
|
|
12
12
|
export declare type PaymentSourceType = AdyenPayment | BraintreePayment | CheckoutComPayment | ExternalPayment | PaypalPayment | StripePayment | WireTransfer;
|
|
13
|
-
|
|
13
|
+
interface Card {
|
|
14
14
|
type: string;
|
|
15
15
|
brand: string;
|
|
16
16
|
last4: string;
|
|
17
17
|
exp_year: number;
|
|
18
18
|
exp_month: number;
|
|
19
|
-
}
|
|
20
|
-
export
|
|
19
|
+
}
|
|
20
|
+
export interface PaymentSourceObject {
|
|
21
21
|
adyen_payments: AdyenPayment & {
|
|
22
22
|
payment_request_data?: {
|
|
23
23
|
payment_method?: Card;
|
|
@@ -51,7 +51,7 @@ export declare type PaymentSourceObject = {
|
|
|
51
51
|
};
|
|
52
52
|
};
|
|
53
53
|
klarna_payments: KlarnaPayment;
|
|
54
|
-
}
|
|
54
|
+
}
|
|
55
55
|
export declare type PaymentMethodActionType = 'setErrors' | 'setPaymentMethods' | 'setPaymentMethodConfig' | 'setPaymentSource' | 'setPaymentRef' | 'setLoading';
|
|
56
56
|
export declare type PaymentRef = MutableRefObject<null | HTMLFormElement>;
|
|
57
57
|
export interface PaymentMethodActionPayload {
|
|
@@ -64,7 +64,7 @@ export interface PaymentMethodActionPayload {
|
|
|
64
64
|
paymentSource: PaymentSourceTypes;
|
|
65
65
|
loading: boolean;
|
|
66
66
|
}
|
|
67
|
-
export declare function setLoading({ loading, dispatch
|
|
67
|
+
export declare function setLoading({ loading, dispatch }: {
|
|
68
68
|
loading: boolean;
|
|
69
69
|
dispatch?: Dispatch<PaymentMethodAction>;
|
|
70
70
|
}): void;
|
|
@@ -79,9 +79,7 @@ export interface PaymentMethodAction {
|
|
|
79
79
|
payload: Partial<PaymentMethodActionPayload>;
|
|
80
80
|
}
|
|
81
81
|
export declare const paymentMethodInitialState: PaymentMethodState;
|
|
82
|
-
export
|
|
83
|
-
<V extends BaseError[]>(errors: V, dispatch?: Dispatch<PaymentMethodAction>): void;
|
|
84
|
-
}
|
|
82
|
+
export declare type SetPaymentMethodErrors = <V extends BaseError[]>(errors: V, dispatch?: Dispatch<PaymentMethodAction>) => void;
|
|
85
83
|
export declare const setPaymentMethodErrors: SetPaymentMethodErrors;
|
|
86
84
|
declare type GetPaymentMethods = (args: {
|
|
87
85
|
order: Order;
|
|
@@ -118,7 +116,7 @@ export declare type SetPaymentSource = (args: {
|
|
|
118
116
|
paymentSourceId?: string;
|
|
119
117
|
customerPaymentSourceId?: string;
|
|
120
118
|
updateOrder?: typeof updateOrder;
|
|
121
|
-
} & PaymentMethodState) => Promise<PaymentSourceType |
|
|
119
|
+
} & PaymentMethodState) => Promise<PaymentSourceType | undefined>;
|
|
122
120
|
export declare const setPaymentSource: SetPaymentSource;
|
|
123
121
|
export declare type UpdatePaymentSource = (args: {
|
|
124
122
|
id: string;
|
|
@@ -136,7 +134,7 @@ export declare type DestroyPaymentSource = (args: {
|
|
|
136
134
|
orderId?: string;
|
|
137
135
|
}) => Promise<void>;
|
|
138
136
|
export declare const destroyPaymentSource: DestroyPaymentSource;
|
|
139
|
-
export
|
|
137
|
+
export interface PaymentMethodConfig {
|
|
140
138
|
stripePayment?: StripeConfig;
|
|
141
139
|
braintreePayment?: BraintreeConfig;
|
|
142
140
|
wireTransfer?: Partial<WireTransferConfig>;
|
|
@@ -144,7 +142,7 @@ export declare type PaymentMethodConfig = {
|
|
|
144
142
|
adyenPayment?: AdyenPaymentConfig;
|
|
145
143
|
checkoutComPayment?: CheckoutComConfig;
|
|
146
144
|
klarnaPayment?: Pick<AdyenPaymentConfig, 'placeOrderCallback'> & Pick<StripeConfig, 'containerClassName'>;
|
|
147
|
-
}
|
|
145
|
+
}
|
|
148
146
|
declare type SetPaymentMethodConfig = (config: PaymentMethodConfig, dispatch: Dispatch<PaymentMethodAction>) => void;
|
|
149
147
|
export declare const setPaymentMethodConfig: SetPaymentMethodConfig;
|
|
150
148
|
export declare function getPaymentConfig<K extends PaymentResourceKey>(paymentResource: PaymentResource, config: PaymentMethodConfig): PaymentMethodConfig[K];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getErrors,{setErrors}from"../utils/getErrors";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function setLoading({loading,dispatch}){dispatch&&dispatch({type:"setLoading",payload:{loading}})}export const setPaymentRef=({ref,dispatch})=>{ref&&dispatch&&dispatch({type:"setPaymentRef",payload:{currentPaymentMethodRef:ref}})},paymentMethodInitialState={errors:[]},setPaymentMethodErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},getPaymentMethods=async({order,dispatch})=>{const paymentMethods=order.available_payment_methods,paymentMethod=order.payment_method,paymentSource=order.payment_source;dispatch({type:"setPaymentMethods",payload:{paymentMethods,currentPaymentMethodId:paymentMethod?.id,currentPaymentMethodType:paymentMethod?.payment_source_type,paymentSource}})},setPaymentMethod=async({config,dispatch,order,paymentMethodId,updateOrder,setOrderErrors,paymentResource})=>{try{if(config&&order&&dispatch&&paymentResource){localStorage.removeItem("_save_payment_source_to_customer_wallet");const attributes={payment_method:getSdk(config).payment_methods.relationship(paymentMethodId)};updateOrder&&await updateOrder({id:order.id,attributes}),dispatch({type:"setPaymentMethods",payload:{currentPaymentMethodId:paymentMethodId,currentPaymentMethodType:paymentResource,errors:[]}}),setOrderErrors&&setOrderErrors([])}}catch(error){const errors=getErrors(error,"orders",paymentResource);console.error("Set payment method",errors)}},setPaymentSource=async({config,dispatch,getOrder,attributes
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getErrors,{setErrors}from"../utils/getErrors";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function setLoading({loading,dispatch}){dispatch&&dispatch({type:"setLoading",payload:{loading}})}export const setPaymentRef=({ref,dispatch})=>{ref&&dispatch&&dispatch({type:"setPaymentRef",payload:{currentPaymentMethodRef:ref}})},paymentMethodInitialState={errors:[],paymentMethods:void 0},setPaymentMethodErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},getPaymentMethods=async({order,dispatch})=>{const paymentMethods=order.available_payment_methods,paymentMethod=order.payment_method,paymentSource=order.payment_source;dispatch({type:"setPaymentMethods",payload:{paymentMethods,currentPaymentMethodId:paymentMethod?.id,currentPaymentMethodType:paymentMethod?.payment_source_type,paymentSource}})},setPaymentMethod=async({config,dispatch,order,paymentMethodId,updateOrder,setOrderErrors,paymentResource})=>{try{if(config&&order&&dispatch&&paymentResource){localStorage.removeItem("_save_payment_source_to_customer_wallet");const attributes={payment_method:getSdk(config).payment_methods.relationship(paymentMethodId)};updateOrder&&await updateOrder({id:order.id,attributes}),dispatch({type:"setPaymentMethods",payload:{currentPaymentMethodId:paymentMethodId,currentPaymentMethodType:paymentResource,errors:[]}}),setOrderErrors&&setOrderErrors([])}}catch(error){const errors=getErrors(error,"orders",paymentResource);console.error("Set payment method",errors)}},setPaymentSource=async({config,dispatch,getOrder,attributes,order,paymentResource,customerPaymentSourceId,paymentSourceId,updateOrder,errors:currentErrors})=>{try{if(config&&order){let paymentSource;const sdk=getSdk(config);if(customerPaymentSourceId)updateOrder&&await updateOrder({id:order.id,attributes:{_customer_payment_source_id:customerPaymentSourceId}});else{if(paymentSourceId){const attrs={id:paymentSourceId,...attributes};paymentSource=attributes!=null?await sdk[paymentResource].update(attrs):sdk[paymentResource].retrieve(paymentSourceId)}else{const attrs={...attributes,order:sdk.orders.relationship(order.id)};paymentSource=await sdk[paymentResource].create(attrs)}return getOrder&&await getOrder(order.id),dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource,errors:[]}}),paymentSource}}}catch(error){const errors=getErrors(error,"payment_methods",paymentResource);console.error("Set payment source:",errors),dispatch&&setErrors({currentErrors,newErrors:errors,dispatch})}},updatePaymentSource=async({id,attributes,config,dispatch,paymentResource})=>{if(config)try{const paymentSource=await getSdk(config)[paymentResource].update({id,...attributes});dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource}})}catch(err){console.error("Update payment source:",err)}},destroyPaymentSource=async({paymentSourceId,paymentResource,dispatch})=>{paymentSourceId&&paymentResource&&dispatch&&dispatch({type:"setPaymentSource",payload:{paymentSource:void 0}})},setPaymentMethodConfig=(config,dispatch)=>{dispatch({type:"setPaymentMethodConfig",payload:{config}})};export function getPaymentConfig(paymentResource,config){const resource=camelCase(paymentResource).replace("Payments","Payment").replace("Transfers","Transfer");return!isEmpty(config)&&has(config,resource)?config[resource]:void 0}const type=["setErrors","setPaymentMethodConfig","setPaymentMethods","setPaymentSource","setPaymentRef","setLoading"],paymentMethodReducer=(state,reducer)=>baseReducer(state,reducer,type);export default paymentMethodReducer;
|
|
@@ -2,42 +2,35 @@ import { BaseAction, LoaderType } from '../typings/index';
|
|
|
2
2
|
import { Price } from '@commercelayer/sdk';
|
|
3
3
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
4
4
|
import { Dispatch } from 'react';
|
|
5
|
-
import { ItemPrices } from './ItemReducer';
|
|
6
5
|
import { BaseError } from '../typings/errors';
|
|
7
6
|
export interface Prices {
|
|
8
7
|
[key: string]: Price | Price[];
|
|
9
8
|
}
|
|
10
9
|
declare type SkuCodesPrice = string[];
|
|
11
|
-
export interface SetSkuCodesPrice {
|
|
12
|
-
(skuCodes: SkuCodesPrice): void;
|
|
13
|
-
}
|
|
14
10
|
export interface PriceState {
|
|
15
11
|
loading: boolean;
|
|
16
12
|
prices: Prices;
|
|
17
13
|
skuCodes: SkuCodesPrice;
|
|
18
14
|
errors?: BaseError[];
|
|
19
15
|
skuCode?: string;
|
|
20
|
-
setSkuCodes?:
|
|
16
|
+
setSkuCodes?: typeof setSkuCodes;
|
|
21
17
|
loader?: LoaderType;
|
|
22
18
|
}
|
|
23
19
|
export interface PriceAction extends BaseAction {
|
|
24
20
|
type: PriceActionType;
|
|
25
21
|
}
|
|
26
22
|
export declare const priceInitialState: PriceState;
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
export declare
|
|
38
|
-
export interface UnsetPriceState {
|
|
39
|
-
(dispatch: Dispatch<PriceAction>): void;
|
|
40
|
-
}
|
|
23
|
+
export declare function setSkuCodes({ skuCodes, dispatch }: {
|
|
24
|
+
skuCodes: SkuCodesPrice;
|
|
25
|
+
dispatch?: Dispatch<PriceAction>;
|
|
26
|
+
}): void;
|
|
27
|
+
export declare function getSkusPrice(skuCodes: SkuCodesPrice, { config, dispatch, perPage, filters }: {
|
|
28
|
+
config: CommerceLayerConfig;
|
|
29
|
+
dispatch: Dispatch<PriceAction>;
|
|
30
|
+
perPage: number;
|
|
31
|
+
filters: Record<string, any>;
|
|
32
|
+
}): void;
|
|
33
|
+
export declare type UnsetPriceState = (dispatch: Dispatch<PriceAction>) => void;
|
|
41
34
|
export declare const unsetPriceState: UnsetPriceState;
|
|
42
35
|
export declare type PriceActionType = 'setLoading' | 'setPrices' | 'setSkuCodes' | 'setErrors';
|
|
43
36
|
declare const priceReducer: (state: PriceState, reducer: PriceAction) => PriceState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import getPrices from"../utils/getPrices";import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const priceInitialState={loading:!0,prices:{},skuCodes:[],errors:[]},getSkusPrice
|
|
1
|
+
import getPrices from"../utils/getPrices";import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const priceInitialState={loading:!0,prices:{},skuCodes:[],errors:[]};export function setSkuCodes({skuCodes,dispatch}){dispatch&&dispatch({type:"setSkuCodes",payload:{skuCodes}})}export function getSkusPrice(skuCodes,{config,dispatch,perPage,filters}){let allPrices={};const sdk=getSdk(config);sdk.prices.list({filters:{sku_code_in:skuCodes.join(","),...filters},pageSize:perPage}).then(async response=>{const pricesObj=getPrices(response);allPrices={...allPrices,...pricesObj},dispatch({type:"setPrices",payload:{prices:allPrices}}),dispatch({type:"setLoading",payload:{loading:!1}});const meta=response.meta;if(meta.pageCount>1)for(let pageNumber=meta.currentPage+1;pageNumber<=meta.pageCount;pageNumber++){const pageResponse=await sdk.prices.list({filters:{sku_code_in:skuCodes.join(","),...filters},pageSize:perPage,pageNumber}),pricesObj2=getPrices(pageResponse);allPrices={...allPrices,...pricesObj2},dispatch({type:"setPrices",payload:{prices:allPrices}})}}).catch(error=>{const errors=getErrors(error,"prices");dispatch({type:"setErrors",payload:{errors}})})}export const unsetPriceState=dispatch=>{dispatch({type:"setPrices",payload:{prices:{}}}),dispatch({type:"setLoading",payload:{loading:!1}})};const typeAction=["setLoading","setPrices","setSkuCodes","setErrors"],priceReducer=(state,reducer)=>baseReducer(state,reducer,typeAction);export default priceReducer;
|
|
@@ -10,12 +10,12 @@ export declare type SkuState = Partial<{
|
|
|
10
10
|
skuCodes: string[];
|
|
11
11
|
}>;
|
|
12
12
|
export declare const skuInitialState: SkuState;
|
|
13
|
-
|
|
13
|
+
interface GetSku {
|
|
14
14
|
config: CommerceLayerConfig;
|
|
15
15
|
skus: string[];
|
|
16
16
|
dispatch: Dispatch<SkuAction>;
|
|
17
17
|
queryParams?: QueryParamsList;
|
|
18
|
-
}
|
|
19
|
-
export declare function getSku<T extends GetSku>({ config, skus, dispatch, queryParams
|
|
18
|
+
}
|
|
19
|
+
export declare function getSku<T extends GetSku>({ config, skus, dispatch, queryParams }: T): Promise<void>;
|
|
20
20
|
export default function skuReducer(state: SkuState, reducer: SkuAction): SkuState;
|
|
21
21
|
export {};
|
|
@@ -27,7 +27,7 @@ export declare const ErrorPropTypes: {
|
|
|
27
27
|
declare type ErrorChildrenComponentProps = ChildrenFunction<Omit<ErrorComponentProps, 'children'> & {
|
|
28
28
|
errors: string[];
|
|
29
29
|
}>;
|
|
30
|
-
export
|
|
30
|
+
export interface ErrorComponentProps {
|
|
31
31
|
/**
|
|
32
32
|
* Resource which caused the error
|
|
33
33
|
*/
|
|
@@ -40,12 +40,12 @@ export declare type ErrorComponentProps = {
|
|
|
40
40
|
/**
|
|
41
41
|
* Error message which you can translate
|
|
42
42
|
*/
|
|
43
|
-
messages?: {
|
|
43
|
+
messages?: Array<{
|
|
44
44
|
code: CodeErrorType;
|
|
45
45
|
message: string;
|
|
46
46
|
resource?: ResourceErrorType;
|
|
47
47
|
field?: string;
|
|
48
48
|
id?: string;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
51
|
export {};
|