@commercelayer/react-components 4.0.0-alpha.5 → 4.0.0-alpha.6
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/SubmitButton.d.ts +6 -15
- package/lib/cjs/components/SubmitButton.js +1 -1
- package/lib/cjs/components/addresses/AddressInput.d.ts +0 -11
- package/lib/cjs/components/addresses/AddressInput.js +1 -1
- package/lib/cjs/components/addresses/SaveAddressesButton.d.ts +4 -3
- package/lib/cjs/components/addresses/SaveAddressesButton.js +1 -1
- package/lib/cjs/components/auth/CommerceLayer.d.ts +2 -9
- package/lib/cjs/components/auth/CommerceLayer.js +1 -1
- package/lib/cjs/components/customers/SaveCustomerButton.d.ts +6 -7
- package/lib/cjs/components/customers/SaveCustomerButton.js +1 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.d.ts +8 -16
- package/lib/cjs/components/gift_cards/GiftCardOrCouponCode.js +1 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponRemoveButton.d.ts +4 -12
- package/lib/cjs/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -1
- package/lib/cjs/components/gift_cards/GiftCardOrCouponSubmit.d.ts +6 -12
- package/lib/cjs/components/gift_cards/GiftCardOrCouponSubmit.js +1 -1
- package/lib/cjs/components/line_items/LineItemOption.d.ts +2 -2
- package/lib/cjs/components/line_items/LineItemQuantity.d.ts +4 -16
- package/lib/cjs/components/line_items/LineItemQuantity.js +1 -1
- package/lib/cjs/components/line_items/LineItemRemoveLink.d.ts +6 -16
- package/lib/cjs/components/line_items/LineItemRemoveLink.js +1 -1
- package/lib/cjs/components/line_items/LineItemsCount.d.ts +4 -14
- package/lib/cjs/components/line_items/LineItemsCount.js +1 -1
- package/lib/cjs/components/line_items/LineItemsEmpty.d.ts +6 -17
- package/lib/cjs/components/line_items/LineItemsEmpty.js +1 -1
- package/lib/cjs/components/orders/AddToCartButton.d.ts +4 -5
- package/lib/cjs/components/orders/AddToCartButton.js +1 -1
- package/lib/cjs/components/orders/CartLink.d.ts +6 -6
- package/lib/cjs/components/orders/CartLink.js +1 -1
- package/lib/cjs/components/orders/CheckoutLink.d.ts +4 -4
- package/lib/cjs/components/orders/CheckoutLink.js +1 -1
- package/lib/cjs/components/orders/ItemContainer.d.ts +2 -13
- package/lib/cjs/components/orders/ItemContainer.js +1 -1
- package/lib/cjs/components/orders/OrderList.d.ts +10 -11
- package/lib/cjs/components/orders/OrderList.js +1 -1
- package/lib/cjs/components/orders/OrderListEmpty.d.ts +14 -0
- package/lib/cjs/components/orders/OrderListEmpty.js +1 -0
- package/lib/cjs/components/orders/OrderListRow.d.ts +1 -1
- package/lib/cjs/components/orders/PlaceOrderButton.d.ts +4 -14
- package/lib/cjs/components/orders/PlaceOrderButton.js +1 -1
- package/lib/cjs/components/parcels/Parcel.d.ts +6 -0
- package/lib/cjs/components/parcels/Parcel.js +1 -0
- package/lib/cjs/components/payment_source/AdyenPayment.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.d.ts +4 -14
- package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandName.d.ts +4 -11
- package/lib/cjs/components/payment_source/PaymentSourceBrandName.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +6 -12
- package/lib/cjs/components/payment_source/PaymentSourceDetail.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceEditButton.d.ts +4 -10
- package/lib/cjs/components/payment_source/PaymentSourceEditButton.js +1 -1
- package/lib/cjs/components/prices/Price.d.ts +6 -18
- package/lib/cjs/components/prices/Price.js +1 -1
- package/lib/cjs/components/prices/PricesContainer.d.ts +4 -20
- package/lib/cjs/components/prices/PricesContainer.js +1 -1
- package/lib/cjs/components/shipments/Shipment.d.ts +2 -8
- package/lib/cjs/components/shipments/Shipment.js +1 -1
- package/lib/cjs/components/shipments/ShipmentField.d.ts +0 -7
- package/lib/cjs/components/shipments/ShipmentField.js +1 -1
- package/lib/cjs/components/shipments/ShipmentsContainer.d.ts +2 -8
- package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -1
- package/lib/cjs/components/shipping_methods/ShippingMethod.d.ts +2 -9
- package/lib/cjs/components/shipping_methods/ShippingMethod.js +1 -1
- package/lib/cjs/components/shipping_methods/ShippingMethodName.d.ts +0 -6
- package/lib/cjs/components/shipping_methods/ShippingMethodName.js +1 -1
- package/lib/cjs/components/skus/AvailabilityTemplate.d.ts +4 -13
- package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
- package/lib/cjs/components/skus/QuantitySelector.d.ts +4 -18
- package/lib/cjs/components/skus/QuantitySelector.js +1 -1
- package/lib/cjs/components/skus/VariantSelector.d.ts +4 -27
- package/lib/cjs/components/skus/VariantSelector.js +1 -1
- package/lib/cjs/components/utils/AddressCardsTemplate.d.ts +2 -2
- package/lib/cjs/components/utils/BaseInput.d.ts +1 -1
- package/lib/cjs/components/utils/ErrorBoundary.d.ts +14 -0
- package/lib/cjs/components/utils/ErrorBoundary.js +1 -0
- package/lib/cjs/components/utils/PaymentCardsTemplate.d.ts +2 -2
- package/lib/cjs/components/utils/PriceTemplate.d.ts +2 -2
- package/lib/cjs/components/utils/PriceTemplate.js +1 -1
- package/lib/cjs/context/BillingAddressFormContext.d.ts +2 -2
- package/lib/cjs/context/OrderListChildrenContext.d.ts +8 -0
- package/lib/cjs/context/ParcelChildrenContext.d.ts +7 -0
- package/lib/cjs/context/ParcelChildrenContext.js +1 -0
- package/lib/cjs/context/ShipmentChildrenContext.d.ts +6 -5
- package/lib/cjs/context/ShipmentChildrenContext.js +1 -1
- package/lib/cjs/index.d.ts +35 -34
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/reducers/CustomerReducer.d.ts +16 -18
- package/lib/cjs/reducers/CustomerReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.d.ts +14 -24
- package/lib/cjs/reducers/ShipmentReducer.d.ts +1 -3
- package/lib/cjs/typings/errors.d.ts +2 -2
- package/lib/cjs/typings/index.d.ts +8 -16
- package/lib/cjs/utils/getPrices.d.ts +4 -15
- package/lib/cjs/utils/getPrices.js +1 -1
- package/lib/cjs/utils/getSdk.d.ts +1 -1
- package/lib/cjs/utils/organization.d.ts +2 -2
- package/lib/esm/components/SubmitButton.d.ts +6 -15
- package/lib/esm/components/SubmitButton.js +1 -1
- package/lib/esm/components/addresses/AddressInput.d.ts +0 -11
- package/lib/esm/components/addresses/AddressInput.js +1 -1
- package/lib/esm/components/addresses/SaveAddressesButton.d.ts +4 -3
- package/lib/esm/components/addresses/SaveAddressesButton.js +1 -1
- package/lib/esm/components/auth/CommerceLayer.d.ts +2 -9
- package/lib/esm/components/auth/CommerceLayer.js +1 -1
- package/lib/esm/components/customers/SaveCustomerButton.d.ts +6 -7
- package/lib/esm/components/customers/SaveCustomerButton.js +1 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponCode.d.ts +8 -16
- package/lib/esm/components/gift_cards/GiftCardOrCouponCode.js +1 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponRemoveButton.d.ts +4 -12
- package/lib/esm/components/gift_cards/GiftCardOrCouponRemoveButton.js +1 -1
- package/lib/esm/components/gift_cards/GiftCardOrCouponSubmit.d.ts +6 -12
- package/lib/esm/components/gift_cards/GiftCardOrCouponSubmit.js +1 -1
- package/lib/esm/components/line_items/LineItemOption.d.ts +2 -2
- package/lib/esm/components/line_items/LineItemQuantity.d.ts +4 -16
- package/lib/esm/components/line_items/LineItemQuantity.js +1 -1
- package/lib/esm/components/line_items/LineItemRemoveLink.d.ts +6 -16
- package/lib/esm/components/line_items/LineItemRemoveLink.js +1 -1
- package/lib/esm/components/line_items/LineItemsCount.d.ts +4 -14
- package/lib/esm/components/line_items/LineItemsCount.js +1 -1
- package/lib/esm/components/line_items/LineItemsEmpty.d.ts +6 -17
- package/lib/esm/components/line_items/LineItemsEmpty.js +1 -1
- package/lib/esm/components/orders/AddToCartButton.d.ts +4 -5
- package/lib/esm/components/orders/AddToCartButton.js +1 -1
- package/lib/esm/components/orders/CartLink.d.ts +6 -6
- package/lib/esm/components/orders/CartLink.js +1 -1
- package/lib/esm/components/orders/CheckoutLink.d.ts +4 -4
- package/lib/esm/components/orders/CheckoutLink.js +1 -1
- package/lib/esm/components/orders/ItemContainer.d.ts +2 -13
- package/lib/esm/components/orders/ItemContainer.js +1 -1
- package/lib/esm/components/orders/OrderList.d.ts +10 -11
- package/lib/esm/components/orders/OrderList.js +1 -1
- package/lib/esm/components/orders/OrderListEmpty.d.ts +14 -0
- package/lib/esm/components/orders/OrderListEmpty.js +1 -0
- package/lib/esm/components/orders/OrderListRow.d.ts +1 -1
- package/lib/esm/components/orders/PlaceOrderButton.d.ts +4 -14
- package/lib/esm/components/orders/PlaceOrderButton.js +1 -1
- package/lib/esm/components/parcels/Parcel.d.ts +6 -0
- package/lib/esm/components/parcels/Parcel.js +1 -0
- package/lib/esm/components/payment_source/AdyenPayment.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandIcon.d.ts +4 -14
- package/lib/esm/components/payment_source/PaymentSourceBrandIcon.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandName.d.ts +4 -11
- package/lib/esm/components/payment_source/PaymentSourceBrandName.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +6 -12
- package/lib/esm/components/payment_source/PaymentSourceDetail.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceEditButton.d.ts +4 -10
- package/lib/esm/components/payment_source/PaymentSourceEditButton.js +1 -1
- package/lib/esm/components/prices/Price.d.ts +6 -18
- package/lib/esm/components/prices/Price.js +1 -1
- package/lib/esm/components/prices/PricesContainer.d.ts +4 -20
- package/lib/esm/components/prices/PricesContainer.js +1 -1
- package/lib/esm/components/shipments/Shipment.d.ts +2 -8
- package/lib/esm/components/shipments/Shipment.js +1 -1
- package/lib/esm/components/shipments/ShipmentField.d.ts +0 -7
- package/lib/esm/components/shipments/ShipmentField.js +1 -1
- package/lib/esm/components/shipments/ShipmentsContainer.d.ts +2 -8
- package/lib/esm/components/shipments/ShipmentsContainer.js +1 -1
- package/lib/esm/components/shipping_methods/ShippingMethod.d.ts +2 -9
- package/lib/esm/components/shipping_methods/ShippingMethod.js +1 -1
- package/lib/esm/components/shipping_methods/ShippingMethodName.d.ts +0 -6
- package/lib/esm/components/shipping_methods/ShippingMethodName.js +1 -1
- package/lib/esm/components/skus/AvailabilityTemplate.d.ts +4 -13
- package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
- package/lib/esm/components/skus/QuantitySelector.d.ts +4 -18
- package/lib/esm/components/skus/QuantitySelector.js +1 -1
- package/lib/esm/components/skus/VariantSelector.d.ts +4 -27
- package/lib/esm/components/skus/VariantSelector.js +1 -1
- package/lib/esm/components/utils/AddressCardsTemplate.d.ts +2 -2
- package/lib/esm/components/utils/BaseInput.d.ts +1 -1
- package/lib/esm/components/utils/ErrorBoundary.d.ts +14 -0
- package/lib/esm/components/utils/ErrorBoundary.js +1 -0
- package/lib/esm/components/utils/PaymentCardsTemplate.d.ts +2 -2
- package/lib/esm/components/utils/PriceTemplate.d.ts +2 -2
- package/lib/esm/components/utils/PriceTemplate.js +1 -1
- package/lib/esm/context/BillingAddressFormContext.d.ts +2 -2
- package/lib/esm/context/OrderListChildrenContext.d.ts +8 -0
- package/lib/esm/context/ParcelChildrenContext.d.ts +7 -0
- package/lib/esm/context/ParcelChildrenContext.js +1 -0
- package/lib/esm/context/ShipmentChildrenContext.d.ts +6 -5
- package/lib/esm/context/ShipmentChildrenContext.js +1 -1
- package/lib/esm/index.d.ts +35 -34
- package/lib/esm/index.js +1 -1
- package/lib/esm/reducers/CustomerReducer.d.ts +16 -18
- package/lib/esm/reducers/CustomerReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.d.ts +14 -24
- package/lib/esm/reducers/ShipmentReducer.d.ts +1 -3
- package/lib/esm/typings/errors.d.ts +2 -2
- package/lib/esm/typings/index.d.ts +8 -16
- package/lib/esm/utils/getPrices.d.ts +4 -15
- package/lib/esm/utils/getPrices.js +1 -1
- package/lib/esm/utils/getSdk.d.ts +1 -1
- package/lib/esm/utils/organization.d.ts +2 -2
- package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +46 -35
|
@@ -4,7 +4,7 @@ import type { Address, AddressCreate, AddressUpdate, Customer, CustomerPaymentSo
|
|
|
4
4
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
5
5
|
import { updateOrder } from './OrderReducer';
|
|
6
6
|
export declare type CustomerActionType = 'setErrors' | 'setCustomerEmail' | 'setAddresses' | 'setPayments' | 'setOrders';
|
|
7
|
-
export
|
|
7
|
+
export interface CustomerActionPayload {
|
|
8
8
|
addresses: Address[];
|
|
9
9
|
payments: CustomerPaymentSource[];
|
|
10
10
|
customerEmail: string;
|
|
@@ -12,7 +12,7 @@ export declare type CustomerActionPayload = {
|
|
|
12
12
|
orders: Order[];
|
|
13
13
|
isGuest: boolean;
|
|
14
14
|
customers: Customer;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
export declare type CustomerState = Partial<CustomerActionPayload>;
|
|
17
17
|
export interface CustomerAction {
|
|
18
18
|
type: CustomerActionType;
|
|
@@ -22,7 +22,7 @@ export declare type SetSaveOnBlur = (args: {
|
|
|
22
22
|
saveOnBlur: boolean;
|
|
23
23
|
dispatch: Dispatch<CustomerAction>;
|
|
24
24
|
}) => void;
|
|
25
|
-
export
|
|
25
|
+
export interface SaveCustomerUser {
|
|
26
26
|
/**
|
|
27
27
|
* The Commerce Layer Config
|
|
28
28
|
*/
|
|
@@ -43,11 +43,9 @@ export declare type SaveCustomerUser = {
|
|
|
43
43
|
* The function to update the order resource
|
|
44
44
|
*/
|
|
45
45
|
updateOrder: typeof updateOrder;
|
|
46
|
-
};
|
|
47
|
-
export declare function saveCustomerUser({ customerEmail, order, updateOrder, }: SaveCustomerUser): Promise<void>;
|
|
48
|
-
export interface SetCustomerErrors {
|
|
49
|
-
<V extends BaseError[]>(errors: V, dispatch?: Dispatch<CustomerAction>): void;
|
|
50
46
|
}
|
|
47
|
+
export declare function saveCustomerUser({ customerEmail, order, updateOrder }: SaveCustomerUser): Promise<void>;
|
|
48
|
+
export declare type SetCustomerErrors = <V extends BaseError[]>(errors: V, dispatch?: Dispatch<CustomerAction>) => void;
|
|
51
49
|
export declare function setCustomerErrors(
|
|
52
50
|
/**
|
|
53
51
|
* @param errors - An array of errors
|
|
@@ -66,7 +64,7 @@ customerEmail: string,
|
|
|
66
64
|
* @param dispatch The dispatch function
|
|
67
65
|
*/
|
|
68
66
|
dispatch?: Dispatch<CustomerAction>): void;
|
|
69
|
-
export
|
|
67
|
+
export interface GetCustomerAddresses {
|
|
70
68
|
/**
|
|
71
69
|
* The Commerce Layer config
|
|
72
70
|
*/
|
|
@@ -75,16 +73,16 @@ export declare type GetCustomerAddresses = {
|
|
|
75
73
|
* The Customer dispatch function
|
|
76
74
|
*/
|
|
77
75
|
dispatch: Dispatch<CustomerAction>;
|
|
78
|
-
}
|
|
79
|
-
export declare function getCustomerAddresses({ config, dispatch
|
|
80
|
-
export
|
|
76
|
+
}
|
|
77
|
+
export declare function getCustomerAddresses({ config, dispatch }: GetCustomerAddresses): Promise<void>;
|
|
78
|
+
export interface DeleteCustomerAddress {
|
|
81
79
|
config?: CommerceLayerConfig;
|
|
82
80
|
dispatch?: Dispatch<CustomerAction>;
|
|
83
81
|
customerAddressId: string;
|
|
84
82
|
addresses?: Address[];
|
|
85
|
-
}
|
|
86
|
-
export declare function deleteCustomerAddress({ config, dispatch, customerAddressId, addresses
|
|
87
|
-
export
|
|
83
|
+
}
|
|
84
|
+
export declare function deleteCustomerAddress({ config, dispatch, customerAddressId, addresses }: DeleteCustomerAddress): Promise<void>;
|
|
85
|
+
export interface GetCustomerPaymentSources {
|
|
88
86
|
/**
|
|
89
87
|
* The Customer dispatch function
|
|
90
88
|
*/
|
|
@@ -93,7 +91,7 @@ export declare type GetCustomerPaymentSources = {
|
|
|
93
91
|
* The Commerce Layer Order resource
|
|
94
92
|
*/
|
|
95
93
|
order?: Order;
|
|
96
|
-
}
|
|
94
|
+
}
|
|
97
95
|
export declare function getCustomerPaymentSources(params?: GetCustomerPaymentSources): void;
|
|
98
96
|
export declare type GetCustomerOrders = (params: {
|
|
99
97
|
/**
|
|
@@ -107,7 +105,7 @@ export declare type GetCustomerOrders = (params: {
|
|
|
107
105
|
}) => Promise<void>;
|
|
108
106
|
export declare const getCustomerOrders: GetCustomerOrders;
|
|
109
107
|
export declare type TCustomerAddress = AddressCreate & AddressUpdate;
|
|
110
|
-
|
|
108
|
+
interface TCreateCustomerAddress {
|
|
111
109
|
/**
|
|
112
110
|
* Customer address dispatch function
|
|
113
111
|
*/
|
|
@@ -124,8 +122,8 @@ declare type TCreateCustomerAddress = {
|
|
|
124
122
|
* Current state of the customer
|
|
125
123
|
*/
|
|
126
124
|
state?: CustomerState;
|
|
127
|
-
}
|
|
128
|
-
export declare function createCustomerAddress({ address, config, dispatch, state
|
|
125
|
+
}
|
|
126
|
+
export declare function createCustomerAddress({ address, config, dispatch, state }: TCreateCustomerAddress): Promise<void>;
|
|
129
127
|
export declare const customerInitialState: CustomerState;
|
|
130
128
|
declare const customerReducer: (state: CustomerState, reducer: CustomerAction) => CustomerState;
|
|
131
129
|
export default customerReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.createCustomerAddress=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=tslib_1.__importDefault(require("../utils/jwt"));async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;async function getCustomerAddresses({config,dispatch}){try{const addresses=[];(await(0,getSdk_1.default)(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=(0,getErrors_1.default)(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}}exports.getCustomerAddresses=getCustomerAddresses;async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await(0,getSdk_1.default)(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}}exports.deleteCustomerAddress=deleteCustomerAddress;function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;const getCustomerOrders=async({config,dispatch})=>{if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const customers=await(0,getSdk_1.default)(config).customers.retrieve(owner.id,{include:["orders"]}),orders=customers.orders?.filter(order=>order.status!=="pending"&&order.status!=="draft");dispatch({type:"setOrders",payload:{orders,customers}})}}};exports.getCustomerOrders=getCustomerOrders;async function createCustomerAddress({address,config,dispatch,state}){if(config&&address){const sdk=(0,getSdk_1.default)(config),{id}=address;try{if(id){const upAddress=await sdk.addresses.update(address),updatedAddresses=state?.addresses?.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=await sdk.addresses.create(address);if(state?.customers?.id&&newAddress?.id){const newCustomerAddress=await sdk.customer_addresses.create({customer:sdk.customers.relationship(state?.customers?.id),address:sdk.addresses.relationship(newAddress.id)});await sdk.addresses.update({id:newAddress.id,reference:newCustomerAddress.id}),dispatch&&state?.addresses&&(newAddress.reference=newCustomerAddress.id,dispatch({type:"setAddresses",payload:{addresses:[...state.addresses,newAddress]}}))}}}catch{throw new Error("Couldn't create customer address")}}}exports.createCustomerAddress=createCustomerAddress,exports.customerInitialState={errors:[],addresses:[],payments:[]
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.createCustomerAddress=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=tslib_1.__importDefault(require("../utils/jwt"));async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;async function getCustomerAddresses({config,dispatch}){try{const addresses=[];(await(0,getSdk_1.default)(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=(0,getErrors_1.default)(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}}exports.getCustomerAddresses=getCustomerAddresses;async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await(0,getSdk_1.default)(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}}exports.deleteCustomerAddress=deleteCustomerAddress;function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;const getCustomerOrders=async({config,dispatch})=>{if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const customers=await(0,getSdk_1.default)(config).customers.retrieve(owner.id,{include:["orders"]}),orders=customers.orders?.filter(order=>order.status!=="pending"&&order.status!=="draft");dispatch({type:"setOrders",payload:{orders,customers}})}}};exports.getCustomerOrders=getCustomerOrders;async function createCustomerAddress({address,config,dispatch,state}){if(config&&address){const sdk=(0,getSdk_1.default)(config),{id}=address;try{if(id){const upAddress=await sdk.addresses.update(address),updatedAddresses=state?.addresses?.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=await sdk.addresses.create(address);if(state?.customers?.id&&newAddress?.id){const newCustomerAddress=await sdk.customer_addresses.create({customer:sdk.customers.relationship(state?.customers?.id),address:sdk.addresses.relationship(newAddress.id)});await sdk.addresses.update({id:newAddress.id,reference:newCustomerAddress.id}),dispatch&&state?.addresses&&(newAddress.reference=newCustomerAddress.id,dispatch({type:"setAddresses",payload:{addresses:[...state.addresses,newAddress]}}))}}}catch{throw new Error("Couldn't create customer address")}}}exports.createCustomerAddress=createCustomerAddress,exports.customerInitialState={errors:[],addresses:[],payments:[]};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders"],customerReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=customerReducer;
|
|
@@ -15,13 +15,9 @@ export declare type GetOrderParams = Partial<{
|
|
|
15
15
|
persistKey: string;
|
|
16
16
|
state: OrderState;
|
|
17
17
|
}>;
|
|
18
|
-
export
|
|
19
|
-
(params: GetOrderParams): Promise<void | Order>;
|
|
20
|
-
}
|
|
18
|
+
export declare type GetOrder = (params: GetOrderParams) => Promise<void | Order>;
|
|
21
19
|
declare type CreateOrderParams = Pick<AddToCartParams, 'config' | 'dispatch' | 'persistKey' | 'state' | 'orderMetadata' | 'orderAttributes' | 'setLocalOrder'>;
|
|
22
|
-
export
|
|
23
|
-
(params?: CreateOrderParams): Promise<string>;
|
|
24
|
-
}
|
|
20
|
+
export declare type CreateOrder = (params?: CreateOrderParams) => Promise<string>;
|
|
25
21
|
export declare type AddToCartParams = Partial<{
|
|
26
22
|
bundleCode: string;
|
|
27
23
|
skuCode: string;
|
|
@@ -47,16 +43,10 @@ export declare type AddToCartReturn = Promise<{
|
|
|
47
43
|
success: boolean;
|
|
48
44
|
orderId: string | undefined;
|
|
49
45
|
}>;
|
|
50
|
-
export
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export
|
|
54
|
-
(params: AddToCartImportParams): AddToCartReturn;
|
|
55
|
-
}
|
|
56
|
-
export interface UnsetOrderState {
|
|
57
|
-
(dispatch: Dispatch<OrderActions>): void;
|
|
58
|
-
}
|
|
59
|
-
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' | 'payment_source' | 'available_payment_methods' | 'payment_method';
|
|
46
|
+
export declare type AddToCart = (params: AddToCartParams) => AddToCartReturn;
|
|
47
|
+
export declare type AddToCartImport = (params: AddToCartImportParams) => AddToCartReturn;
|
|
48
|
+
export declare type UnsetOrderState = (dispatch: Dispatch<OrderActions>) => void;
|
|
49
|
+
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' | 'payment_source' | 'available_payment_methods' | 'payment_method';
|
|
60
50
|
declare type ResourceIncludedLoaded = Partial<Record<ResourceIncluded, boolean>>;
|
|
61
51
|
export interface OrderPayload {
|
|
62
52
|
loading?: boolean;
|
|
@@ -78,15 +68,15 @@ export interface OrderActions {
|
|
|
78
68
|
export declare type OrderActionType = 'setLoading' | 'setOrderId' | 'setOrder' | 'setSingleQuantity' | 'setCurrentSkuCodes' | 'setCurrentSkuPrices' | 'setCurrentItem' | 'setErrors' | 'setSaveAddressToCustomerAddressBook' | 'setGiftCardOrCouponCode' | 'setIncludesResource';
|
|
79
69
|
export declare const createOrder: CreateOrder;
|
|
80
70
|
export declare const getApiOrder: GetOrder;
|
|
81
|
-
export
|
|
71
|
+
export interface UpdateOrderArgs {
|
|
82
72
|
id: string;
|
|
83
73
|
attributes: Omit<OrderUpdate, 'id'>;
|
|
84
74
|
dispatch?: Dispatch<OrderActions>;
|
|
85
75
|
include?: string[];
|
|
86
76
|
config?: CommerceLayerConfig;
|
|
87
77
|
state?: OrderState;
|
|
88
|
-
}
|
|
89
|
-
export declare function updateOrder({ id, attributes, dispatch, config, include, state
|
|
78
|
+
}
|
|
79
|
+
export declare function updateOrder({ id, attributes, dispatch, config, include, state }: UpdateOrderArgs): Promise<{
|
|
90
80
|
success: boolean;
|
|
91
81
|
error?: undefined;
|
|
92
82
|
} | {
|
|
@@ -94,20 +84,20 @@ export declare function updateOrder({ id, attributes, dispatch, config, include,
|
|
|
94
84
|
error: unknown;
|
|
95
85
|
}>;
|
|
96
86
|
export declare const setOrder: (order: Order, dispatch?: Dispatch<OrderActions>) => void;
|
|
97
|
-
export
|
|
87
|
+
export interface AddResourceToInclude {
|
|
98
88
|
resourcesIncluded?: ResourceIncluded[];
|
|
99
89
|
dispatch?: Dispatch<OrderActions>;
|
|
100
90
|
newResource?: ResourceIncluded | ResourceIncluded[];
|
|
101
91
|
resourceIncludedLoaded?: ResourceIncludedLoaded;
|
|
102
92
|
newResourceLoaded?: ResourceIncludedLoaded;
|
|
103
|
-
}
|
|
104
|
-
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, newResourceLoaded, resourceIncludedLoaded
|
|
93
|
+
}
|
|
94
|
+
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, newResourceLoaded, resourceIncludedLoaded }: AddResourceToInclude): void;
|
|
105
95
|
export declare const addToCart: AddToCart;
|
|
106
96
|
export declare const unsetOrderState: UnsetOrderState;
|
|
107
|
-
|
|
97
|
+
interface OrderErrors {
|
|
108
98
|
dispatch?: Dispatch<OrderActions>;
|
|
109
99
|
errors: BaseError[];
|
|
110
|
-
}
|
|
100
|
+
}
|
|
111
101
|
export declare function setOrderErrors({ dispatch, errors }: OrderErrors): {
|
|
112
102
|
success: boolean;
|
|
113
103
|
};
|
|
@@ -18,9 +18,7 @@ export interface ShipmentAction {
|
|
|
18
18
|
payload: Partial<ShipmentActionPayload>;
|
|
19
19
|
}
|
|
20
20
|
export declare const shipmentInitialState: ShipmentState;
|
|
21
|
-
export
|
|
22
|
-
<V extends BaseError[]>(errors: V, dispatch?: Dispatch<ShipmentAction>): void;
|
|
23
|
-
}
|
|
21
|
+
export declare type SetShipmentErrors = <V extends BaseError[]>(errors: V, dispatch?: Dispatch<ShipmentAction>) => void;
|
|
24
22
|
export declare const setShipmentErrors: SetShipmentErrors;
|
|
25
23
|
declare type GetShipments = (args: {
|
|
26
24
|
order: Order;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
|
-
import {
|
|
2
|
+
import { ChildrenFunction } from './index';
|
|
3
3
|
export declare type CodeErrorType = 'EMPTY_ERROR' | 'FILTER_NOT_ALLOWED' | 'FORBIDDEN' | 'INTERNAL_SERVER_ERROR' | 'INVALID_DATA_FORMAT' | 'INVALID_FIELD' | 'INVALID_FIELD_FORMAT' | 'INVALID_FIELD_VALUE' | 'INVALID_FILTERS_SYNTAX' | 'INVALID_FILTER_VALUE' | 'INVALID_INCLUDE' | 'INVALID_LINKS_OBJECT' | 'INVALID_PAGE_OBJECT' | 'INVALID_PAGE_VALUE' | 'INVALID_RESOURCE' | 'INVALID_RESOURCE_ID' | 'INVALID_SORT_CRITERIA' | 'INVALID_TOKEN' | 'KEY_NOT_INCLUDED_IN_URL' | 'KEY_ORDER_MISMATCH' | 'LOCKED' | 'NOT_ACCEPTABLE' | 'OUT_OF_STOCK' | 'PARAM_MISSING' | 'PARAM_NOT_ALLOWED' | 'PAYMENT_NOT_APPROVED_FOR_EXECUTION' | 'PAYMENT_INTENT_AUTHENTICATION_FAILURE' | 'RECORD_NOT_FOUND' | 'RECORD_NOT_FOUND' | 'RELATION_EXISTS' | 'NO_SHIPPING_METHODS' | 'SAVE_FAILED' | 'TYPE_MISMATCH' | 'UNAUTHORIZED' | 'UNSUPPORTED_MEDIA_TYPE' | 'VALIDATION_ERROR';
|
|
4
4
|
export declare type ResourceErrorType = 'addresses' | 'billing_address' | 'gift_cards' | 'gift_card_or_coupon_code' | 'line_items' | 'orders' | 'payment_methods' | 'prices' | 'shipments' | 'shipping_address' | 'customer_address' | 'sku_options' | 'variant';
|
|
5
5
|
export interface BaseError {
|
|
@@ -24,7 +24,7 @@ export declare const ErrorPropTypes: {
|
|
|
24
24
|
children: PropTypes.Requireable<(...args: any[]) => any>;
|
|
25
25
|
field: PropTypes.Requireable<string>;
|
|
26
26
|
};
|
|
27
|
-
declare type ErrorChildrenComponentProps =
|
|
27
|
+
declare type ErrorChildrenComponentProps = ChildrenFunction<Omit<ErrorComponentProps, 'children'> & {
|
|
28
28
|
errors: string[];
|
|
29
29
|
}>;
|
|
30
30
|
export declare type ErrorComponentProps = {
|
|
@@ -24,11 +24,11 @@ export declare const BaseSelectComponentPropTypes: {
|
|
|
24
24
|
};
|
|
25
25
|
export declare type SelectPlaceholder = Option;
|
|
26
26
|
declare type BaseSelectChildrenComponentProps = Omit<BaseSelectComponentProps, 'children'>;
|
|
27
|
-
|
|
27
|
+
interface Option {
|
|
28
28
|
label: string;
|
|
29
29
|
value: string | number;
|
|
30
30
|
disabled?: boolean;
|
|
31
|
-
}
|
|
31
|
+
}
|
|
32
32
|
export interface BaseSelectComponentProps {
|
|
33
33
|
children?: (props: BaseSelectChildrenComponentProps) => JSX.Element;
|
|
34
34
|
options: Option[];
|
|
@@ -67,9 +67,9 @@ export declare type LoaderType = string | ReactNode;
|
|
|
67
67
|
export declare const BMObject: PropTypes.Requireable<{
|
|
68
68
|
[x: string]: string | null | undefined;
|
|
69
69
|
}>;
|
|
70
|
-
export
|
|
70
|
+
export interface BaseMetadataObject {
|
|
71
71
|
[key: string]: string | undefined | null;
|
|
72
|
-
}
|
|
72
|
+
}
|
|
73
73
|
export declare type TimeFormat = 'days' | 'hours';
|
|
74
74
|
export declare type BaseComponent = InferProps<typeof BC>;
|
|
75
75
|
export interface BaseAction<A = string, P = Record<string, any>> {
|
|
@@ -81,15 +81,9 @@ export interface BaseState {
|
|
|
81
81
|
errors?: BaseError[];
|
|
82
82
|
}
|
|
83
83
|
export declare type BaseActionType<T = string> = T[];
|
|
84
|
-
export
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
export interface BaseReducer {
|
|
88
|
-
<S extends BaseState, A extends BaseAction, T extends BaseActionType>(state: S, action: A, type: T): S;
|
|
89
|
-
}
|
|
90
|
-
export interface BaseUnsetState<A> {
|
|
91
|
-
(dispatch: Dispatch<A>): void;
|
|
92
|
-
}
|
|
84
|
+
export declare type BFSetStateContainer<T> = <P extends T>(param: P) => void;
|
|
85
|
+
export declare type BaseReducer = <S extends BaseState, A extends BaseAction, T extends BaseActionType>(state: S, action: A, type: T) => S;
|
|
86
|
+
export declare type BaseUnsetState<A> = (dispatch: Dispatch<A>) => void;
|
|
93
87
|
export interface BaseMetadata {
|
|
94
88
|
[key: string]: string | undefined | null;
|
|
95
89
|
}
|
|
@@ -122,9 +116,7 @@ export declare type BaseAmountComponent = {
|
|
|
122
116
|
priceCents?: number;
|
|
123
117
|
labelFree?: string;
|
|
124
118
|
} & JSX.IntrinsicElements['span'];
|
|
125
|
-
export
|
|
126
|
-
(props: P): JSX.Element;
|
|
127
|
-
}
|
|
119
|
+
export declare type ChildrenFunction<P = Record<string, any>> = (props: P) => JSX.Element;
|
|
128
120
|
export declare type ExcludeTag<T extends keyof JSX.IntrinsicElements> = Exclude<keyof JSX.IntrinsicElements, T>;
|
|
129
121
|
export declare type ExtractTag<T extends keyof JSX.IntrinsicElements> = Extract<keyof JSX.IntrinsicElements, T>;
|
|
130
122
|
export declare type ConditionalElement<E> = ({
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { Price } from '@commercelayer/sdk';
|
|
2
|
-
import { Prices } from '../reducers/PriceReducer';
|
|
3
|
-
import { Items } from '../reducers/ItemReducer';
|
|
4
|
-
import { ReactNode } from 'react';
|
|
5
3
|
import { PTemplateProps } from '../components/utils/PriceTemplate';
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare const getPriceByCode: GetPriceByCode;
|
|
10
|
-
export interface GetPricesComponent {
|
|
11
|
-
(skuPrices: Price[], props: PTemplateProps): ReactNode;
|
|
12
|
-
}
|
|
13
|
-
export declare const getPricesComponent: GetPricesComponent;
|
|
14
|
-
export interface GetPrices {
|
|
15
|
-
(prices: Price[] | Items): Prices;
|
|
16
|
-
}
|
|
17
|
-
export default function getPrices<P extends Price>(prices: P[]): Record<string, any>;
|
|
4
|
+
export declare function getPriceByCode(skuPrices: Price[], code?: string): Price | undefined;
|
|
5
|
+
export declare function getPricesComponent(skuPrices: Price[], props: PTemplateProps): JSX.Element[] | JSX.Element;
|
|
6
|
+
export default function getPrices<P extends Price>(prices: P[]): Record<string, P[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPricesComponent=exports.getPriceByCode=void 0;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),lodash_1=require("lodash"),PriceTemplate_1=tslib_1.__importDefault(require("../components/utils/PriceTemplate"))
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPricesComponent=exports.getPriceByCode=void 0;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),lodash_1=require("lodash"),PriceTemplate_1=tslib_1.__importDefault(require("../components/utils/PriceTemplate"));function getPriceByCode(skuPrices,code=""){return code?(0,lodash_1.first)(skuPrices.filter(p=>p.currency_code===code)):(0,lodash_1.first)(skuPrices)}exports.getPriceByCode=getPriceByCode;function getPricesComponent(skuPrices,props){return(0,lodash_1.isEmpty)(skuPrices)?(0,jsx_runtime_1.jsx)(PriceTemplate_1.default,{...props}):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return(0,react_1.createElement)(PriceTemplate_1.default,{...props,key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code})})}exports.getPricesComponent=getPricesComponent;function getPrices(prices){const obj={};return(0,lodash_1.isArray)(prices)&&prices.forEach(p=>{const sku=p.sku_code;(0,lodash_1.has)(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}exports.default=getPrices;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import Sdk from '@commercelayer/sdk';
|
|
2
2
|
import { CommerceLayerConfig } from '../context/CommerceLayerContext';
|
|
3
|
-
export default function getSdk({ endpoint, accessToken
|
|
3
|
+
export default function getSdk({ endpoint, accessToken }: CommerceLayerConfig): ReturnType<typeof Sdk>;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { ChildrenFunction } from '../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
|
+
}
|
|
5
|
+
interface Props extends Omit<JSX.IntrinsicElements['button'], 'children'> {
|
|
6
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
6
7
|
label?: string | ReactNode;
|
|
7
|
-
} & JSX.IntrinsicElements['button'];
|
|
8
|
-
export declare function SubmitButton(props: Props): JSX.Element;
|
|
9
|
-
export declare namespace SubmitButton {
|
|
10
|
-
var propTypes: {
|
|
11
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
12
|
-
label: import("prop-types").Requireable<NonNullable<string | import("prop-types").ReactElementLike | null | undefined>>;
|
|
13
|
-
};
|
|
14
|
-
var defaultProps: {
|
|
15
|
-
label: string;
|
|
16
|
-
};
|
|
17
|
-
var displayName: string;
|
|
18
8
|
}
|
|
9
|
+
export declare function SubmitButton(props: Props): JSX.Element;
|
|
19
10
|
export default SubmitButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./utils/Parent";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"./utils/Parent";import isFunction from"lodash/isFunction";export function SubmitButton(props){const{children,label="Submit",...p}=props,parentProps={...p,label};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"submit",...p,children:isFunction(label)?label():label})}export default SubmitButton;
|
|
@@ -5,15 +5,4 @@ declare type Props = {
|
|
|
5
5
|
name: Extract<AddressValuesKeys, AddressInputName>;
|
|
6
6
|
} & Omit<BaseInputComponentProps, 'name'> & JSX.IntrinsicElements['input'] & JSX.IntrinsicElements['textarea'];
|
|
7
7
|
export declare function AddressInput(props: Props): JSX.Element | null;
|
|
8
|
-
export declare namespace AddressInput {
|
|
9
|
-
var propTypes: {
|
|
10
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
11
|
-
name: import("prop-types").Validator<NonNullable<AddressInputName>>;
|
|
12
|
-
type: import("prop-types").Validator<NonNullable<import("../../typings/index").BaseInputType>>;
|
|
13
|
-
placeholder: import("prop-types").Requireable<string>;
|
|
14
|
-
disabled: import("prop-types").Requireable<boolean>;
|
|
15
|
-
required: import("prop-types").Requireable<boolean>;
|
|
16
|
-
};
|
|
17
|
-
var displayName: string;
|
|
18
|
-
}
|
|
19
8
|
export default AddressInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"../utils/BaseInput";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"../utils/BaseInput";import BillingAddressFormContext from"../../context/BillingAddressFormContext";import ShippingAddressFormContext from"../../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../../utils/validateFormFields";import CustomerAddressFormContext from"../../context/CustomerAddressFormContext";export function AddressInput(props){const{placeholder="",required,value,className,...p}=props,billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),customerAddress=useContext(CustomerAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>(value&&billingAddress?.setValue&&billingAddress.setValue(p.name,value),value&&shippingAddress?.setValue&&shippingAddress.setValue(p.name,value),value&&customerAddress?.setValue&&customerAddress.setValue(p.name,value),billingAddress.errors&&billingAddress?.errors?.[p.name]?.error&&setHasError(!0),billingAddress&&isEmpty(billingAddress?.errors?.[p.name])&&hasError&&setHasError(!1),customerAddress.errors&&customerAddress?.errors?.[p.name]?.error&&setHasError(!0),isEmpty(customerAddress?.errors?.[p.name])&&hasError&&setHasError(!1),shippingAddress.errors&&shippingAddress?.errors?.[p.name]?.error&&setHasError(!0),shippingAddress&&isEmpty(shippingAddress?.errors?.[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}),[value,billingAddress?.errors,shippingAddress?.errors]);const mandatoryField=billingAddress?.isBusiness?businessMandatoryField(p.name,billingAddress.isBusiness):businessMandatoryField(p.name,shippingAddress.isBusiness),reqField=required!==void 0?required:mandatoryField,errorClassName=billingAddress?.errorClassName||shippingAddress?.errorClassName,classNameComputed=`${className||""} ${hasError&&errorClassName?errorClassName:""}`;return p.name==="billing_address_billing_info"&&!billingAddress.requiresBillingInfo?null:_jsx(BaseInput,{ref:billingAddress?.validation||shippingAddress?.validation||customerAddress?.validation,className:classNameComputed,required:reqField,placeholder,defaultValue:value,...p})}export default AddressInput;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
|
+
}
|
|
4
5
|
declare type Props = {
|
|
5
|
-
children?: ChildrenProps
|
|
6
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
6
7
|
label?: string | ReactNode;
|
|
7
8
|
onClick?: () => void;
|
|
8
9
|
addressId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"../utils/Parent";import AddressContext from"../../context/AddressContext";import{shippingAddressController,countryLockController,billingAddressController}from"../../utils/addressesManager";import OrderContext from"../../context/OrderContext";import CustomerContext from"../../context/CustomerContext";import isFunction from"lodash/isFunction";export function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,onClick,...p}=props,{errors,billing_address,shipToDifferentAddress,shipping_address,saveAddresses,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),{addresses,isGuest,createCustomerAddress}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled),customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email,billingDisable=billingAddressController({billing_address,errors,billingAddressId,requiresBillingInfo:order?.requires_billing_info}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId}),countryLockDisable=countryLockController({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address,shipping_address,shippingAddressId}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=()=>{if(errors&&Object.keys(errors).length===0&&!disable){if(setForceDisable(!0),order)saveAddresses();else if(createCustomerAddress&&
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"../utils/Parent";import AddressContext from"../../context/AddressContext";import{shippingAddressController,countryLockController,billingAddressController}from"../../utils/addressesManager";import OrderContext from"../../context/OrderContext";import CustomerContext from"../../context/CustomerContext";import isFunction from"lodash/isFunction";export function SaveAddressesButton(props){const{children,label="Continue to delivery",resource,disabled=!1,addressId,onClick,...p}=props,{errors,billing_address:billingAddress,shipToDifferentAddress,shipping_address:shippingAddress,saveAddresses,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),{addresses,isGuest,createCustomerAddress}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled),customerEmail=(isGuest===!0||typeof isGuest>"u")&&!order?.customer_email,billingDisable=billingAddressController({billing_address:billingAddress,errors,billingAddressId,requiresBillingInfo:order?.requires_billing_info}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address:shippingAddress,shippingAddressId}),countryLockDisable=countryLockController({countryCodeLock:order?.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address:billingAddress,shipping_address:shippingAddress,shippingAddressId}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=()=>{if(errors&&Object.keys(errors).length===0&&!disable){if(setForceDisable(!0),order)saveAddresses();else if(createCustomerAddress&&billingAddress){const address={...billingAddress};addressId&&(address.id=addressId),createCustomerAddress(address)}setForceDisable(!1),onClick&&onClick()}},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable||forceDisable,onClick:handleClick,...p,children:isFunction(label)?label():label})}export default SaveAddressesButton;
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
declare type Props = {
|
|
3
|
-
children:
|
|
3
|
+
children: JSX.Element[] | JSX.Element;
|
|
4
4
|
accessToken: string;
|
|
5
5
|
endpoint: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function CommerceLayer(props: Props): JSX.Element;
|
|
8
|
-
export declare namespace CommerceLayer {
|
|
9
|
-
var propTypes: {
|
|
10
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
11
|
-
accessToken: import("prop-types").Validator<string>;
|
|
12
|
-
endpoint: import("prop-types").Validator<string>;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
8
|
export default CommerceLayer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import CommerceLayerContext from"../../context/CommerceLayerContext";import ErrorBoundary from"../utils/ErrorBoundary";export function CommerceLayer(props){const{children,...p}=props;return _jsx(ErrorBoundary,{children:_jsx(CommerceLayerContext.Provider,{value:{...p},children})})}export default CommerceLayer;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
handleClick: () => void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
children?: ChildrenProps;
|
|
5
|
+
}
|
|
6
|
+
interface Props extends Omit<JSX.IntrinsicElements['button'], 'children'> {
|
|
7
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
8
|
label?: string | ReactNode;
|
|
10
9
|
onClick?: () => void;
|
|
11
|
-
}
|
|
10
|
+
}
|
|
12
11
|
export declare function SaveCustomerButton(props: Props): JSX.Element;
|
|
13
12
|
export default SaveCustomerButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import{isEmpty}from"lodash";import CustomerContext from"../../context/CustomerContext";export function SaveCustomerButton(props){const{children,label="Save",resource,disabled,onClick,...p}=props,{errors,saveCustomerUser,customerEmail}=useContext(CustomerContext),disable=disabled||!isEmpty(errors)||isEmpty(customerEmail),handleClick=async()=>{isEmpty(errors)&&!disable&&(saveCustomerUser&&await saveCustomerUser(customerEmail),onClick&&onClick())},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable,onClick:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import{isEmpty}from"lodash";import CustomerContext from"../../context/CustomerContext";export function SaveCustomerButton(props){const{children,label="Save",resource,disabled,onClick,...p}=props,{errors,saveCustomerUser,customerEmail}=useContext(CustomerContext),disable=disabled||!isEmpty(errors)||isEmpty(customerEmail),handleClick=async()=>{isEmpty(errors)&&!disable&&(saveCustomerUser&&await saveCustomerUser(customerEmail),onClick&&onClick())},parentProps={...p,label,resource,handleClick,disabled:disable};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"button",disabled:disable,onClick:()=>{handleClick()},...p,children:label})}export default SaveCustomerButton;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
3
|
import type { CodeType } from '../../reducers/OrderReducer';
|
|
4
|
-
|
|
4
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
5
5
|
code?: string;
|
|
6
6
|
hide?: boolean;
|
|
7
|
-
discountAmountCents?:
|
|
8
|
-
discountAmountFloat?:
|
|
7
|
+
discountAmountCents?: number;
|
|
8
|
+
discountAmountFloat?: number;
|
|
9
9
|
formattedDiscountAmount?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare type Props = {
|
|
10
|
+
}
|
|
11
|
+
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
13
12
|
type?: CodeType;
|
|
14
|
-
children?:
|
|
15
|
-
} & JSX.IntrinsicElements['span'];
|
|
16
|
-
export declare function GiftCardOrCouponCode({ children, type, ...props }: Props): JSX.Element | null;
|
|
17
|
-
export declare namespace GiftCardOrCouponCode {
|
|
18
|
-
var propTypes: {
|
|
19
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
20
|
-
type: import("prop-types").Requireable<CodeType>;
|
|
21
|
-
};
|
|
22
|
-
var displayName: string;
|
|
13
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
23
14
|
}
|
|
15
|
+
export declare function GiftCardOrCouponCode({ children, type, ...props }: Props): JSX.Element | null;
|
|
24
16
|
export default GiftCardOrCouponCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import has from"lodash/has";import isEmpty from"lodash/isEmpty";export function GiftCardOrCouponCode({children,type,...props}){const{order}=useContext(OrderContext);let codeType=type&&`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),parentProps={...props,code,hide,discountAmountCents:order?.discount_amount_cents,discountAmountFloat:order?.discount_amount_float,formattedDiscountAmount:order?.formatted_discount_amount};return children?_jsx(Parent,{...parentProps,children}):hide?null:_jsx("span",{...props,children:code})}export default GiftCardOrCouponCode;
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
3
|
import { CodeType, OrderCodeType } from '../../reducers/OrderReducer';
|
|
4
|
-
|
|
4
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
5
5
|
codeType?: OrderCodeType;
|
|
6
6
|
hide?: boolean;
|
|
7
7
|
handleClick?: () => void;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
declare type Props = {
|
|
10
10
|
type?: CodeType;
|
|
11
|
-
children?:
|
|
11
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
12
12
|
label?: string | ReactNode;
|
|
13
13
|
onClick?: (response: {
|
|
14
14
|
success: boolean;
|
|
15
15
|
}) => void;
|
|
16
16
|
} & Omit<JSX.IntrinsicElements['button'], 'type'>;
|
|
17
17
|
export declare function GiftCardOrCouponRemoveButton(props: Props): JSX.Element | null;
|
|
18
|
-
export declare namespace GiftCardOrCouponRemoveButton {
|
|
19
|
-
var propTypes: {
|
|
20
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
21
|
-
type: import("prop-types").Requireable<CodeType>;
|
|
22
|
-
label: import("prop-types").Requireable<NonNullable<string | object | null | undefined>>;
|
|
23
|
-
};
|
|
24
|
-
var displayName: string;
|
|
25
|
-
}
|
|
26
18
|
export default GiftCardOrCouponRemoveButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import{has,isEmpty}from"lodash";export function GiftCardOrCouponRemoveButton(props){const{children,label="Remove",onClick,type,...p}=props,{order,removeGiftCardOrCouponCode}=useContext(OrderContext);let codeType=type?`${type}_code`:void 0;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=async()=>{const response=removeGiftCardOrCouponCode&&codeType&&await removeGiftCardOrCouponCode({codeType});onClick&&response&&onClick(response)},parentProps={...p,label,handleClick,codeType};return children?_jsx(Parent,{...parentProps,children}):hide?null:_jsx("button",{type:"button",onClick:()=>{handleClick()},...p,children:label})}export default GiftCardOrCouponRemoveButton;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
|
+
}
|
|
5
|
+
interface Props extends Omit<JSX.IntrinsicElements['button'], 'children'> {
|
|
6
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
6
7
|
label?: string | ReactNode;
|
|
7
|
-
} & JSX.IntrinsicElements['button'];
|
|
8
|
-
export declare function GiftCardOrCouponSubmit(props: Props): JSX.Element;
|
|
9
|
-
export declare namespace GiftCardOrCouponSubmit {
|
|
10
|
-
var propTypes: {
|
|
11
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
12
|
-
label: import("prop-types").Requireable<NonNullable<string | object | null | undefined>>;
|
|
13
|
-
};
|
|
14
|
-
var displayName: string;
|
|
15
8
|
}
|
|
9
|
+
export declare function GiftCardOrCouponSubmit(props: Props): JSX.Element;
|
|
16
10
|
export default GiftCardOrCouponSubmit;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";export function GiftCardOrCouponSubmit(props){const{children,label="Submit",...p}=props,parentProps={...p,label};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{type:"submit",...p,children:label})}export default GiftCardOrCouponSubmit;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CSSProperties } from 'react';
|
|
2
2
|
import { LineItemOption as LineItemOptionType } from '@commercelayer/sdk';
|
|
3
|
-
import {
|
|
4
|
-
declare type LineItemOptionChildrenProps =
|
|
3
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
4
|
+
declare type LineItemOptionChildrenProps = ChildrenFunction<Omit<Props, 'children'> & {
|
|
5
5
|
lineItemOption: LineItemOptionType;
|
|
6
6
|
}>;
|
|
7
7
|
declare type Props = {
|