@commercelayer/react-components 4.0.0-alpha.9 → 4.0.0-beta.1
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/auth/CommerceLayer.d.ts +2 -2
- 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 +34 -9
- 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/CartLink.js +1 -1
- package/lib/cjs/components/orders/CheckoutLink.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.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.d.ts +18 -0
- package/lib/cjs/components/parcels/ParcelLineItemsCount.js +1 -0
- package/lib/cjs/components/parcels/ParcelsCount.js +1 -1
- package/lib/cjs/components/payment_gateways/AdyenGateway.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/CommerceLayerContext.d.ts +2 -2
- package/lib/cjs/context/CommerceLayerContext.js +1 -1
- 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 -3
- package/lib/cjs/context/OrderContext.js +1 -1
- package/lib/cjs/context/PaymentMethodContext.d.ts +2 -11
- package/lib/cjs/context/PaymentMethodContext.js +1 -1
- package/lib/cjs/index.d.ts +4 -16
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/reducers/AvailabilityReducer.d.ts +13 -23
- 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/getSdk.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/auth/CommerceLayer.d.ts +2 -2
- 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 +34 -9
- 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/CartLink.js +1 -1
- package/lib/esm/components/orders/CheckoutLink.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.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.d.ts +18 -0
- package/lib/esm/components/parcels/ParcelLineItemsCount.js +1 -0
- package/lib/esm/components/parcels/ParcelsCount.js +1 -1
- package/lib/esm/components/payment_gateways/AdyenGateway.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/CommerceLayerContext.d.ts +2 -2
- package/lib/esm/context/CommerceLayerContext.js +1 -1
- 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 -3
- package/lib/esm/context/OrderContext.js +1 -1
- package/lib/esm/context/PaymentMethodContext.d.ts +2 -11
- package/lib/esm/context/PaymentMethodContext.js +1 -1
- package/lib/esm/index.d.ts +4 -16
- package/lib/esm/index.js +1 -1
- package/lib/esm/reducers/AvailabilityReducer.d.ts +13 -23
- 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/getSdk.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 +9 -8
- 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 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import has from"lodash/has";import isEmpty from"lodash/isEmpty";import getCurrentItemKey from"../../utils/getCurrentItemKey";import ItemContext from"../../context/ItemContext";import SkuListsContext from"../../context/SkuListsContext";import SkuChildrenContext from"../../context/SkuChildrenContext";export function QuantitySelector(props){const{skuCode,skuListId,children,min=1,max,...p}=props,{item,setQuantity,items,quantity,prices,skuCode:itemSkuCode}=useContext(ItemContext),{sku}=useContext(SkuChildrenContext),{skuLists,listIds}=useContext(SkuListsContext),defaultVal=p?.value||min,[value,setValue]=useState(defaultVal),[disabled,setDisabled]=useState(!!p.disabled),sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:sku?.code||skuCode||getCurrentItemKey(item)||itemSkuCode,inventory=isEmpty(item)?50:item[sCode]?.inventory?.quantity,maxInv=max||inventory;useEffect(()=>{if(setValue(defaultVal),(!prices[sCode]||!sCode)&&setDisabled(!0),skuListId&&setDisabled(!1),sCode&&!quantity[sCode]){const qty=Number(defaultVal);setQuantity&&setQuantity({...quantity,[`${sCode}`]:qty}),!isEmpty(prices)&&has(prices,sCode)&&setDisabled(!1)}return()=>{setValue(defaultVal)}},[item,listIds,prices,quantity]);const handleChange=e=>{const qty=Number(e.target.value),valid=Number(qty)>=Number(min)&&Number(qty)<=Number(maxInv);setValue(qty),!isEmpty(skuLists)&&skuListId&&valid?setQuantity&&setQuantity({...quantity,[`${skuListId}`]:Number(qty)}):sCode&&valid&&setQuantity&&setQuantity({...quantity,[`${sCode}`]:Number(qty)})},handleBlur=e=>{const qty=e.target.value;if(!(Number(qty)>=Number(min)&&Number(qty)<=Number(maxInv))){const resetVal=Number(qty)<Number(min)?min:maxInv;resetVal&&setValue(resetVal),!isEmpty(skuLists)&&skuListId?setQuantity&&setQuantity({...quantity,[`${skuListId}`]:Number(resetVal)}):setQuantity&&setQuantity({...quantity,[`${sCode}`]:Number(resetVal)})}},parentProps={min,max:maxInv,disabled,handleChange,handleBlur,value,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("input",{type:"number",max:maxInv,min,value:value||"",disabled,onChange:handleChange,onBlur:handleBlur,...p})}export default QuantitySelector;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
declare type Props = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
id: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function SkuOption(props: Props): JSX.Element;
|
|
7
|
-
export declare namespace SkuOption {
|
|
8
|
-
var propTypes: {
|
|
9
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
10
|
-
id: import("prop-types").Validator<string>;
|
|
11
|
-
};
|
|
12
|
-
var displayName: string;
|
|
13
|
-
}
|
|
14
|
-
export default SkuOption;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext}from"react";import SkuOptionChildrenContext from"../../context/SkuOptionChildrenContext";import SkuOptionsContext from"../../context/SkuOptionsContext";import components from"../../config/components";const propTypes=components.SkuOption.propTypes,displayName=components.SkuOption.displayName;export function SkuOption(props){const{id}=props,{skuOptions,skuCode}=useContext(SkuOptionsContext),items=skuOptions&&skuOptions.filter(l=>l.id===id).map((skuOption,k)=>_jsx(SkuOptionChildrenContext.Provider,{value:{skuOption,skuCode},children:props.children},k));return _jsx(Fragment,{children:items})}SkuOption.propTypes=propTypes,SkuOption.displayName=displayName;export default SkuOption;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { BaseInputComponentProps } from '../../typings/index';
|
|
3
|
-
declare type Props = BaseInputComponentProps & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
|
|
4
|
-
export declare function SkuOptionInput(props: Props): JSX.Element;
|
|
5
|
-
export declare namespace SkuOptionInput {
|
|
6
|
-
var propTypes: {
|
|
7
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
8
|
-
name: import("prop-types").Validator<string>;
|
|
9
|
-
type: import("prop-types").Validator<NonNullable<import("../../typings/index").BaseInputType>>;
|
|
10
|
-
onChange: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
11
|
-
placeholder: import("prop-types").Requireable<string>;
|
|
12
|
-
};
|
|
13
|
-
var displayName: string;
|
|
14
|
-
}
|
|
15
|
-
export default SkuOptionInput;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import BaseInput from"../utils/BaseInput";import ItemContext from"../../context/ItemContext";import SkuOptionChildrenContext from"../../context/SkuOptionChildrenContext";import has from"lodash/has";import components from"../../config/components";const propTypes=components.SkuOptionInput.propTypes,displayName=components.SkuOptionInput.displayName;export function SkuOptionInput(props){const{name}=props,{option,setOption}=useContext(ItemContext),{skuOption,skuCode}=useContext(SkuOptionChildrenContext);return _jsx(BaseInput,{onChange:event=>{const val=event.target.value,options=has(option,`${skuCode}.${skuOption?.id}`)?option[skuCode]?.[`${skuOption?.id}`]?.options:{},o={[skuCode]:{...option[skuCode],[`${skuOption?.id}`]:{skuOptionId:skuOption?.id,options:{...options,[name]:val}}}};setOption&&setOption(o)},...props})}SkuOptionInput.propTypes=propTypes,SkuOptionInput.displayName=displayName;export default SkuOptionInput;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
declare type Props = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
skuCode?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function SkuOptionsContainer(props: Props): JSX.Element;
|
|
7
|
-
export declare namespace SkuOptionsContainer {
|
|
8
|
-
var propTypes: {
|
|
9
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
10
|
-
skuCode: import("prop-types").Requireable<string>;
|
|
11
|
-
};
|
|
12
|
-
var displayName: string;
|
|
13
|
-
}
|
|
14
|
-
export default SkuOptionsContainer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useContext,useEffect}from"react";import SkuOptionsContext from"../../context/SkuOptionsContext";import skuOptionsReducer,{skuOptionsInitialState}from"../../reducers/SkuOptionsReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import{isEmpty}from"lodash";import getCurrentItemKey from"../../utils/getCurrentItemKey";import ItemContext from"../../context/ItemContext";import{getSkuOptions}from"../../reducers/SkuOptionsReducer";import components from"../../config/components";const propTypes=components.SkuOptionsContainer.propTypes,displayName=components.SkuOptionsContainer.displayName;export function SkuOptionsContainer(props){const{skuCode,children}=props,[state,dispatch]=useReducer(skuOptionsReducer,skuOptionsInitialState),config=useContext(CommerceLayerContext),{item,items}=useContext(ItemContext),sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:skuCode||getCurrentItemKey(item),skuOptionsValue={...state,skuCode:sCode};return useEffect(()=>(sCode&&item[sCode]?.sku_options&&getSkuOptions({skuOptions:item[sCode]?.sku_options,dispatch}),()=>{isEmpty(sCode)&&dispatch({type:"setSkuOptions",payload:{skuOptions:[]}})}),[config,sCode]),_jsx(SkuOptionsContext.Provider,{value:skuOptionsValue,children})}SkuOptionsContainer.propTypes=propTypes,SkuOptionsContainer.displayName=displayName;export default SkuOptionsContainer;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { VariantHandleCallback } from '../utils/VariantTemplate';
|
|
3
|
-
import { BaseSelectorType } from '../../typings/index';
|
|
4
|
-
import { ChildrenFunction } from '../../typings/index';
|
|
5
|
-
import { VariantsObject, SetSkuCode } from '../../reducers/VariantReducer';
|
|
6
|
-
export interface VariantOption {
|
|
7
|
-
label: string;
|
|
8
|
-
code: string;
|
|
9
|
-
lineItem?: {
|
|
10
|
-
name: string;
|
|
11
|
-
imageUrl?: string | null;
|
|
12
|
-
} | null;
|
|
13
|
-
}
|
|
14
|
-
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
15
|
-
variants: VariantsObject;
|
|
16
|
-
handleSelect: SetSkuCode;
|
|
17
|
-
loading: boolean;
|
|
18
|
-
}
|
|
19
|
-
declare type Props = {
|
|
20
|
-
children?: ChildrenFunction<ChildrenProps>;
|
|
21
|
-
options: VariantOption[];
|
|
22
|
-
type?: BaseSelectorType;
|
|
23
|
-
loader?: ReactNode;
|
|
24
|
-
placeholder?: string;
|
|
25
|
-
skuCode?: string;
|
|
26
|
-
handleCallback?: VariantHandleCallback;
|
|
27
|
-
} & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['select'];
|
|
28
|
-
export declare function VariantSelector(props: Props): JSX.Element;
|
|
29
|
-
export default VariantSelector;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Fragment as _Fragment,jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect}from"react";import VariantTemplate from"../utils/VariantTemplate";import Parent from"../utils/Parent";import VariantsContext from"../../context/VariantsContext";export function VariantSelector(props){const{children,type="select",placeholder,skuCode,name,options,...prs}=props,{setSkuCode,skuCode:variantSkuCode,loading,variants,setSkuCodes}=useContext(VariantsContext);useEffect(()=>(setSkuCodes&&setSkuCodes(options),()=>{setSkuCodes&&setSkuCodes([])}),[options]);const sCode=variantSkuCode||skuCode||"",DefaultTemplate=()=>loading?_jsx(_Fragment,{children:props.loader||"Loading..."}):_jsx(VariantTemplate,{variants,type,placeholder,skuCode:sCode,options,handleChange:setSkuCode,name,...prs}),parentProps={variants,loading:!!loading,handleSelect:setSkuCode,skuCode:sCode,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx(DefaultTemplate,{})}export default VariantSelector;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
declare type Props = {
|
|
3
|
-
children: ReactNode;
|
|
4
|
-
filters?: Record<string, any>;
|
|
5
|
-
skuCode?: string;
|
|
6
|
-
};
|
|
7
|
-
export declare function VariantsContainer(props: Props): JSX.Element;
|
|
8
|
-
export declare namespace VariantsContainer {
|
|
9
|
-
var propTypes: {
|
|
10
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
11
|
-
skuCode: import("prop-types").Requireable<string>;
|
|
12
|
-
filters: import("prop-types").Requireable<object>;
|
|
13
|
-
};
|
|
14
|
-
var defaultProps: {
|
|
15
|
-
skuCode: string;
|
|
16
|
-
filters: {};
|
|
17
|
-
};
|
|
18
|
-
var displayName: string;
|
|
19
|
-
}
|
|
20
|
-
export default VariantsContainer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext}from"react";import variantReducer,{variantInitialState,unsetVariantState,setSkuCode,getVariants}from"../../reducers/VariantReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import VariantsContext from"../../context/VariantsContext";import{setVariantSkuCodes}from"../../reducers/VariantReducer";import isEmpty from"lodash/isEmpty";import isEqual from"lodash/isEqual";import getCurrentItemKey from"../../utils/getCurrentItemKey";import ItemContext from"../../context/ItemContext";import components from"../../config/components";const propTypes=components.VariantsContainer.propTypes,defaultProps=components.VariantsContainer.defaultProps,displayName=components.VariantsContainer.displayName;export function VariantsContainer(props){const{children,skuCode="",filters={}}=props,config=useContext(CommerceLayerContext),{setItem,setItems,items,item:currentItem,setCustomLineItems,skuCode:itemSkuCode,setSkuCode:setItemSkuCode}=useContext(ItemContext),[state,dispatch]=useReducer(variantReducer,variantInitialState),sCode=getCurrentItemKey(currentItem)||skuCode||state.skuCode||itemSkuCode||"";useEffect(()=>{if(!isEmpty(items)&&!isEmpty(state.variants)&&!isEqual(items,state.variants)){const mergeItems={...items,...state.variants};setItems&&setItems(mergeItems)}return state.skuCodes.length>=1&&config.accessToken&&(dispatch({type:"setLoading",payload:{loading:!0}}),getVariants({config,state,dispatch,setItem,skuCode:sCode,filters})),()=>unsetVariantState(dispatch)},[config.accessToken]);const variantValue={...state,skuCode:sCode,setSkuCode:(code,id,lineItem={})=>{isEmpty(lineItem)||setCustomLineItems&&setCustomLineItems({[code]:lineItem}),setSkuCode({code,id,config,setItem,dispatch,setItemSkuCode})},setSkuCodes:skuCodes=>setVariantSkuCodes({skuCodes,dispatch,setCustomLineItems})};return _jsx(VariantsContext.Provider,{value:variantValue,children})}VariantsContainer.propTypes=propTypes,VariantsContainer.defaultProps=defaultProps,VariantsContainer.displayName=displayName;export default VariantsContainer;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent, ReactNode } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { BaseSelectorType } from '../../typings/index';
|
|
4
|
-
import { VariantsObject, SetSkuCode } from '../../reducers/VariantReducer';
|
|
5
|
-
import { VariantOption } from '../skus/VariantSelector';
|
|
6
|
-
export declare const propTypes: {
|
|
7
|
-
variants: PropTypes.Validator<any>;
|
|
8
|
-
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
9
|
-
options: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
|
|
10
|
-
label: PropTypes.Validator<string>;
|
|
11
|
-
code: PropTypes.Validator<string>;
|
|
12
|
-
lineItem: PropTypes.Requireable<PropTypes.InferProps<{
|
|
13
|
-
name: PropTypes.Validator<string>;
|
|
14
|
-
imageUrl: PropTypes.Requireable<string>;
|
|
15
|
-
}>>;
|
|
16
|
-
}>>[]>;
|
|
17
|
-
name: PropTypes.Requireable<string>;
|
|
18
|
-
children: PropTypes.Requireable<(...args: any[]) => any>;
|
|
19
|
-
type: PropTypes.Requireable<BaseSelectorType>;
|
|
20
|
-
loader: PropTypes.Requireable<PropTypes.ReactElementLike>;
|
|
21
|
-
placeholder: PropTypes.Requireable<string>;
|
|
22
|
-
skuCode: PropTypes.Requireable<string>;
|
|
23
|
-
};
|
|
24
|
-
export declare type VariantHandleCallback = (variant: VariantOption) => void;
|
|
25
|
-
export declare type VariantTemplateProps = {
|
|
26
|
-
variants: VariantsObject | Record<string, any>;
|
|
27
|
-
handleChange?: SetSkuCode;
|
|
28
|
-
options: VariantOption[];
|
|
29
|
-
type?: BaseSelectorType;
|
|
30
|
-
loader?: ReactNode;
|
|
31
|
-
placeholder?: string;
|
|
32
|
-
skuCode?: string;
|
|
33
|
-
handleCallback?: VariantHandleCallback;
|
|
34
|
-
} & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['select'];
|
|
35
|
-
declare const VariantTemplate: FunctionComponent<VariantTemplateProps>;
|
|
36
|
-
export default VariantTemplate;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{Fragment}from"react";import PropTypes from"prop-types";export const propTypes={variants:PropTypes.any.isRequired,onChange:PropTypes.func,options:PropTypes.arrayOf(PropTypes.shape({label:PropTypes.string.isRequired,code:PropTypes.string.isRequired,lineItem:PropTypes.shape({name:PropTypes.string.isRequired,imageUrl:PropTypes.string})}).isRequired).isRequired,name:PropTypes.string,children:PropTypes.func,type:PropTypes.oneOf(["select","radio"]),loader:PropTypes.element,placeholder:PropTypes.string,skuCode:PropTypes.string};const VariantTemplate=props=>{const{id,variants,type,placeholder,options,skuCode,handleChange,handleCallback,...prs}=props,vars=Object.keys(variants).map((v,k)=>{const checked=skuCode===v,label=options.length>0?options[k]?.label:variants[v].name;return type==="select"?_jsx("option",{"data-sku-id":variants[v].id,"data-label":label,value:variants[v].code,children:label},variants[v].id):_jsxs(Fragment,{children:[_jsx("input",{id:id&&`${id}-${k}`,defaultChecked:checked,type:"radio",value:variants[v].code,onChange:e=>{const code=e.target.value;handleChange&&handleChange(code,variants[v].id),handleCallback&&handleCallback({code,label})},...prs}),label]},variants[v].id)});return type==="select"?_jsxs("select",{id,title:"Variant selector",onChange:e=>{const v=e.target.value,i=e.target.selectedIndex,id2=e.target[i]?.dataset?.skuId,label=e.target[i]?.dataset?.label;handleChange&&handleChange(v,id2),handleCallback&&handleCallback({code:v,label})},value:skuCode||"",...prs,children:[_jsx("option",{disabled:!!skuCode,children:placeholder}),vars]}):_jsx(_Fragment,{children:vars})};export default VariantTemplate;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { ItemState, Items, ItemQuantity, ItemOptions, ItemPrices, CustomLineItems } from '../reducers/ItemReducer';
|
|
3
|
-
export interface InitItemContext extends Partial<ItemState> {
|
|
4
|
-
item: Items;
|
|
5
|
-
items: Items;
|
|
6
|
-
quantity: ItemQuantity;
|
|
7
|
-
option: ItemOptions;
|
|
8
|
-
prices: ItemPrices;
|
|
9
|
-
lineItems: CustomLineItems;
|
|
10
|
-
}
|
|
11
|
-
export declare const initialItemContext: InitItemContext;
|
|
12
|
-
declare const ItemContext: import("react").Context<InitItemContext>;
|
|
13
|
-
export default ItemContext;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createContext}from"react";export const initialItemContext={item:{},items:{},quantity:{},option:{},prices:{},lineItems:{}};const ItemContext=createContext(initialItemContext);export default ItemContext;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { SkuOption } from '@commercelayer/sdk';
|
|
3
|
-
export interface SkuOptionChildrenInitalState {
|
|
4
|
-
skuOption?: SkuOption | null;
|
|
5
|
-
skuCode: string;
|
|
6
|
-
}
|
|
7
|
-
declare const SkuOptionChildrenContext: import("react").Context<SkuOptionChildrenInitalState>;
|
|
8
|
-
export default SkuOptionChildrenContext;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createContext}from"react";const initial={skuCode:""},SkuOptionChildrenContext=createContext(initial);export default SkuOptionChildrenContext;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createContext}from"react";import{skuOptionsInitialState}from"../reducers/SkuOptionsReducer";const SkuOptionsContext=createContext(skuOptionsInitialState);export default SkuOptionsContext;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createContext}from"react";import{variantInitialState}from"../reducers/VariantReducer";const VariantsContext=createContext(variantInitialState);export default VariantsContext;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { BaseUnsetState } from '../typings/index';
|
|
2
|
-
import { Price } from '@commercelayer/sdk';
|
|
3
|
-
import { Dispatch } from 'react';
|
|
4
|
-
import { SkuInventory } from './AvailabilityReducer';
|
|
5
|
-
export interface Items {
|
|
6
|
-
[skuCode: string]: SkuInventory;
|
|
7
|
-
}
|
|
8
|
-
export interface ItemPrices {
|
|
9
|
-
[skuCode: string]: Price;
|
|
10
|
-
}
|
|
11
|
-
export interface ItemQuantity {
|
|
12
|
-
[skuCode: string]: number;
|
|
13
|
-
}
|
|
14
|
-
export interface ItemOption {
|
|
15
|
-
[key: string]: {
|
|
16
|
-
skuOptionId: string;
|
|
17
|
-
options: {
|
|
18
|
-
[key: string]: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export interface ItemOptions {
|
|
23
|
-
[skuCode: string]: ItemOption;
|
|
24
|
-
}
|
|
25
|
-
export declare type CustomLineItem = {
|
|
26
|
-
name?: string;
|
|
27
|
-
imageUrl?: string | null;
|
|
28
|
-
};
|
|
29
|
-
export interface CustomLineItems {
|
|
30
|
-
[skuCode: string]: CustomLineItem;
|
|
31
|
-
}
|
|
32
|
-
declare type ItemParams = {
|
|
33
|
-
type: ItemActionType;
|
|
34
|
-
key: 'items' | 'item' | 'quantity' | 'option' | 'prices' | 'lineItem' | 'lineItems' | 'skuCode';
|
|
35
|
-
};
|
|
36
|
-
declare type DataType = Items | ItemQuantity | ItemOptions | ItemPrices | CustomLineItems | CustomLineItem | string;
|
|
37
|
-
export interface SetItemState {
|
|
38
|
-
(data: DataType, params: ItemParams, dispatch: Dispatch<ItemAction>): void;
|
|
39
|
-
}
|
|
40
|
-
export declare const setItemState: SetItemState;
|
|
41
|
-
export declare const unsetItemState: BaseUnsetState<ItemAction>;
|
|
42
|
-
export declare type SetCustomLineItems = (lineItems: CustomLineItems) => void;
|
|
43
|
-
export declare type SetCustomLineItem = (lineItem: CustomLineItem) => void;
|
|
44
|
-
export interface ItemState {
|
|
45
|
-
skuCode?: string;
|
|
46
|
-
items?: Items;
|
|
47
|
-
item?: Items;
|
|
48
|
-
lineItems?: CustomLineItems;
|
|
49
|
-
lineItem?: CustomLineItem;
|
|
50
|
-
quantity?: ItemQuantity;
|
|
51
|
-
option?: ItemOptions;
|
|
52
|
-
prices?: ItemPrices;
|
|
53
|
-
setItems?: (items: Items) => void;
|
|
54
|
-
setItem?: (item: Items) => void;
|
|
55
|
-
setQuantity?: (quantity: ItemQuantity) => void;
|
|
56
|
-
setOption?: (option: ItemOptions) => void;
|
|
57
|
-
setPrices?: (prices: ItemPrices) => void;
|
|
58
|
-
setSkuCode?: (skuCode: string) => void;
|
|
59
|
-
setCustomLineItems: SetCustomLineItems;
|
|
60
|
-
setCustomLineItem?: SetCustomLineItem;
|
|
61
|
-
}
|
|
62
|
-
declare type ItemActionType = 'setItem' | 'setItems' | 'setQuantity' | 'setOption' | 'setPrices' | 'setCustomLineItems' | 'setCustomLineItem' | 'setSkuCode';
|
|
63
|
-
export interface ItemAction {
|
|
64
|
-
type: ItemActionType;
|
|
65
|
-
payload: Partial<ItemState>;
|
|
66
|
-
}
|
|
67
|
-
export declare const itemInitialState: Partial<ItemState>;
|
|
68
|
-
declare const itemReducer: (state: Partial<ItemState>, reducer: ItemAction) => Partial<ItemState>;
|
|
69
|
-
export default itemReducer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";export const setItemState=(data,params,dispatch)=>{dispatch({type:params.type,payload:{[`${params.key}`]:data}})},unsetItemState=dispatch=>{dispatch({type:"setItem",payload:{item:{}}}),dispatch({type:"setItems",payload:{items:{}}}),dispatch({type:"setQuantity",payload:{quantity:{}}}),dispatch({type:"setOption",payload:{option:{}}}),dispatch({type:"setCustomLineItems",payload:{lineItems:{}}}),dispatch({type:"setCustomLineItem",payload:{lineItem:{}}})};const actionType=["setItem","setItems","setQuantity","setOption","setPrices","setCustomLineItems","setCustomLineItem","setSkuCode"];export const itemInitialState={items:{},item:{},quantity:{},option:{},prices:{},lineItems:{},lineItem:{},skuCode:""};const itemReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default itemReducer;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Dispatch } from 'react';
|
|
2
|
-
import { SkuOption } from '@commercelayer/sdk';
|
|
3
|
-
import { BaseUnsetState } from '../typings/index';
|
|
4
|
-
import { BaseError } from '../typings/errors';
|
|
5
|
-
export interface SkuOptionsState {
|
|
6
|
-
skuCode?: string;
|
|
7
|
-
skuOptions?: SkuOption[];
|
|
8
|
-
errors?: BaseError[];
|
|
9
|
-
}
|
|
10
|
-
interface GetSkuOptionsParams {
|
|
11
|
-
dispatch: Dispatch<SkuOptionsAction>;
|
|
12
|
-
skuOptions?: SkuOption[];
|
|
13
|
-
}
|
|
14
|
-
export interface GetSkuOptions {
|
|
15
|
-
(params: GetSkuOptionsParams): void;
|
|
16
|
-
}
|
|
17
|
-
export declare const getSkuOptions: GetSkuOptions;
|
|
18
|
-
export declare const unsetSkuOptionsState: BaseUnsetState<SkuOptionsAction>;
|
|
19
|
-
export declare type SkuOptionsActionType = 'setSkuOptions' | 'setErrors';
|
|
20
|
-
export interface SkuOptionsAction {
|
|
21
|
-
type: SkuOptionsActionType;
|
|
22
|
-
payload: SkuOptionsState;
|
|
23
|
-
}
|
|
24
|
-
export declare const skuOptionsInitialState: SkuOptionsState;
|
|
25
|
-
declare const skuOptionsReducer: (state: SkuOptionsState, reducer: SkuOptionsAction) => SkuOptionsState;
|
|
26
|
-
export default skuOptionsReducer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";export const getSkuOptions=async params=>{const{skuOptions,dispatch}=params;dispatch({type:"setSkuOptions",payload:{skuOptions}})},unsetSkuOptionsState=dispatch=>{dispatch({type:"setSkuOptions",payload:{skuOptions:[]}}),dispatch({type:"setErrors",payload:{errors:[]}})};const actionType=["setSkuOptions","setErrors"];export const skuOptionsInitialState={skuCode:"",skuOptions:[]};const skuOptionsReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default skuOptionsReducer;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Sku } from '@commercelayer/sdk';
|
|
2
|
-
import { VariantOption } from '../components/skus/VariantSelector';
|
|
3
|
-
import { Dispatch } from 'react';
|
|
4
|
-
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
5
|
-
import { Items, CustomLineItem, SetCustomLineItems } from './ItemReducer';
|
|
6
|
-
import { BaseError } from '../typings/errors';
|
|
7
|
-
declare type SetSkuCodeVariantParams = {
|
|
8
|
-
code: string;
|
|
9
|
-
id: string;
|
|
10
|
-
config: CommerceLayerConfig;
|
|
11
|
-
dispatch: Dispatch<VariantAction>;
|
|
12
|
-
setItem: ((item: Items) => void) | undefined;
|
|
13
|
-
setItemSkuCode?: ((skuCode: string) => void) | undefined;
|
|
14
|
-
};
|
|
15
|
-
export interface SetSkuCodeVariant {
|
|
16
|
-
(params: SetSkuCodeVariantParams): void;
|
|
17
|
-
}
|
|
18
|
-
declare type SetVariantSkuCodesParams = {
|
|
19
|
-
skuCodes: VariantOption[];
|
|
20
|
-
dispatch: Dispatch<VariantAction>;
|
|
21
|
-
setCustomLineItems?: SetCustomLineItems;
|
|
22
|
-
};
|
|
23
|
-
export interface SetVariantSkuCodes {
|
|
24
|
-
(params: SetVariantSkuCodesParams): void;
|
|
25
|
-
}
|
|
26
|
-
export interface VariantsObject {
|
|
27
|
-
[key: string]: Sku;
|
|
28
|
-
}
|
|
29
|
-
export declare type SetSkuCode = (code: string, id: string, lineItem?: CustomLineItem) => void;
|
|
30
|
-
export interface VariantPayload {
|
|
31
|
-
loading?: boolean;
|
|
32
|
-
variants?: VariantsObject | Record<string, any>;
|
|
33
|
-
skuCodes?: string[];
|
|
34
|
-
skuCode?: string;
|
|
35
|
-
errors?: BaseError[];
|
|
36
|
-
currentSkuId?: string;
|
|
37
|
-
currentSkuInventory?: any;
|
|
38
|
-
currentQuantity?: number;
|
|
39
|
-
currentPrices?: Sku[];
|
|
40
|
-
setSkuCode?: SetSkuCode;
|
|
41
|
-
setSkuCodes?: (skuCodes: VariantOption[]) => void;
|
|
42
|
-
}
|
|
43
|
-
export interface VariantState extends VariantPayload {
|
|
44
|
-
skuCodes: string[];
|
|
45
|
-
variants: VariantsObject | Record<string, any>;
|
|
46
|
-
}
|
|
47
|
-
export interface VariantAction {
|
|
48
|
-
type: VariantActionType;
|
|
49
|
-
payload: VariantPayload;
|
|
50
|
-
}
|
|
51
|
-
export declare const setVariantSkuCodes: SetVariantSkuCodes;
|
|
52
|
-
export interface UnsetVariantState {
|
|
53
|
-
(dispatch: Dispatch<VariantAction>): void;
|
|
54
|
-
}
|
|
55
|
-
export declare const setSkuCode: SetSkuCodeVariant;
|
|
56
|
-
declare type GetVariantsParams = {
|
|
57
|
-
config: CommerceLayerConfig;
|
|
58
|
-
state: VariantState;
|
|
59
|
-
skuCode: string;
|
|
60
|
-
dispatch: Dispatch<VariantAction>;
|
|
61
|
-
filters: Record<string, any>;
|
|
62
|
-
setItem: ((item: Items) => void) | undefined;
|
|
63
|
-
};
|
|
64
|
-
export interface GetVariants {
|
|
65
|
-
(params: GetVariantsParams): void;
|
|
66
|
-
}
|
|
67
|
-
export declare const getVariants: GetVariants;
|
|
68
|
-
export declare const unsetVariantState: UnsetVariantState;
|
|
69
|
-
export declare const variantInitialState: VariantState;
|
|
70
|
-
export declare type VariantActionType = 'setLoading' | 'setVariants' | 'setSkuCodes' | 'setSkuCode' | 'setCurrentSkuId' | 'setCurrentSkuInventory' | 'setCurrentPrices' | 'setErrors';
|
|
71
|
-
declare const variantReducer: (state: VariantState, reducer: VariantAction) => VariantState;
|
|
72
|
-
export default variantReducer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import getSkus from"../utils/getSkus";import{isEmpty,has}from"lodash";import getSdk from"../utils/getSdk";export const setVariantSkuCodes=({skuCodes,dispatch,setCustomLineItems})=>{const lineItems={},sCodes=skuCodes.map(s=>(has(s,"lineItem")&&(lineItems[s.code]=s.lineItem),s.code));isEmpty(lineItems)||setCustomLineItems&&setCustomLineItems(lineItems),dispatch({type:"setSkuCodes",payload:{skuCodes:sCodes}})},setSkuCode=params=>{const{id,code,config,setItem,dispatch,setItemSkuCode}=params;id&&getSdk(config).skus.retrieve(id,{include:["sku_options"]}).then(sku=>{setItem&&setItem({[`${code}`]:sku}),setItemSkuCode&&setItemSkuCode(code)}).catch(errors=>{dispatch({type:"setErrors",payload:{errors}})})},getVariants=params=>{const{config,state,skuCode,dispatch,setItem,filters}=params;getSdk(config).skus.list({filters:{code_in:state.skuCodes.join(","),...filters}}).then(skus=>{const skusObj=getSkus(skus,state.skuCodes);skuCode&&setSkuCode({code:skusObj[skuCode].code,id:skusObj[skuCode].id,config,dispatch,setItem}),dispatch({type:"setVariants",payload:{variants:skusObj}}),dispatch({type:"setLoading",payload:{loading:!1}})}).catch(errors=>{dispatch({type:"setErrors",payload:{errors}})})},unsetVariantState=dispatch=>{dispatch({type:"setSkuCode",payload:{skuCode:""}}),dispatch({type:"setVariants",payload:{variants:{}}}),dispatch({type:"setLoading",payload:{loading:!1}})},variantInitialState={loading:!1,variants:{},skuCodes:[],skuCode:"",errors:[],currentSkuId:"",currentSkuInventory:{available:!1,quantity:0,levels:[]},currentQuantity:1,currentPrices:[]};const actionType=["setLoading","setVariants","setSkuCodes","setSkuCode","setCurrentSkuId","setCurrentSkuInventory","setCurrentPrices","setErrors"],variantReducer=(state,reducer)=>baseReducer(state,reducer,actionType);export default variantReducer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import first from"lodash/first";import keys from"lodash/keys";const getCurrentItemKey=item=>first(keys(item))||"";export default getCurrentItemKey;
|