@commercelayer/react-components 4.0.0-alpha.5 → 4.0.0-alpha.7
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/Address.d.ts +4 -9
- package/lib/cjs/components/addresses/Address.js +1 -1
- package/lib/cjs/components/addresses/AddressField.d.ts +8 -12
- package/lib/cjs/components/addresses/AddressField.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/AddressesContainer.d.ts +2 -9
- package/lib/cjs/components/addresses/AddressesContainer.js +1 -1
- package/lib/cjs/components/addresses/AddressesEmpty.d.ts +14 -0
- package/lib/cjs/components/addresses/AddressesEmpty.js +1 -0
- 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/CustomerContainer.d.ts +2 -2
- package/lib/cjs/components/customers/CustomerContainer.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/OrderContainer.d.ts +4 -18
- package/lib/cjs/components/orders/OrderContainer.js +1 -1
- package/lib/cjs/components/orders/OrderList.d.ts +11 -12
- 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 +9 -5
- package/lib/cjs/components/orders/OrderListRow.js +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 +8 -8
- package/lib/cjs/components/utils/AddressCardsTemplate.js +1 -1
- 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/OrderContext.d.ts +3 -3
- 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 +36 -34
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/reducers/AddressReducer.d.ts +17 -23
- package/lib/cjs/reducers/AddressReducer.js +1 -1
- package/lib/cjs/reducers/CustomerReducer.d.ts +18 -20
- package/lib/cjs/reducers/CustomerReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.d.ts +16 -29
- package/lib/cjs/reducers/OrderReducer.js +1 -1
- 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/addressesManager.d.ts +5 -4
- 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/Address.d.ts +4 -9
- package/lib/esm/components/addresses/Address.js +1 -1
- package/lib/esm/components/addresses/AddressField.d.ts +8 -12
- package/lib/esm/components/addresses/AddressField.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/AddressesContainer.d.ts +2 -9
- package/lib/esm/components/addresses/AddressesContainer.js +1 -1
- package/lib/esm/components/addresses/AddressesEmpty.d.ts +14 -0
- package/lib/esm/components/addresses/AddressesEmpty.js +1 -0
- 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/CustomerContainer.d.ts +2 -2
- package/lib/esm/components/customers/CustomerContainer.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/OrderContainer.d.ts +4 -18
- package/lib/esm/components/orders/OrderContainer.js +1 -1
- package/lib/esm/components/orders/OrderList.d.ts +11 -12
- 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 +9 -5
- package/lib/esm/components/orders/OrderListRow.js +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 +8 -8
- package/lib/esm/components/utils/AddressCardsTemplate.js +1 -1
- 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/OrderContext.d.ts +3 -3
- 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 +36 -34
- package/lib/esm/index.js +1 -1
- package/lib/esm/reducers/AddressReducer.d.ts +17 -23
- package/lib/esm/reducers/AddressReducer.js +1 -1
- package/lib/esm/reducers/CustomerReducer.d.ts +18 -20
- package/lib/esm/reducers/CustomerReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.d.ts +16 -29
- package/lib/esm/reducers/OrderReducer.js +1 -1
- 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/addressesManager.d.ts +5 -4
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PaymentResource, PaymentSourceType } from '../../reducers/PaymentMethodReducer';
|
|
3
3
|
import PaymentSourceContext, { IconBrand } from '../../context/PaymentSourceContext';
|
|
4
|
-
import {
|
|
4
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
5
5
|
declare type ChildrenProps = Pick<Props, 'customerPayments'> & {
|
|
6
6
|
PaymentSourceProvider: typeof PaymentSourceContext.Provider;
|
|
7
7
|
};
|
|
@@ -12,7 +12,7 @@ declare type CustomerPayment = PaymentSourceType & {
|
|
|
12
12
|
};
|
|
13
13
|
handleClick?: () => void;
|
|
14
14
|
};
|
|
15
|
-
export declare type CustomerCardsTemplateChildren =
|
|
15
|
+
export declare type CustomerCardsTemplateChildren = ChildrenFunction<ChildrenProps>;
|
|
16
16
|
export declare type CustomerCardsType = ChildrenProps;
|
|
17
17
|
declare type Props = {
|
|
18
18
|
customerPayments: CustomerPayment[];
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { PriceProps } from '../prices/Price';
|
|
3
3
|
export declare type PTemplateProps = {
|
|
4
4
|
formattedAmount?: string;
|
|
5
5
|
formattedCompare?: string;
|
|
6
6
|
} & Omit<PriceProps, 'children'>;
|
|
7
|
-
declare
|
|
7
|
+
export declare function PriceTemplate(props: PTemplateProps): JSX.Element;
|
|
8
8
|
export default PriceTemplate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";
|
|
1
|
+
import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";export function PriceTemplate(props){const{showCompare,formattedCompare,compareClassName,className,formattedAmount,skuCode,...p}=props;return _jsxs(_Fragment,{children:[_jsx("span",{"data-testid":`price-${skuCode??""}`,className,...p,children:formattedAmount}),showCompare&&_jsx("span",{"data-testid":`compare-${skuCode??""}`,className:compareClassName||"",...p,children:formattedCompare})]})}export default PriceTemplate;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Address } from '@commercelayer/sdk';
|
|
3
3
|
export declare type AddressValuesKeys = `${keyof Address}` | `billing_address_${keyof Address}` | `shipping_address_${keyof Address}`;
|
|
4
|
-
export
|
|
4
|
+
export interface DefaultContextAddress {
|
|
5
5
|
validation?: void;
|
|
6
6
|
setValue?: (name: AddressValuesKeys, value: string | number | readonly string[]) => void;
|
|
7
7
|
errors?: {
|
|
@@ -20,6 +20,6 @@ export declare type DefaultContextAddress = {
|
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
22
|
isBusiness?: boolean;
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
24
|
declare const BillingAddressFormContext: import("react").Context<DefaultContextAddress>;
|
|
25
25
|
export default BillingAddressFormContext;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { Order } from '@commercelayer/sdk';
|
|
3
3
|
import { AddToCart, OrderState, CreateOrder, SetGiftCardOrCouponCode, RemoveGiftCardOrCouponCode, SaveAddressToCustomerAddressBook, addResourceToInclude, updateOrder, getOrderContext } from '../reducers/OrderReducer';
|
|
4
4
|
import { BaseError } from '../typings/errors';
|
|
5
|
-
|
|
5
|
+
interface DefaultContext extends OrderState {
|
|
6
6
|
createOrder: CreateOrder;
|
|
7
7
|
addToCart: AddToCart;
|
|
8
8
|
setOrderErrors: (errors: BaseError[]) => void;
|
|
@@ -13,7 +13,7 @@ declare type DefaultContext = {
|
|
|
13
13
|
getOrder: getOrderContext;
|
|
14
14
|
updateOrder: typeof updateOrder;
|
|
15
15
|
setOrder: (order: Order) => void;
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
export declare const defaultOrderContext: {
|
|
18
18
|
addToCart: AddToCart;
|
|
19
19
|
createOrder: CreateOrder;
|
|
@@ -23,7 +23,7 @@ export declare const defaultOrderContext: {
|
|
|
23
23
|
removeGiftCardOrCouponCode: RemoveGiftCardOrCouponCode;
|
|
24
24
|
saveAddressToCustomerAddressBook: SaveAddressToCustomerAddressBook;
|
|
25
25
|
addResourceToInclude: typeof addResourceToInclude;
|
|
26
|
-
getOrder: () => Promise<
|
|
26
|
+
getOrder: () => Promise<undefined>;
|
|
27
27
|
updateOrder: typeof updateOrder;
|
|
28
28
|
};
|
|
29
29
|
declare const OrderContext: import("react").Context<DefaultContext>;
|
|
@@ -6,6 +6,10 @@ export declare type InitialOrderListContext = Partial<{
|
|
|
6
6
|
* The current order
|
|
7
7
|
*/
|
|
8
8
|
order: Order | null;
|
|
9
|
+
/**
|
|
10
|
+
* The list of orders
|
|
11
|
+
*/
|
|
12
|
+
orders: Order[] | null;
|
|
9
13
|
/**
|
|
10
14
|
* The current row
|
|
11
15
|
*/
|
|
@@ -34,6 +38,10 @@ declare const OrderListChildrenContext: import("react").Context<Partial<{
|
|
|
34
38
|
* The current order
|
|
35
39
|
*/
|
|
36
40
|
order: Order | null;
|
|
41
|
+
/**
|
|
42
|
+
* The list of orders
|
|
43
|
+
*/
|
|
44
|
+
orders: Order[] | null;
|
|
37
45
|
/**
|
|
38
46
|
* The current row
|
|
39
47
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createContext}from"react";const initial={};export default createContext(initial);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { DeliveryLeadTime, LineItem, Shipment, ShippingMethod, StockTransfer } from '@commercelayer/sdk';
|
|
2
|
+
import type { DeliveryLeadTime, LineItem, Parcel, Shipment, ShippingMethod, StockTransfer } from '@commercelayer/sdk';
|
|
3
3
|
export interface InitialShipmentContext {
|
|
4
|
-
lineItems?: LineItem[];
|
|
5
|
-
shippingMethods?: ShippingMethod[];
|
|
6
4
|
currentShippingMethodId?: string;
|
|
7
|
-
stockTransfers?: StockTransfer[];
|
|
8
5
|
deliveryLeadTimes?: DeliveryLeadTime[];
|
|
9
|
-
shipment?: Shipment;
|
|
10
6
|
keyNumber: number;
|
|
7
|
+
lineItems?: LineItem[];
|
|
8
|
+
parcels?: Parcel[];
|
|
9
|
+
shipment?: Shipment;
|
|
10
|
+
shippingMethods?: ShippingMethod[];
|
|
11
|
+
stockTransfers?: StockTransfer[];
|
|
11
12
|
}
|
|
12
13
|
declare const ShipmentChildrenContext: import("react").Context<InitialShipmentContext>;
|
|
13
14
|
export default ShipmentChildrenContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext}from"react";const initial={lineItems:[],shippingMethods:[],stockTransfers:[]
|
|
1
|
+
import{createContext}from"react";const initial={keyNumber:0,lineItems:[],shippingMethods:[],stockTransfers:[]},ShipmentChildrenContext=createContext(initial);export default ShipmentChildrenContext;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
export * from './components/
|
|
2
|
-
export * from './components/
|
|
1
|
+
export * from './components/Errors';
|
|
2
|
+
export * from './components/ExternalFunction';
|
|
3
|
+
export * from './components/MetadataInput';
|
|
4
|
+
export * from './components/SubmitButton';
|
|
3
5
|
export * from './components/addresses/Address';
|
|
6
|
+
export * from './components/addresses/AddressCountrySelector';
|
|
4
7
|
export * from './components/addresses/AddressField';
|
|
5
8
|
export * from './components/addresses/AddressInput';
|
|
6
9
|
export * from './components/addresses/AddressStateSelector';
|
|
7
10
|
export * from './components/addresses/AddressesContainer';
|
|
11
|
+
export * from './components/addresses/AddressesEmpty';
|
|
8
12
|
export * from './components/addresses/BillingAddressContainer';
|
|
9
13
|
export * from './components/addresses/BillingAddressForm';
|
|
10
|
-
export * from './components/
|
|
11
|
-
export * from './components/
|
|
12
|
-
export * from './components/
|
|
13
|
-
export * from './components/orders/CartLink';
|
|
14
|
-
export * from './components/orders/CheckoutLink';
|
|
14
|
+
export * from './components/addresses/SaveAddressesButton';
|
|
15
|
+
export * from './components/addresses/ShippingAddressContainer';
|
|
16
|
+
export * from './components/addresses/ShippingAddressForm';
|
|
15
17
|
export * from './components/auth/CommerceLayer';
|
|
18
|
+
export * from './components/customers/CustomerAddressForm';
|
|
16
19
|
export * from './components/customers/CustomerContainer';
|
|
17
20
|
export * from './components/customers/CustomerField';
|
|
18
|
-
export * from './components/customers/CustomerAddressForm';
|
|
19
21
|
export * from './components/customers/CustomerInput';
|
|
20
|
-
export * from './components/
|
|
21
|
-
export * from './components/orders/DiscountAmount';
|
|
22
|
-
export * from './components/Errors';
|
|
23
|
-
export * from './components/ExternalFunction';
|
|
22
|
+
export * from './components/customers/SaveCustomerButton';
|
|
24
23
|
export * from './components/gift_cards/GiftCard';
|
|
25
|
-
export * from './components/orders/GiftCardAmount';
|
|
26
24
|
export * from './components/gift_cards/GiftCardContainer';
|
|
27
25
|
export * from './components/gift_cards/GiftCardCurrencySelector';
|
|
28
26
|
export * from './components/gift_cards/GiftCardInput';
|
|
@@ -31,7 +29,6 @@ export * from './components/gift_cards/GiftCardOrCouponForm';
|
|
|
31
29
|
export * from './components/gift_cards/GiftCardOrCouponInput';
|
|
32
30
|
export * from './components/gift_cards/GiftCardOrCouponRemoveButton';
|
|
33
31
|
export * from './components/gift_cards/GiftCardOrCouponSubmit';
|
|
34
|
-
export * from './components/orders/ItemContainer';
|
|
35
32
|
export * from './components/line_items/LineItem';
|
|
36
33
|
export * from './components/line_items/LineItemAmount';
|
|
37
34
|
export * from './components/line_items/LineItemCode';
|
|
@@ -44,12 +41,26 @@ export * from './components/line_items/LineItemRemoveLink';
|
|
|
44
41
|
export * from './components/line_items/LineItemsContainer';
|
|
45
42
|
export * from './components/line_items/LineItemsCount';
|
|
46
43
|
export * from './components/line_items/LineItemsEmpty';
|
|
47
|
-
export * from './components/
|
|
44
|
+
export * from './components/orders/AddToCartButton';
|
|
45
|
+
export * from './components/orders/AdjustmentAmount';
|
|
46
|
+
export * from './components/orders/CartLink';
|
|
47
|
+
export * from './components/orders/CheckoutLink';
|
|
48
|
+
export * from './components/orders/DiscountAmount';
|
|
49
|
+
export * from './components/orders/GiftCardAmount';
|
|
50
|
+
export * from './components/orders/ItemContainer';
|
|
48
51
|
export * from './components/orders/OrderContainer';
|
|
49
|
-
export * from './components/orders/OrderNumber';
|
|
50
|
-
export * from './components/orders/OrderStorage';
|
|
51
52
|
export * from './components/orders/OrderList';
|
|
53
|
+
export * from './components/orders/OrderListEmpty';
|
|
52
54
|
export * from './components/orders/OrderListRow';
|
|
55
|
+
export * from './components/orders/OrderNumber';
|
|
56
|
+
export * from './components/orders/OrderStorage';
|
|
57
|
+
export * from './components/orders/PlaceOrderButton';
|
|
58
|
+
export * from './components/orders/PlaceOrderContainer';
|
|
59
|
+
export * from './components/orders/PrivacyAndTermsCheckbox';
|
|
60
|
+
export * from './components/orders/ShippingAmount';
|
|
61
|
+
export * from './components/orders/SubTotalAmount';
|
|
62
|
+
export * from './components/orders/TaxesAmount';
|
|
63
|
+
export * from './components/orders/TotalAmount';
|
|
53
64
|
export * from './components/payment_methods/PaymentMethod';
|
|
54
65
|
export * from './components/payment_methods/PaymentMethodAmount';
|
|
55
66
|
export * from './components/payment_methods/PaymentMethodName';
|
|
@@ -61,24 +72,19 @@ export * from './components/payment_source/PaymentSourceBrandIcon';
|
|
|
61
72
|
export * from './components/payment_source/PaymentSourceBrandName';
|
|
62
73
|
export * from './components/payment_source/PaymentSourceDetail';
|
|
63
74
|
export * from './components/payment_source/PaymentSourceEditButton';
|
|
64
|
-
export * from './components/orders/PlaceOrderButton';
|
|
65
|
-
export * from './components/orders/PlaceOrderContainer';
|
|
66
75
|
export * from './components/prices/Price';
|
|
67
76
|
export * from './components/prices/PricesContainer';
|
|
68
|
-
export * from './components/orders/PrivacyAndTermsCheckbox';
|
|
69
|
-
export * from './components/skus/QuantitySelector';
|
|
70
|
-
export * from './components/addresses/SaveAddressesButton';
|
|
71
|
-
export * from './components/customers/SaveCustomerButton';
|
|
72
77
|
export * from './components/shipments/Shipment';
|
|
73
78
|
export * from './components/shipments/ShipmentField';
|
|
74
79
|
export * from './components/shipments/ShipmentsContainer';
|
|
75
|
-
export * from './components/addresses/ShippingAddressContainer';
|
|
76
|
-
export * from './components/addresses/ShippingAddressForm';
|
|
77
|
-
export * from './components/orders/ShippingAmount';
|
|
78
80
|
export * from './components/shipping_methods/ShippingMethod';
|
|
79
81
|
export * from './components/shipping_methods/ShippingMethodName';
|
|
80
82
|
export * from './components/shipping_methods/ShippingMethodPrice';
|
|
81
83
|
export * from './components/shipping_methods/ShippingMethodRadioButton';
|
|
84
|
+
export * from './components/skus/AvailabilityContainer';
|
|
85
|
+
export * from './components/skus/AvailabilityTemplate';
|
|
86
|
+
export * from './components/skus/DeliveryLeadTime';
|
|
87
|
+
export * from './components/skus/QuantitySelector';
|
|
82
88
|
export * from './components/skus/SkuField';
|
|
83
89
|
export * from './components/skus/SkuList';
|
|
84
90
|
export * from './components/skus/SkuListsContainer';
|
|
@@ -87,21 +93,17 @@ export * from './components/skus/SkuOptionInput';
|
|
|
87
93
|
export * from './components/skus/SkuOptionsContainer';
|
|
88
94
|
export * from './components/skus/Skus';
|
|
89
95
|
export * from './components/skus/SkusContainer';
|
|
90
|
-
export * from './components/stock_transfers/StockTransfer';
|
|
91
|
-
export * from './components/stock_transfers/StockTransferField';
|
|
92
|
-
export * from './components/orders/SubTotalAmount';
|
|
93
|
-
export * from './components/SubmitButton';
|
|
94
|
-
export * from './components/orders/TaxesAmount';
|
|
95
|
-
export * from './components/orders/TotalAmount';
|
|
96
96
|
export * from './components/skus/VariantSelector';
|
|
97
97
|
export * from './components/skus/VariantsContainer';
|
|
98
|
+
export * from './components/stock_transfers/StockTransfer';
|
|
99
|
+
export * from './components/stock_transfers/StockTransferField';
|
|
98
100
|
export type { CustomerCardsType } from './components/utils/PaymentCardsTemplate';
|
|
99
101
|
export type { AddressCardsType } from './components/utils/AddressCardsTemplate';
|
|
100
102
|
export type { AddToCartButtonType } from './components/orders/AddToCartButton';
|
|
101
|
-
export type { ShippingMethodRadioButtonType, ShippingMethodRadioButtonOnChangeType
|
|
103
|
+
export type { ShippingMethodRadioButtonType, ShippingMethodRadioButtonOnChangeType } from './components/shipping_methods/ShippingMethodRadioButton';
|
|
102
104
|
export type { LineItemCodeType } from './components/line_items/LineItemCode';
|
|
103
105
|
export type { LineItemNameType } from './components/line_items/LineItemName';
|
|
104
106
|
export type { LineItemImageType } from './components/line_items/LineItemImage';
|
|
105
107
|
export type { LineItemType } from './typings/index';
|
|
106
108
|
export type { ErrorComponentProps, ResourceErrorType } from './typings/errors';
|
|
107
|
-
export type { AddressCountrySelectName, AddressInputName, AddressStateSelectName, BaseInputType
|
|
109
|
+
export type { AddressCountrySelectName, AddressInputName, AddressStateSelectName, BaseInputType } from './typings/index';
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./components/
|
|
1
|
+
export*from"./components/Errors";export*from"./components/ExternalFunction";export*from"./components/MetadataInput";export*from"./components/SubmitButton";export*from"./components/addresses/Address";export*from"./components/addresses/AddressCountrySelector";export*from"./components/addresses/AddressField";export*from"./components/addresses/AddressInput";export*from"./components/addresses/AddressStateSelector";export*from"./components/addresses/AddressesContainer";export*from"./components/addresses/AddressesEmpty";export*from"./components/addresses/BillingAddressContainer";export*from"./components/addresses/BillingAddressForm";export*from"./components/addresses/SaveAddressesButton";export*from"./components/addresses/ShippingAddressContainer";export*from"./components/addresses/ShippingAddressForm";export*from"./components/auth/CommerceLayer";export*from"./components/customers/CustomerAddressForm";export*from"./components/customers/CustomerContainer";export*from"./components/customers/CustomerField";export*from"./components/customers/CustomerInput";export*from"./components/customers/SaveCustomerButton";export*from"./components/gift_cards/GiftCard";export*from"./components/gift_cards/GiftCardContainer";export*from"./components/gift_cards/GiftCardCurrencySelector";export*from"./components/gift_cards/GiftCardInput";export*from"./components/gift_cards/GiftCardOrCouponCode";export*from"./components/gift_cards/GiftCardOrCouponForm";export*from"./components/gift_cards/GiftCardOrCouponInput";export*from"./components/gift_cards/GiftCardOrCouponRemoveButton";export*from"./components/gift_cards/GiftCardOrCouponSubmit";export*from"./components/line_items/LineItem";export*from"./components/line_items/LineItemAmount";export*from"./components/line_items/LineItemCode";export*from"./components/line_items/LineItemImage";export*from"./components/line_items/LineItemName";export*from"./components/line_items/LineItemOption";export*from"./components/line_items/LineItemOptions";export*from"./components/line_items/LineItemQuantity";export*from"./components/line_items/LineItemRemoveLink";export*from"./components/line_items/LineItemsContainer";export*from"./components/line_items/LineItemsCount";export*from"./components/line_items/LineItemsEmpty";export*from"./components/orders/AddToCartButton";export*from"./components/orders/AdjustmentAmount";export*from"./components/orders/CartLink";export*from"./components/orders/CheckoutLink";export*from"./components/orders/DiscountAmount";export*from"./components/orders/GiftCardAmount";export*from"./components/orders/ItemContainer";export*from"./components/orders/OrderContainer";export*from"./components/orders/OrderList";export*from"./components/orders/OrderListEmpty";export*from"./components/orders/OrderListRow";export*from"./components/orders/OrderNumber";export*from"./components/orders/OrderStorage";export*from"./components/orders/PlaceOrderButton";export*from"./components/orders/PlaceOrderContainer";export*from"./components/orders/PrivacyAndTermsCheckbox";export*from"./components/orders/ShippingAmount";export*from"./components/orders/SubTotalAmount";export*from"./components/orders/TaxesAmount";export*from"./components/orders/TotalAmount";export*from"./components/payment_methods/PaymentMethod";export*from"./components/payment_methods/PaymentMethodAmount";export*from"./components/payment_methods/PaymentMethodName";export*from"./components/payment_methods/PaymentMethodPrice";export*from"./components/payment_methods/PaymentMethodRadioButton";export*from"./components/payment_methods/PaymentMethodsContainer";export*from"./components/payment_source/PaymentSource";export*from"./components/payment_source/PaymentSourceBrandIcon";export*from"./components/payment_source/PaymentSourceBrandName";export*from"./components/payment_source/PaymentSourceDetail";export*from"./components/payment_source/PaymentSourceEditButton";export*from"./components/prices/Price";export*from"./components/prices/PricesContainer";export*from"./components/shipments/Shipment";export*from"./components/shipments/ShipmentField";export*from"./components/shipments/ShipmentsContainer";export*from"./components/shipping_methods/ShippingMethod";export*from"./components/shipping_methods/ShippingMethodName";export*from"./components/shipping_methods/ShippingMethodPrice";export*from"./components/shipping_methods/ShippingMethodRadioButton";export*from"./components/skus/AvailabilityContainer";export*from"./components/skus/AvailabilityTemplate";export*from"./components/skus/DeliveryLeadTime";export*from"./components/skus/QuantitySelector";export*from"./components/skus/SkuField";export*from"./components/skus/SkuList";export*from"./components/skus/SkuListsContainer";export*from"./components/skus/SkuOption";export*from"./components/skus/SkuOptionInput";export*from"./components/skus/SkuOptionsContainer";export*from"./components/skus/Skus";export*from"./components/skus/SkusContainer";export*from"./components/skus/VariantSelector";export*from"./components/skus/VariantsContainer";export*from"./components/stock_transfers/StockTransfer";export*from"./components/stock_transfers/StockTransferField";
|
|
@@ -25,33 +25,27 @@ export interface AddressAction {
|
|
|
25
25
|
payload: Partial<AddressActionPayload>;
|
|
26
26
|
}
|
|
27
27
|
export declare const addressInitialState: AddressState;
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
export declare type SetAddressParams<V extends AddressSchema> = {
|
|
28
|
+
export declare type SetAddressErrors = <V extends BaseError[]>(args: {
|
|
29
|
+
errors: V;
|
|
30
|
+
resource: Extract<ResourceErrorType, 'billing_address' | 'shipping_address'>;
|
|
31
|
+
dispatch?: Dispatch<AddressAction>;
|
|
32
|
+
currentErrors?: V;
|
|
33
|
+
}) => void;
|
|
34
|
+
export interface SetAddressParams<V extends AddressSchema> {
|
|
37
35
|
values: V;
|
|
38
36
|
resource: AddressResource;
|
|
39
37
|
dispatch?: Dispatch<AddressAction>;
|
|
40
|
-
};
|
|
41
|
-
export interface SetAddress {
|
|
42
|
-
<V extends AddressSchema>(params: SetAddressParams<V>): void;
|
|
43
|
-
}
|
|
44
|
-
export interface SaveAddresses {
|
|
45
|
-
(params: {
|
|
46
|
-
orderId?: string;
|
|
47
|
-
order?: Order | null;
|
|
48
|
-
updateOrder?: typeof updateOrder;
|
|
49
|
-
config: CommerceLayerConfig;
|
|
50
|
-
state: AddressState;
|
|
51
|
-
dispatch: Dispatch<AddressAction>;
|
|
52
|
-
getCustomerAddresses?: () => Promise<void>;
|
|
53
|
-
}): Promise<void>;
|
|
54
38
|
}
|
|
39
|
+
export declare type SetAddress = <V extends AddressSchema>(params: SetAddressParams<V>) => void;
|
|
40
|
+
export declare type SaveAddresses = (params: {
|
|
41
|
+
orderId?: string;
|
|
42
|
+
order?: Order | null;
|
|
43
|
+
updateOrder?: typeof updateOrder;
|
|
44
|
+
config: CommerceLayerConfig;
|
|
45
|
+
state: AddressState;
|
|
46
|
+
dispatch: Dispatch<AddressAction>;
|
|
47
|
+
getCustomerAddresses?: () => Promise<void>;
|
|
48
|
+
}) => Promise<void>;
|
|
55
49
|
export declare const setAddressErrors: SetAddressErrors;
|
|
56
50
|
export declare const setAddress: SetAddress;
|
|
57
51
|
declare type SetCloneAddress = (id: string, resource: AddressResource, dispatch: Dispatch<AddressAction>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";export const addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],addressInitialState={errors:[]},setAddressErrors=({errors,dispatch,currentErrors=[],resource})=>{const billingErrors=resource==="billing_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="billing_address"),shippingErrors=resource==="shipping_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="shipping_address"),finalErrors=[...billingErrors,...shippingErrors];dispatch&&dispatch({type:"setErrors",payload:{errors:finalErrors}})},setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})},setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${camelCase(resource)}Id`]:id}})},saveAddresses=async({config,updateOrder,order,state})=>{const{shipToDifferentAddress,billing_address,shipping_address,billingAddressId,shippingAddressId}=state;try{const sdk=getSdk(config);if(order){const currentBillingAddressRef=order?.billing_address?.reference,orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=order?.billing_address?.id,orderAttributes._shipping_address_clone_id=order?.shipping_address?.id),!isEmpty(
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import getSdk from"../utils/getSdk";import camelCase from"lodash/camelCase";export const addressFields=["city","company","country_code","first_name","last_name","line_1","line_2","phone","state_code","zip_code"],addressInitialState={errors:[]},setAddressErrors=({errors,dispatch,currentErrors=[],resource})=>{const billingErrors=resource==="billing_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="billing_address"),shippingErrors=resource==="shipping_address"?errors.filter(e=>e.resource===resource):currentErrors.filter(e=>e.resource==="shipping_address"),finalErrors=[...billingErrors,...shippingErrors];dispatch&&dispatch({type:"setErrors",payload:{errors:finalErrors}})},setAddress=({values,resource,dispatch})=>{dispatch&&dispatch({type:"setAddress",payload:{[`${resource}`]:values}})},setCloneAddress=(id,resource,dispatch)=>{dispatch({type:"setCloneAddress",payload:{[`${camelCase(resource)}Id`]:id}})},saveAddresses=async({config,updateOrder,order,state})=>{const{shipToDifferentAddress,billing_address:billingAddress,shipping_address:shippingAddress,billingAddressId,shippingAddressId}=state;try{const sdk=getSdk(config);if(order){const currentBillingAddressRef=order?.billing_address?.reference,orderAttributes={id:order?.id,_billing_address_clone_id:billingAddressId,_shipping_address_clone_id:billingAddressId};if(currentBillingAddressRef===billingAddressId&&(orderAttributes._billing_address_clone_id=order?.billing_address?.id,orderAttributes._shipping_address_clone_id=order?.shipping_address?.id),!isEmpty(billingAddress)&&billingAddress){delete orderAttributes._billing_address_clone_id,delete orderAttributes._shipping_address_clone_id,orderAttributes._shipping_address_same_as_billing=!0;const address=await sdk.addresses.create(billingAddress);orderAttributes.billing_address=sdk.addresses.relationship(address.id)}if(shipToDifferentAddress&&(delete orderAttributes._shipping_address_same_as_billing,shippingAddressId&&(orderAttributes._shipping_address_clone_id=shippingAddressId),!isEmpty(shippingAddress)&&shippingAddress)){delete orderAttributes._shipping_address_clone_id;const address=await sdk.addresses.create(shippingAddress);orderAttributes.shipping_address=sdk.addresses.relationship(address.id)}!isEmpty(orderAttributes)&&updateOrder&&await updateOrder({id:order.id,attributes:orderAttributes})}}catch(error){console.error(error)}};const type=["setErrors","setAddress","setShipToDifferentAddress","setCloneAddress","cleanup"],addressReducer=(state,reducer)=>baseReducer(state,reducer,type);export default addressReducer;
|
|
@@ -4,15 +4,15 @@ 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
|
|
8
|
-
addresses: Address[];
|
|
7
|
+
export interface CustomerActionPayload {
|
|
8
|
+
addresses: Address[] | null;
|
|
9
9
|
payments: CustomerPaymentSource[];
|
|
10
10
|
customerEmail: string;
|
|
11
11
|
errors: BaseError[];
|
|
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
|
-
addresses?: Address[];
|
|
85
|
-
}
|
|
86
|
-
export declare function deleteCustomerAddress({ config, dispatch, customerAddressId, addresses
|
|
87
|
-
export
|
|
82
|
+
addresses?: Address[] | null;
|
|
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
|
-
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";import jwtDecode from"../utils/jwt";export async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}export function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}export function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}export async function getCustomerAddresses({config,dispatch}){try{const addresses=[];(await getSdk(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=getErrors(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}}export async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await getSdk(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")}}export 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}})}}export const getCustomerOrders=async({config,dispatch})=>{if(config.accessToken){const{owner}=jwtDecode(config.accessToken);if(owner?.id){const customers=await getSdk(config).customers.retrieve(owner.id,{include:["orders"]}),orders=customers.orders?.filter(order=>order.status!=="pending"&&order.status!=="draft");dispatch({type:"setOrders",payload:{orders,customers}})}}};export async function createCustomerAddress({address,config,dispatch,state}){if(config&&address){const sdk=getSdk(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")}}}export const customerInitialState={errors:[],addresses:
|
|
1
|
+
import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";import jwtDecode from"../utils/jwt";export async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}export function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}export function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}export async function getCustomerAddresses({config,dispatch}){try{const addresses=[];(await getSdk(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=getErrors(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}}export async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await getSdk(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")}}export 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}})}}export const getCustomerOrders=async({config,dispatch})=>{if(config.accessToken){const{owner}=jwtDecode(config.accessToken);if(owner?.id){const customers=await getSdk(config).customers.retrieve(owner.id,{include:["orders"]}),orders=customers.orders?.filter(order=>order.status!=="pending"&&order.status!=="draft");dispatch({type:"setOrders",payload:{orders,customers}})}}};export async function createCustomerAddress({address,config,dispatch,state}){if(config&&address){const sdk=getSdk(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")}}}export const customerInitialState={errors:[],addresses:null,payments:[]};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders"],customerReducer=(state,reducer)=>baseReducer(state,reducer,type);export 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<undefined | 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;
|
|
@@ -69,7 +59,7 @@ export interface OrderPayload {
|
|
|
69
59
|
}
|
|
70
60
|
export declare type AddToCartValues = Pick<AddToCartParams, 'bundleCode' | 'lineItem' | 'quantity' | 'skuCode' | 'skuId' | 'option' | 'buyNowMode' | 'checkoutUrl'>;
|
|
71
61
|
export declare type AddToCartImportValues = Pick<AddToCartImportParams, 'lineItems'>;
|
|
72
|
-
export declare type getOrderContext = (id: string) => Promise<
|
|
62
|
+
export declare type getOrderContext = (id: string) => Promise<undefined | Order>;
|
|
73
63
|
export declare type OrderState = Partial<OrderPayload>;
|
|
74
64
|
export interface OrderActions {
|
|
75
65
|
type: OrderActionType;
|
|
@@ -78,36 +68,33 @@ 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
|
|
90
|
-
success: boolean;
|
|
91
|
-
error?: undefined;
|
|
92
|
-
} | {
|
|
78
|
+
}
|
|
79
|
+
export declare function updateOrder({ id, attributes, dispatch, config, include, state }: UpdateOrderArgs): Promise<{
|
|
93
80
|
success: boolean;
|
|
94
|
-
error
|
|
81
|
+
error?: unknown;
|
|
95
82
|
}>;
|
|
96
83
|
export declare const setOrder: (order: Order, dispatch?: Dispatch<OrderActions>) => void;
|
|
97
|
-
export
|
|
84
|
+
export interface AddResourceToInclude {
|
|
98
85
|
resourcesIncluded?: ResourceIncluded[];
|
|
99
86
|
dispatch?: Dispatch<OrderActions>;
|
|
100
87
|
newResource?: ResourceIncluded | ResourceIncluded[];
|
|
101
88
|
resourceIncludedLoaded?: ResourceIncludedLoaded;
|
|
102
89
|
newResourceLoaded?: ResourceIncludedLoaded;
|
|
103
|
-
}
|
|
104
|
-
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, newResourceLoaded, resourceIncludedLoaded
|
|
90
|
+
}
|
|
91
|
+
export declare function addResourceToInclude({ resourcesIncluded, dispatch, newResource, newResourceLoaded, resourceIncludedLoaded }: AddResourceToInclude): void;
|
|
105
92
|
export declare const addToCart: AddToCart;
|
|
106
93
|
export declare const unsetOrderState: UnsetOrderState;
|
|
107
|
-
|
|
94
|
+
interface OrderErrors {
|
|
108
95
|
dispatch?: Dispatch<OrderActions>;
|
|
109
96
|
errors: BaseError[];
|
|
110
|
-
}
|
|
97
|
+
}
|
|
111
98
|
export declare function setOrderErrors({ dispatch, errors }: OrderErrors): {
|
|
112
99
|
success: boolean;
|
|
113
100
|
};
|