@commercelayer/react-components 4.0.0-alpha.11 → 4.0.0-alpha.12
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/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/shipments/ShipmentsCount.js +1 -1
- package/lib/cjs/components/skus/VariantSelector.js +1 -1
- package/lib/cjs/components/skus/VariantsContainer.d.ts +4 -16
- package/lib/cjs/components/skus/VariantsContainer.js +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/VariantTemplate.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 +1 -1
- package/lib/cjs/index.js +1 -1
- 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/VariantReducer.d.ts +7 -15
- package/lib/cjs/reducers/VariantReducer.js +1 -1
- 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/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/shipments/ShipmentsCount.js +1 -1
- package/lib/esm/components/skus/VariantSelector.js +1 -1
- package/lib/esm/components/skus/VariantsContainer.d.ts +4 -16
- package/lib/esm/components/skus/VariantsContainer.js +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/VariantTemplate.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 +1 -1
- package/lib/esm/index.js +1 -1
- 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/VariantReducer.d.ts +7 -15
- package/lib/esm/reducers/VariantReducer.js +1 -1
- 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 +1 -1
- package/lib/cjs/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
- package/lib/cjs/components/payment_methods/PaymentMethodAmount.js +0 -1
- package/lib/esm/components/payment_methods/PaymentMethodAmount.d.ts +0 -18
- package/lib/esm/components/payment_methods/PaymentMethodAmount.js +0 -1
|
@@ -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;
|
|
@@ -4,25 +4,21 @@ import { Dispatch } from 'react';
|
|
|
4
4
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
5
5
|
import { Items, CustomLineItem, SetCustomLineItems } from './ItemReducer';
|
|
6
6
|
import { BaseError } from '../typings/errors';
|
|
7
|
-
|
|
7
|
+
interface SetSkuCodeVariantParams {
|
|
8
8
|
code: string;
|
|
9
9
|
id: string;
|
|
10
10
|
config: CommerceLayerConfig;
|
|
11
11
|
dispatch: Dispatch<VariantAction>;
|
|
12
12
|
setItem: ((item: Items) => void) | undefined;
|
|
13
13
|
setItemSkuCode?: ((skuCode: string) => void) | undefined;
|
|
14
|
-
};
|
|
15
|
-
export interface SetSkuCodeVariant {
|
|
16
|
-
(params: SetSkuCodeVariantParams): void;
|
|
17
14
|
}
|
|
18
|
-
declare type
|
|
15
|
+
export declare type SetSkuCodeVariant = (params: SetSkuCodeVariantParams) => void;
|
|
16
|
+
interface SetVariantSkuCodesParams {
|
|
19
17
|
skuCodes: VariantOption[];
|
|
20
18
|
dispatch: Dispatch<VariantAction>;
|
|
21
19
|
setCustomLineItems?: SetCustomLineItems;
|
|
22
|
-
};
|
|
23
|
-
export interface SetVariantSkuCodes {
|
|
24
|
-
(params: SetVariantSkuCodesParams): void;
|
|
25
20
|
}
|
|
21
|
+
export declare type SetVariantSkuCodes = (params: SetVariantSkuCodesParams) => void;
|
|
26
22
|
export interface VariantsObject {
|
|
27
23
|
[key: string]: Sku;
|
|
28
24
|
}
|
|
@@ -49,21 +45,17 @@ export interface VariantAction {
|
|
|
49
45
|
payload: VariantPayload;
|
|
50
46
|
}
|
|
51
47
|
export declare const setVariantSkuCodes: SetVariantSkuCodes;
|
|
52
|
-
export
|
|
53
|
-
(dispatch: Dispatch<VariantAction>): void;
|
|
54
|
-
}
|
|
48
|
+
export declare type UnsetVariantState = (dispatch: Dispatch<VariantAction>) => void;
|
|
55
49
|
export declare const setSkuCode: SetSkuCodeVariant;
|
|
56
|
-
|
|
50
|
+
interface GetVariantsParams {
|
|
57
51
|
config: CommerceLayerConfig;
|
|
58
52
|
state: VariantState;
|
|
59
53
|
skuCode: string;
|
|
60
54
|
dispatch: Dispatch<VariantAction>;
|
|
61
55
|
filters: Record<string, any>;
|
|
62
56
|
setItem: ((item: Items) => void) | undefined;
|
|
63
|
-
};
|
|
64
|
-
export interface GetVariants {
|
|
65
|
-
(params: GetVariantsParams): void;
|
|
66
57
|
}
|
|
58
|
+
export declare type GetVariants = (params: GetVariantsParams) => void;
|
|
67
59
|
export declare const getVariants: GetVariants;
|
|
68
60
|
export declare const unsetVariantState: UnsetVariantState;
|
|
69
61
|
export declare const variantInitialState: VariantState;
|
|
@@ -1 +1 @@
|
|
|
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))
|
|
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;
|
|
@@ -109,13 +109,13 @@ export declare const baseOrderComponentPricePropTypes: {
|
|
|
109
109
|
export declare type BasePriceType = 'total' | 'option' | 'unit';
|
|
110
110
|
export declare type BaseSelectorType = 'select' | 'radio';
|
|
111
111
|
export declare type BaseAmountComponentChildren = Omit<BaseAmountComponent, 'children'>;
|
|
112
|
-
export
|
|
113
|
-
children?:
|
|
112
|
+
export interface BaseAmountComponent extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
113
|
+
children?: ChildrenFunction<BaseAmountComponentChildren>;
|
|
114
114
|
format?: BaseFormatPrice;
|
|
115
115
|
price?: string;
|
|
116
116
|
priceCents?: number;
|
|
117
117
|
labelFree?: string;
|
|
118
|
-
}
|
|
118
|
+
}
|
|
119
119
|
export declare type ChildrenFunction<P = Record<string, any>> = (props: P) => JSX.Element;
|
|
120
120
|
export declare type ExcludeTag<T extends keyof JSX.IntrinsicElements> = Exclude<keyof JSX.IntrinsicElements, T>;
|
|
121
121
|
export declare type ExtractTag<T extends keyof JSX.IntrinsicElements> = Extract<keyof JSX.IntrinsicElements, T>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
interface TReturn {
|
|
2
2
|
screenWidth: string | number;
|
|
3
3
|
screenHeight: string | number;
|
|
4
4
|
colorDepth: string | number;
|
|
@@ -6,4 +6,7 @@ export default function getBrowserInfo(): {
|
|
|
6
6
|
timeZoneOffset: number;
|
|
7
7
|
language: string;
|
|
8
8
|
javaEnabled: boolean;
|
|
9
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export default function getBrowserInfo(): TReturn;
|
|
11
|
+
export declare function cleanUrlBy(symbol?: string): string;
|
|
12
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function getBrowserInfo(){const screenWidth=window
|
|
1
|
+
export default function getBrowserInfo(){const screenWidth=window?.screen?window.screen.width:"",screenHeight=window?.screen?window.screen.height:"",colorDepth=window?.screen?window.screen.colorDepth:"",userAgent=window?.navigator?window.navigator.userAgent:"",javaEnabled=window?.navigator?navigator.javaEnabled():!1;let language="";window?.navigator&&(language=window.navigator.language);const timeZoneOffset=new Date().getTimezoneOffset();return{screenWidth,screenHeight,colorDepth,userAgent,timeZoneOffset,language,javaEnabled}}export function cleanUrlBy(symbol="&"){const currentLocation=window?.location.href,[splitLocation]=currentLocation.split(symbol);return splitLocation??currentLocation}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Context } from 'react';
|
|
2
|
+
interface TParams<C> {
|
|
3
|
+
/**
|
|
4
|
+
* Context to check
|
|
5
|
+
*/
|
|
6
|
+
context: Context<C>;
|
|
7
|
+
/**
|
|
8
|
+
* Name of the component has the context
|
|
9
|
+
*/
|
|
10
|
+
contextComponentName: string;
|
|
11
|
+
/**
|
|
12
|
+
* Name of the current component
|
|
13
|
+
*/
|
|
14
|
+
currentComponentName: string;
|
|
15
|
+
/**
|
|
16
|
+
* Key of the context to check
|
|
17
|
+
*/
|
|
18
|
+
key?: string;
|
|
19
|
+
}
|
|
20
|
+
export default function useCustomContext<T>({ context, key, currentComponentName, contextComponentName }: TParams<T>): T;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useContext}from"react";export default function useCustomContext({context,key,currentComponentName,contextComponentName}){const currentContext=useContext(context),isProduction=process.env.NODE_ENV==="production",msg=`Cannot use <${currentComponentName}/> outside of <${contextComponentName}/>`;if(key!=null&&key in currentContext||key==null&¤tContext!=null)return currentContext;if(isProduction)console.error(msg);else throw new Error(msg);return currentContext}
|