@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,26 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
quantity: number;
|
|
5
5
|
handleChange: (event: React.MouseEvent<HTMLSelectElement>) => void;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
declare type Props = {
|
|
8
|
-
children?:
|
|
8
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
9
|
max?: number;
|
|
10
10
|
disabled?: boolean;
|
|
11
11
|
readonly?: boolean;
|
|
12
12
|
} & (JSX.IntrinsicElements['select'] & JSX.IntrinsicElements['span']);
|
|
13
13
|
export declare function LineItemQuantity(props: Props): JSX.Element;
|
|
14
|
-
export declare namespace LineItemQuantity {
|
|
15
|
-
var propTypes: {
|
|
16
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
17
|
-
max: import("prop-types").Requireable<number>;
|
|
18
|
-
disabled: import("prop-types").Requireable<boolean>;
|
|
19
|
-
readonly: import("prop-types").Requireable<boolean>;
|
|
20
|
-
};
|
|
21
|
-
var defaultProps: {
|
|
22
|
-
max: number;
|
|
23
|
-
};
|
|
24
|
-
var displayName: string;
|
|
25
|
-
}
|
|
26
14
|
export default LineItemQuantity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";export function LineItemQuantity(props){const{max=50,readonly=!1,...p}=props,{lineItem}=useContext(LineItemChildrenContext),{updateLineItem}=useContext(LineItemContext),options=[];for(let i=1;i<=max;i++)options.push(_jsx("option",{value:`${i}`,children:i},i));const handleChange=e=>{const quantity2=Number(e.target.value);updateLineItem&&lineItem&&updateLineItem(lineItem.id,quantity2)},quantity=lineItem?.quantity,parentProps={handleChange,quantity,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):readonly?_jsx("span",{...p,children:quantity}):_jsx("select",{title:lineItem?.name,value:quantity,onChange:handleChange,...p,children:options})}export default LineItemQuantity;
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { PropsWithoutRef } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
handleRemove: (event: React.MouseEvent<HTMLAnchorElement>) => void;
|
|
5
5
|
label?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
children?: ChildrenProps
|
|
6
|
+
}
|
|
7
|
+
interface Props extends PropsWithoutRef<Omit<JSX.IntrinsicElements['a'], 'children'>> {
|
|
8
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
9
|
label?: string;
|
|
10
|
-
} & PropsWithoutRef<JSX.IntrinsicElements['a']>;
|
|
11
|
-
export declare function LineItemRemoveLink(props: Props): JSX.Element;
|
|
12
|
-
export declare namespace LineItemRemoveLink {
|
|
13
|
-
var propTypes: {
|
|
14
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
15
|
-
label: import("prop-types").Requireable<string>;
|
|
16
|
-
};
|
|
17
|
-
var defaultProps: {
|
|
18
|
-
label: string;
|
|
19
|
-
};
|
|
20
|
-
var displayName: string;
|
|
21
10
|
}
|
|
11
|
+
export declare function LineItemRemoveLink(props: Props): JSX.Element;
|
|
22
12
|
export default LineItemRemoveLink;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import LineItemContext from"../../context/LineItemContext";import Parent from"../utils/Parent";export function LineItemRemoveLink(props){const{label="Remove"}=props,{lineItem}=useContext(LineItemChildrenContext),{deleteLineItem}=useContext(LineItemContext),handleRemove=e=>{e.preventDefault(),deleteLineItem&&lineItem&&deleteLineItem(lineItem.id)},parentProps={handleRemove,...props};return props.children?_jsx(Parent,{...parentProps,children:props.children}):_jsx("a",{...props,href:"#",onClick:handleRemove,children:label})}export default LineItemRemoveLink;
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { TypeAccepted } from '../../utils/getLineItemsCount';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
4
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
5
5
|
quantity: number;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
declare type Props = {
|
|
8
|
-
children?:
|
|
8
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
9
|
typeAccepted?: TypeAccepted[];
|
|
10
10
|
} & JSX.IntrinsicElements['span'];
|
|
11
11
|
export declare function LineItemsCount(props: Props): JSX.Element;
|
|
12
|
-
export declare namespace LineItemsCount {
|
|
13
|
-
var propTypes: {
|
|
14
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
15
|
-
id: import("prop-types").Requireable<string>;
|
|
16
|
-
className: import("prop-types").Requireable<string>;
|
|
17
|
-
name: import("prop-types").Requireable<string>;
|
|
18
|
-
style: import("prop-types").Requireable<object>;
|
|
19
|
-
};
|
|
20
|
-
var displayName: string;
|
|
21
|
-
}
|
|
22
12
|
export default LineItemsCount;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";export function LineItemsCount(props){const{children,typeAccepted,...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(0);useEffect(()=>{if(lineItems&&lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[],typeAccepted});setQuantity(qty)}return()=>{setQuantity(0)}},[lineItems,typeAccepted]);const parentProps={quantity,typeAccepted,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:quantity})}export default LineItemsCount;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
quantity: number;
|
|
5
5
|
text: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
children?:
|
|
6
|
+
}
|
|
7
|
+
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
8
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
9
|
text?: string;
|
|
10
|
-
} & JSX.IntrinsicElements['span'];
|
|
11
|
-
export declare function LineItemsEmpty(props: LineItemsCountProps): JSX.Element | null;
|
|
12
|
-
export declare namespace LineItemsEmpty {
|
|
13
|
-
var propTypes: {
|
|
14
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
15
|
-
id: import("prop-types").Requireable<string>;
|
|
16
|
-
className: import("prop-types").Requireable<string>;
|
|
17
|
-
name: import("prop-types").Requireable<string>;
|
|
18
|
-
style: import("prop-types").Requireable<object>;
|
|
19
|
-
text: import("prop-types").Requireable<string>;
|
|
20
|
-
};
|
|
21
|
-
var displayName: string;
|
|
22
10
|
}
|
|
11
|
+
export declare function LineItemsEmpty(props: Props): JSX.Element | null;
|
|
23
12
|
export default LineItemsEmpty;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import Parent from"../utils/Parent";import getLineItemsCount from"../../utils/getLineItemsCount";import LineItemContext from"../../context/LineItemContext";export function LineItemsEmpty(props){const{children,text="Your shopping bag is empty",...p}=props,{lineItems}=useContext(LineItemContext),[quantity,setQuantity]=useState(),emptyText=quantity===0?_jsx("span",{...p,children:text}):null;useEffect(()=>{if(lineItems)if(lineItems.length>0){const qty=getLineItemsCount({lineItems:lineItems||[]});setQuantity(qty)}else setQuantity(0);return()=>{setQuantity(void 0)}},[lineItems]);const parentProps={quantity,text,...p};return children?_jsx(Parent,{...parentProps,children}):emptyText}export default LineItemsEmpty;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { PropsWithoutRef } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
3
|
import { AddToCartReturn } from '../../reducers/OrderReducer';
|
|
4
4
|
import { VariantOption } from '../skus/VariantSelector';
|
|
5
|
-
|
|
5
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
6
6
|
handleClick: () => AddToCartReturn;
|
|
7
|
-
}
|
|
8
|
-
declare type AddToCartButtonChildrenProps = FunctionChildren<ChildrenProps>;
|
|
7
|
+
}
|
|
9
8
|
export declare type AddToCartButtonType = ChildrenProps;
|
|
10
9
|
declare type BuyNowMode = {
|
|
11
10
|
buyNowMode: true;
|
|
@@ -22,7 +21,7 @@ declare type THostedCart = {
|
|
|
22
21
|
hostedCartUrl?: never;
|
|
23
22
|
};
|
|
24
23
|
declare type Props = {
|
|
25
|
-
children?:
|
|
24
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
26
25
|
label?: string | JSX.Element;
|
|
27
26
|
skuCode?: string;
|
|
28
27
|
bundleCode?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import ItemContext from"../../context/ItemContext";import getCurrentItemKey from"../../utils/getCurrentItemKey";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import getCartLink from"../../utils/getCartLink";import CommerceLayerContext from"../../context/CommerceLayerContext";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,...p}=props,{accessToken,endpoint}=useContext(CommerceLayerContext),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),[slug]=endpoint?endpoint.split(".commercelayer"):[""],sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:sku?.code||skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=item[sCode]?.inventory?.quantity,handleClick=async()=>{const qty=quantity[sCode],opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity[skuListId]||1;if(has(skuLists,skuListId)){const lineItems2=skuLists
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderContext from"../../context/OrderContext";import isEmpty from"lodash/isEmpty";import has from"lodash/has";import ItemContext from"../../context/ItemContext";import getCurrentItemKey from"../../utils/getCurrentItemKey";import SkuListsContext from"../../context/SkuListsContext";import ExternalFunctionContext from"../../context/ExternalFunctionContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import getCartLink from"../../utils/getCartLink";import CommerceLayerContext from"../../context/CommerceLayerContext";export function AddToCartButton(props){const{label="Add to cart",children,skuCode,bundleCode,disabled,skuListId,lineItem,buyNowMode=!1,checkoutUrl,redirectToHostedCart,hostedCartUrl,...p}=props,{accessToken,endpoint}=useContext(CommerceLayerContext),{addToCart,orderId,getOrder,setOrderErrors}=useContext(OrderContext),{url,callExternalFunction}=useContext(ExternalFunctionContext),{item,items,quantity,option,prices,lineItems,lineItem:lineItemContext,skuCode:itemSkuCode}=useContext(ItemContext),{skuLists}=useContext(SkuListsContext),{sku}=useContext(SkuChildrenContext),[slug]=endpoint?endpoint.split(".commercelayer"):[""],sCode=!isEmpty(items)&&skuCode?items[skuCode]?.code:sku?.code||skuCode||getCurrentItemKey(item)||itemSkuCode,availabilityQuantity=item[sCode]?.inventory?.quantity,handleClick=async()=>{const qty=quantity[sCode],opt=option[sCode],customLineItem=isEmpty(lineItem||lineItemContext)?lineItems[sCode]:lineItem||lineItemContext;if(!isEmpty(skuLists)&&skuListId&&url){const slQty=quantity[skuListId]||1;if(has(skuLists,skuListId)){const lineItems2=skuLists?.[skuListId]?.map(skuCode2=>({skuCode:skuCode2,quantity:slQty,_update_quantity:1}));return await callExternalFunction({url,data:{resourceType:"orders",inputs:[{id:orderId,lineItems:lineItems2}]}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))}}if(!url&&addToCart){const res=await addToCart({bundleCode,skuCode:sCode,skuId:item[sCode]?.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl});if(redirectToHostedCart){const orderId2=res.orderId;hostedCartUrl&&orderId2?location.href=`https://${hostedCartUrl}/${orderId2}?accessToken=${accessToken}`:orderId2&&slug&&(location.href=getCartLink({orderId:orderId2,slug,accessToken}))}return res}else if(url)return await callExternalFunction({url,data:{bundleCode,skuCode:sCode,skuId:item[sCode]?.id,quantity:qty,option:opt,lineItem:customLineItem,buyNowMode,checkoutUrl}}).then(async res=>(getOrder&&orderId&&await getOrder(orderId),res)).catch(({response})=>(setOrderErrors&&setOrderErrors(response.data),response))},autoDisabled=!isEmpty(skuLists)||skuListId?!1:disabled||!prices[sCode]||!sCode||availabilityQuantity===0,parentProps={handleClick,disabled:disabled||autoDisabled,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{...p,disabled:autoDisabled,onClick:()=>{handleClick()},children:label})}export default AddToCartButton;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { MouseEvent, ReactNode } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
href: string;
|
|
5
5
|
handleClick?: (e: MouseEvent<HTMLAnchorElement>) => Promise<void>;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
children?:
|
|
6
|
+
}
|
|
7
|
+
interface Props extends Omit<JSX.IntrinsicElements['a'], 'children'> {
|
|
8
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
9
|
label?: string | ReactNode;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
11
|
export declare function CartLink(props: Props): JSX.Element | null;
|
|
12
12
|
export default CartLink;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import getCartLink from"../../utils/getCartLink";export function CartLink(props){const{label,children,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=slug&&order?.id?getCartLink({slug,orderId:order?.id,accessToken}):"",handleClick=async event=>{if(event.preventDefault(),order?.id)location.href=href;else{const orderId=await createOrder();slug&&(location.href=getCartLink({slug,orderId,accessToken}))}},parentProps={handleClick,label,href,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,onClick:handleClick,children:label}):null}export default CartLink;
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";import getCartLink from"../../utils/getCartLink";export function CartLink(props){const{label,children,...p}=props,{order,createOrder}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=slug&&order?.id?getCartLink({slug,orderId:order?.id,accessToken}):"",handleClick=async event=>{if(event.preventDefault(),order?.id)location.href=href;else{const orderId=await createOrder();slug&&(location.href=getCartLink({slug,orderId,accessToken}))}},parentProps={handleClick,label,href,...p};return accessToken?children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,onClick:e=>{handleClick(e)},children:label}):null}export default CartLink;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
checkoutUrl: string;
|
|
5
5
|
href: string;
|
|
6
|
-
}
|
|
6
|
+
}
|
|
7
7
|
declare type Props = {
|
|
8
|
-
children?:
|
|
8
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
9
9
|
label?: string;
|
|
10
10
|
hostedCheckout?: boolean;
|
|
11
11
|
} & JSX.IntrinsicElements['a'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=hostedCheckout?`${slug}.checkout.commercelayer.app/${order
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import OrderContext from"../../context/OrderContext";import Parent from"../utils/Parent";import CommerceLayerContext from"../../context/CommerceLayerContext";export function CheckoutLink(props){const{label,hostedCheckout=!0,children,...p}=props,{order}=useContext(OrderContext),{accessToken,endpoint}=useContext(CommerceLayerContext),[slug]=endpoint.split(".commercelayer"),href=hostedCheckout&&slug&&order?.id?`${slug}.checkout.commercelayer.app/${order.id}?accessToken=${accessToken}`:order?.checkout_url,parentProps={checkoutUrl:order?.checkout_url,hostedCheckout,label,href,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("a",{href,...p,children:label})}export default CheckoutLink;
|
|
@@ -1,22 +1,11 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
|
|
2
|
+
interface Props {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
skuCode?: string | null;
|
|
5
5
|
lineItem?: {
|
|
6
6
|
name: string;
|
|
7
7
|
imageUrl?: string | null;
|
|
8
8
|
} | null;
|
|
9
|
-
};
|
|
10
|
-
export declare function ItemContainer(props: Props): JSX.Element;
|
|
11
|
-
export declare namespace ItemContainer {
|
|
12
|
-
var propTypes: {
|
|
13
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
14
|
-
skuCode: import("prop-types").Requireable<string>;
|
|
15
|
-
lineItem: import("prop-types").Requireable<import("prop-types").InferProps<{
|
|
16
|
-
name: import("prop-types").Validator<string>;
|
|
17
|
-
imageUrl: import("prop-types").Requireable<string>;
|
|
18
|
-
}>>;
|
|
19
|
-
};
|
|
20
|
-
var displayName: string;
|
|
21
9
|
}
|
|
10
|
+
export declare function ItemContainer(props: Props): JSX.Element;
|
|
22
11
|
export default ItemContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useEffect}from"react";import ItemContext,{initialItemContext}from"../../context/ItemContext";import itemReducer,{itemInitialState,setItemState}from"../../reducers/ItemReducer";
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useReducer,useEffect}from"react";import ItemContext,{initialItemContext}from"../../context/ItemContext";import itemReducer,{itemInitialState,setItemState}from"../../reducers/ItemReducer";export function ItemContainer(props){const{children,skuCode,lineItem}=props,[state,dispatch]=useReducer(itemReducer,itemInitialState);useEffect(()=>{const code=skuCode;code&&setItemState(code,{type:"setSkuCode",key:"skuCode"},dispatch),lineItem&&setItemState(lineItem,{type:"setCustomLineItem",key:"lineItem"},dispatch)},[]);const itemValue={...initialItemContext,...state,setItems:items=>setItemState(items,{type:"setItems",key:"items"},dispatch),setItem:item=>setItemState(item,{type:"setItem",key:"item"},dispatch),setQuantity:item=>setItemState(item,{type:"setQuantity",key:"quantity"},dispatch),setOption:item=>setItemState(item,{type:"setOption",key:"option"},dispatch),setPrices:item=>setItemState(item,{type:"setPrices",key:"prices"},dispatch),setCustomLineItems:item=>setItemState(item,{type:"setCustomLineItems",key:"lineItems"},dispatch),setSkuCode:code=>setItemState(code,{type:"setSkuCode",key:"skuCode"},dispatch)};return _jsx(ItemContext.Provider,{value:itemValue,children})}export default ItemContainer;
|
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { BaseMetadataObject } from '../../typings/index';
|
|
3
3
|
import type { OrderCreate, Order } from '@commercelayer/sdk';
|
|
4
|
-
|
|
5
|
-
children:
|
|
4
|
+
interface Props {
|
|
5
|
+
children: JSX.Element[] | JSX.Element;
|
|
6
6
|
metadata?: BaseMetadataObject;
|
|
7
7
|
attributes?: OrderCreate;
|
|
8
8
|
orderId?: string;
|
|
9
9
|
fetchOrder?: (order: Order) => void;
|
|
10
|
-
};
|
|
11
|
-
export declare function OrderContainer(props: Props): JSX.Element;
|
|
12
|
-
export declare namespace OrderContainer {
|
|
13
|
-
var propTypes: {
|
|
14
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
15
|
-
orderId: import("prop-types").Requireable<string>;
|
|
16
|
-
metadata: import("prop-types").Requireable<{
|
|
17
|
-
[x: string]: string | null | undefined;
|
|
18
|
-
}>;
|
|
19
|
-
attributes: import("prop-types").Requireable<object>;
|
|
20
|
-
};
|
|
21
|
-
var defaultProps: {
|
|
22
|
-
metadata: {};
|
|
23
|
-
};
|
|
24
|
-
var displayName: string;
|
|
25
10
|
}
|
|
11
|
+
export declare function OrderContainer(props: Props): JSX.Element;
|
|
26
12
|
export default OrderContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useReducer,useContext,useMemo,useState}from"react";import orderReducer,{createOrder,getApiOrder,setOrderErrors,setOrder,orderInitialState,updateOrder}from"../../reducers/OrderReducer";import CommerceLayerContext from"../../context/CommerceLayerContext";import OrderContext,{defaultOrderContext}from"../../context/OrderContext";import OrderStorageContext from"../../context/OrderStorageContext";import compareObjAttribute from"../../utils/compareObjAttribute";export function OrderContainer(props){const{orderId,children,metadata,attributes,fetchOrder}=props,[state,dispatch]=useReducer(orderReducer,orderInitialState),[lock,setLock]=useState(!1),[lockOrder,setLockOrder]=useState(!0),config=useContext(CommerceLayerContext),{persistKey,clearWhenPlaced,getLocalOrder,setLocalOrder,deleteLocalOrder}=useContext(OrderStorageContext);useEffect(()=>{state.withoutIncludes||dispatch({type:"setLoading",payload:{loading:!0}})},[state.withoutIncludes]),useEffect(()=>{if(attributes&&state?.order&&!lock){const updateAttributes=compareObjAttribute({attributes,object:state.order});Object.keys(updateAttributes).length>0&&(updateOrder({id:state.order.id,attributes:updateAttributes,dispatch,config,include:state.include,state}),setLock(!0))}return()=>{if(attributes&&state?.order){const updateAttributes=compareObjAttribute({attributes,object:state.order});state.order&&Object.keys(updateAttributes).length===0&&setLock(!1)}}},[attributes,state?.order,lock]),useEffect(()=>{const localOrder=persistKey?getLocalOrder(persistKey):orderId,startRequest=Object.keys(state?.includeLoaded||{}).filter(key=>state?.includeLoaded?.[key]===!0),getOrder=async()=>{localOrder&&await getApiOrder({id:localOrder,dispatch,config,persistKey,clearWhenPlaced:!!(persistKey&&clearWhenPlaced),deleteLocalOrder,state})};return config.accessToken&&!state.loading?localOrder&&!state.order&&state.include?.length===startRequest.length&&!state.withoutIncludes&&!lockOrder?getOrder():state?.order&&fetchOrder?fetchOrder(state.order):state.withoutIncludes&&!state.include?.length&&startRequest.length===0&&getOrder():[config.accessToken,!state.order,state.loading,state.withoutIncludes].every(Boolean)?dispatch({type:"setLoading",payload:{loading:!1}}):[config.accessToken,!state.order,state.loading,!state.withoutIncludes].every(Boolean)&&dispatch({type:"setLoading",payload:{loading:!1}}),()=>{!state.order&&state.loading&&!state.withoutIncludes&&(state.include?.length===0&&startRequest.length>0?dispatch({type:"setLoading",payload:{loading:!1}}):state.include&&state.include?.length>0&&(dispatch({type:"setIncludesResource",payload:{include:[]}}),setLockOrder(!1)))}},[config.accessToken,state.includeLoaded,state.include,orderId,state.order,state.loading,state.withoutIncludes,lockOrder]);const orderValue=useMemo(()=>({...state,setOrder:order=>setOrder(order,dispatch),getOrder:async id=>await getApiOrder({id,dispatch,config,state}),setOrderErrors:errors=>setOrderErrors({dispatch,errors}),createOrder:async()=>await createOrder({persistKey,dispatch,config,state,orderMetadata:metadata,orderAttributes:attributes,setLocalOrder}),addToCart:async values=>await defaultOrderContext.addToCart({...values,persistKey,dispatch,state,config,errors:state.errors,orderMetadata:metadata||{},orderAttributes:attributes,setLocalOrder}),saveAddressToCustomerAddressBook:args=>defaultOrderContext.saveAddressToCustomerAddressBook({...args,dispatch}),setGiftCardOrCouponCode:async({code,codeType})=>await defaultOrderContext.setGiftCardOrCouponCode({code,codeType,dispatch,order:state.order,config,include:state.include,state}),removeGiftCardOrCouponCode:async({codeType})=>await defaultOrderContext.removeGiftCardOrCouponCode({codeType,dispatch,order:state.order,config,include:state.include,state}),addResourceToInclude:args=>defaultOrderContext.addResourceToInclude({...args,dispatch,resourcesIncluded:state.include,resourceIncludedLoaded:state.includeLoaded}),updateOrder:async args=>await defaultOrderContext.updateOrder({...args,dispatch,config,include:state.include,state})}),[state,config.accessToken]);return _jsx(OrderContext.Provider,{value:orderValue,children})}export default OrderContainer;
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { InitialOrderListContext } from '../../context/OrderListChildrenContext';
|
|
3
3
|
import { Column } from 'react-table';
|
|
4
|
+
import type { Order } from '@commercelayer/sdk';
|
|
5
|
+
export declare type OrderListColumn = Column & {
|
|
6
|
+
Header: string;
|
|
7
|
+
accessor: keyof Order;
|
|
8
|
+
className?: string;
|
|
9
|
+
titleClassName?: string;
|
|
10
|
+
};
|
|
4
11
|
declare type Props = {
|
|
5
|
-
children:
|
|
12
|
+
children: JSX.Element[] | JSX.Element;
|
|
6
13
|
/**
|
|
7
14
|
* Columns to show
|
|
8
15
|
*/
|
|
9
|
-
columns:
|
|
10
|
-
className?: string;
|
|
11
|
-
})[];
|
|
16
|
+
columns: OrderListColumn[];
|
|
12
17
|
/**
|
|
13
18
|
* Custom loader component
|
|
14
19
|
*/
|
|
15
|
-
loadingElement?:
|
|
20
|
+
loadingElement?: string | JSX.Element;
|
|
16
21
|
/**
|
|
17
22
|
* Function to assign as custom row renderer
|
|
18
23
|
*/
|
|
@@ -52,10 +57,4 @@ declare type Props = {
|
|
|
52
57
|
windowOptions?: never;
|
|
53
58
|
});
|
|
54
59
|
export declare function OrderList({ children, columns, loadingElement, showActions, actionsComponent, actionsContainerClassName, infiniteScroll, windowOptions, theadClassName, rowTrClassName, ...p }: Props): JSX.Element;
|
|
55
|
-
export declare namespace OrderList {
|
|
56
|
-
var propTypes: {
|
|
57
|
-
children: import("prop-types").Validator<NonNullable<ReactNode | (() => JSX.Element)>>;
|
|
58
|
-
};
|
|
59
|
-
var displayName: string;
|
|
60
|
-
}
|
|
61
60
|
export default OrderList;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as _createElement}from"react";import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useMemo,useState,useEffect,useCallback}from"react";import
|
|
1
|
+
import{createElement as _createElement}from"react";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useMemo,useState,useEffect,useCallback}from"react";import CustomerContext from"../../context/CustomerContext";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import{useTable,useSortBy,useBlockLayout}from"react-table";import{FixedSizeList}from"react-window";import scrollbarWidth from"../../utils/scrollbarWidth";import{sortDescIcon,sortAscIcon}from"../../utils/icons";export function OrderList({children,columns,loadingElement,showActions=!1,actionsComponent,actionsContainerClassName,infiniteScroll,windowOptions,theadClassName,rowTrClassName,...p}){const[loading,setLoading]=useState(!0),{orders}=useContext(CustomerContext),data=useMemo(()=>orders??[],[orders]),cols=useMemo(()=>columns,[columns]),tablePlugins=[useSortBy];infiniteScroll&&tablePlugins.push(useBlockLayout);const defaultColumn=useMemo(()=>({width:windowOptions?.column||150}),[windowOptions?.column]),table=useTable({data,columns:cols,...infiniteScroll&&{defaultColumn}},...tablePlugins),TableHtmlElement=infiniteScroll?"div":"table",TheadHtmlElement=infiniteScroll?"div":"thead",TbodyHtmlElement=infiniteScroll?"div":"tbody",ThHtmlElement=infiniteScroll?"div":"th",TrHtmlElement=infiniteScroll?"div":"tr";useEffect(()=>(orders!==void 0&&setLoading(!1),()=>{setLoading(!0)}),[orders]);const scrollBarSize=infiniteScroll?useMemo(()=>scrollbarWidth(),[]):0,LoadingComponent=loadingElement||_jsx("div",{children:"Loading..."}),headerComponent=table.headerGroups.map((headerGroup,i)=>{const columns2=headerGroup.headers.map((column,k)=>{const sortLabel=column.isSorted?column.isSortedDesc?"desc":"asc":"";return _createElement(ThHtmlElement,{"data-testid":`thead-${k}`,"data-sort":`${sortLabel}`,className:column?.className,...column.getHeaderProps(column?.getSortByToggleProps&&column?.getSortByToggleProps()),key:k},_jsxs("span",{className:column?.titleClassName,children:[column.render("Header"),column.isSorted?column.isSortedDesc?sortDescIcon:sortAscIcon:""]}))});return _createElement(TrHtmlElement,{...headerGroup.getHeaderGroupProps(),key:i},columns2)}),components=infiniteScroll?useCallback(({index,style})=>{const row=table.rows[index];row&&table.prepareRow(row);const childProps={orders,order:orders?.[index],row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll};return _jsx(TrHtmlElement,{...row?.getRowProps({style}),className:rowTrClassName,children:_jsx(OrderListChildrenContext.Provider,{value:childProps,children})})},[table.prepareRow,table.rows]):table.rows.map((row,i)=>{table.prepareRow(row);const childProps={orders,order:orders?.[i],row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll};return _createElement(TrHtmlElement,{...row.getRowProps(),className:rowTrClassName,key:i},_jsx(OrderListChildrenContext.Provider,{value:childProps,children}))});return loading&&orders==null?_jsx(_Fragment,{children:LoadingComponent}):orders?.length===0?_jsx(OrderListChildrenContext.Provider,{value:{orders},children}):_jsxs(TableHtmlElement,{...p,...table.getTableProps(),children:[_jsx(TheadHtmlElement,{className:theadClassName,children:headerComponent}),_jsx(TbodyHtmlElement,{...table.getTableBodyProps(),children:infiniteScroll?_jsx(FixedSizeList,{height:windowOptions?.height||400,itemCount:table.rows.length,itemSize:windowOptions?.itemSize||100,width:windowOptions?.width||table.totalColumnsWidth+scrollBarSize,children:components}):components})]})}export default OrderList;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
3
|
+
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
4
|
+
/**
|
|
5
|
+
* Function allow you to customize the component
|
|
6
|
+
*/
|
|
7
|
+
children?: ChildrenFunction<Omit<Props, 'children'>>;
|
|
8
|
+
/**
|
|
9
|
+
* Label to show. Default: 'No orders available.'
|
|
10
|
+
*/
|
|
11
|
+
emptyText?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function OrderListEmpty(props: Props): JSX.Element | null;
|
|
14
|
+
export default OrderListEmpty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import{useContext}from"react";export function OrderListEmpty(props){const{children,emptyText="No orders available",...p}=props,{orders}=useContext(OrderListChildrenContext),parentProps={emptyText,...p};return orders!=null&&orders.length>0?null:children!==void 0?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:emptyText})}export default OrderListEmpty;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { Cell, Row } from 'react-table';
|
|
2
|
+
import type { Cell, Row } from 'react-table';
|
|
3
3
|
import type { Order } from '@commercelayer/sdk';
|
|
4
|
-
|
|
4
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
5
5
|
/**
|
|
6
6
|
* The order resource
|
|
7
7
|
*/
|
|
@@ -14,17 +14,21 @@ declare type ChildrenProps = Omit<Props, 'children'> & {
|
|
|
14
14
|
* The current cell
|
|
15
15
|
*/
|
|
16
16
|
cell: Cell[];
|
|
17
|
+
/**
|
|
18
|
+
* All table cells
|
|
19
|
+
*/
|
|
20
|
+
cells: Cell[];
|
|
17
21
|
/**
|
|
18
22
|
* Infinite scroll enabled
|
|
19
23
|
*/
|
|
20
24
|
infiniteScroll: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
25
|
+
}
|
|
26
|
+
interface Props extends Omit<JSX.IntrinsicElements['td'], 'children'> {
|
|
23
27
|
children?: (props: ChildrenProps) => JSX.Element;
|
|
24
28
|
/**
|
|
25
29
|
* The order field to show
|
|
26
30
|
*/
|
|
27
31
|
field: keyof Order;
|
|
28
|
-
}
|
|
32
|
+
}
|
|
29
33
|
export declare function OrderListRow({ field, children, ...p }: Props): JSX.Element;
|
|
30
34
|
export default OrderListRow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as _createElement}from"react";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import isDate from"../../utils/isDate";import last from"lodash/last";export function OrderListRow({field,children,...p}){const{order,row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll}=useContext(OrderListChildrenContext),cell=row?.cells.filter(cell2=>cell2.column.id===field),isLastRow=last(row?.cells)?.column.id===field,As=infiniteScroll?"div":"td",ActionRow=()=>showActions&&isLastRow&&actionsComponent&&_jsx(As,{
|
|
1
|
+
import{createElement as _createElement}from"react";import{jsx as _jsx,Fragment as _Fragment,jsxs as _jsxs}from"react/jsx-runtime";import{useContext}from"react";import Parent from"../utils/Parent";import OrderListChildrenContext from"../../context/OrderListChildrenContext";import isDate from"../../utils/isDate";import last from"lodash/last";export function OrderListRow({field,children,...p}){const{order,row,showActions,actionsComponent,actionsContainerClassName,infiniteScroll}=useContext(OrderListChildrenContext),cell=row?.cells.filter(cell2=>cell2.column.id===field),isLastRow=last(row?.cells)?.column.id===field,As=infiniteScroll?"div":"td",ActionRow=()=>showActions&&isLastRow&&actionsComponent&&_jsx(As,{"data-testid":"action-cell",...p,className:actionsContainerClassName,children:_jsx(Parent,{...parentProps,children:actionsComponent})})||null,parentProps={...p,field,order,row,cell,infiniteScroll};return children?_jsxs(_Fragment,{children:[_jsx(Parent,{...parentProps,children}),_jsx(ActionRow,{})]}):_jsxs(_Fragment,{children:[cell?.map((cell2,k)=>{const cellValue=cell2.value,value=isDate(cellValue)?new Date(Date.parse(cellValue)).toLocaleString():cell2.render("Cell");return _createElement(As,{"data-testid":`cell-${k}`,...p,...cell2.getCellProps(),key:k},value)}),_jsx(ActionRow,{})]})}export default OrderListRow;
|
|
@@ -1,24 +1,14 @@
|
|
|
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: () => Promise<void>;
|
|
5
|
-
}
|
|
5
|
+
}
|
|
6
6
|
declare type Props = {
|
|
7
|
-
children?: ChildrenProps
|
|
7
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
8
8
|
label?: string | ReactNode;
|
|
9
9
|
onClick?: (response: {
|
|
10
10
|
placed: boolean;
|
|
11
11
|
}) => void;
|
|
12
12
|
} & JSX.IntrinsicElements['button'];
|
|
13
13
|
export declare function PlaceOrderButton(props: Props): JSX.Element;
|
|
14
|
-
export declare namespace PlaceOrderButton {
|
|
15
|
-
var propTypes: {
|
|
16
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
17
|
-
label: import("prop-types").Requireable<NonNullable<string | import("prop-types").ReactElementLike | null | undefined>>;
|
|
18
|
-
};
|
|
19
|
-
var defaultProps: {
|
|
20
|
-
label: string;
|
|
21
|
-
};
|
|
22
|
-
var displayName: string;
|
|
23
|
-
}
|
|
24
14
|
export default PlaceOrderButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import Parent from"../utils/Parent";import PlaceOrderContext from"../../context/PlaceOrderContext";import isFunction from"lodash/isFunction";import PaymentMethodContext from"../../context/PaymentMethodContext";import OrderContext from"../../context/OrderContext";import getCardDetails from"../../utils/getCardDetails";export function PlaceOrderButton(props){const ref=useRef(null),{children,label="Place order",disabled,onClick,...p}=props,{isPermitted,setPlaceOrder,options,paymentType,setButtonRef}=useContext(PlaceOrderContext),[notPermitted,setNotPermitted]=useState(!0),[forceDisable,setForceDisable]=useState(disabled),{currentPaymentMethodRef,loading,currentPaymentMethodType,paymentSource,setPaymentSource}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),isFree=order?.total_amount_with_taxes_cents===0;useEffect(()=>{if(loading)setNotPermitted(loading);else if(paymentType===currentPaymentMethodType&&paymentType){const card=getCardDetails({customerPayment:{payment_source:paymentSource},paymentType});(isFree&&isPermitted||currentPaymentMethodRef?.current?.onsubmit||card.brand)&&isPermitted&&setNotPermitted(!1)}else setNotPermitted(!(isFree&&isPermitted));return()=>{setNotPermitted(!0)}},[isPermitted,paymentType,currentPaymentMethodRef?.current?.onsubmit,loading,currentPaymentMethodType,order,paymentSource]),useEffect(()=>{paymentType==="paypal_payments"&&options?.paypalPayerId&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.paypalPayerId,paymentType]),useEffect(()=>{if(paymentType==="adyen_payments"&&options?.adyen?.redirectResult&&order?.status&&["draft","pending"].includes(order?.status)){const attributes={payment_request_details:{details:{redirectResult:options?.adyen?.redirectResult},paymentData:paymentSource.payment_response.paymentData},_details:1};setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}).then(res=>{const resultCode=res?.payment_response?.resultCode;["Authorised","Pending","Received"].includes(resultCode)&&handleClick()})}paymentType==="adyen_payments"&&options?.adyen?.MD&&options?.adyen?.PaRes&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.adyen,paymentType]),useEffect(()=>{paymentType==="checkout_com_payments"&&options?.checkoutCom?.session_id&&order?.status&&["draft","pending"].includes(order?.status)&&handleClick()},[options?.checkoutCom,paymentType]),useEffect(()=>{ref?.current!=null&&setButtonRef!=null&&setButtonRef(ref)},[ref]);const handleClick=async()=>{let isValid=!0;setForceDisable(!0);const card=paymentType&&getCardDetails({paymentType,customerPayment:{payment_source:paymentSource}});currentPaymentMethodRef?.current?.onsubmit&&[!options?.paypalPayerId,!options?.adyen?.MD,!options?.checkoutCom?.session_id].every(Boolean)?(isValid=await currentPaymentMethodRef.current?.onsubmit(paymentSource),!isValid&&paymentSource.payment_response?.resultCode==="Authorised"&&(isValid=!0)):card?.brand&&(isValid=!0);const placed=isValid&&setPlaceOrder&&(paymentSource||isFree)&&await setPlaceOrder({paymentSource});setForceDisable(!1),onClick&&placed&&onClick(placed)},disabledButton=disabled!==void 0?disabled:notPermitted,parentProps={...p,label,disabled:disabledButton,handleClick,ref};return children?_jsx(Parent,{...parentProps,children}):_jsx("button",{ref,type:"button",disabled:disabledButton||forceDisable,onClick:()=>{handleClick()},...p,children:isFunction(label)?label():label})}export default PlaceOrderButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import ParcelChildrenContext from"../../context/ParcelChildrenContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import{useContext}from"react";export function Parcel({children}){const{parcels}=useContext(ShipmentChildrenContext),components=parcels?.map((parcel,key)=>_jsx(ParcelChildrenContext.Provider,{value:{parcel},children},key))??null;return _jsx(_Fragment,{children:components})}export default Parcel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import{setCustomerOrderParam}from"../../utils/localStorage";import Parent from"../utils/Parent";import getBrowserInfo from"../../utils/browserInfo";import PlaceOrderContext from"../../context/PlaceOrderContext";import OrderContext from"../../context/OrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};export function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState(null),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{placeOrderButtonRef}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component&&component.submit&&component.submit(),!1},handleChange=async(state,checkout2)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=()=>handleSubmit(ref.current,checkout2),setPaymentRef({ref}));const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}};paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,component)=>{const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=pSource?.payment_response?.action,resultCode=pSource?.payment_response?.resultCode;if(adyenAction&&component)return component.handleAction(adyenAction),!1;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=pSource?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return console.error("Adyen additional details error:",error),!1}},onSubmit=async(state,component)=>{
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../../context/PaymentMethodContext";import{setCustomerOrderParam}from"../../utils/localStorage";import Parent from"../utils/Parent";import getBrowserInfo from"../../utils/browserInfo";import PlaceOrderContext from"../../context/PlaceOrderContext";import OrderContext from"../../context/OrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={};export function AdyenPayment({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"}){const{cardContainerClassName,threeDSecureContainerClassName,styles}={...defaultConfig,...config},[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState(null),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{order}=useContext(OrderContext),{placeOrderButtonRef}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,component)=>{const savePaymentSourceToCustomerWallet=e?.elements?.save_payment_source_to_customer_wallet?.checked;return savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet),component&&component.submit&&component.submit(),!1},handleChange=async(state,checkout2)=>{if(state.isValid){ref.current&&(ref.current.onsubmit=()=>handleSubmit(ref.current,checkout2),setPaymentRef({ref}));const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}};paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,component)=>{const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=pSource?.payment_response?.action,resultCode=pSource?.payment_response?.resultCode;if(adyenAction&&component)return component.handleAction(adyenAction),!1;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=pSource?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return console.error("Adyen additional details error:",error),!1}},onSubmit=async(state,component)=>{const browserInfo=getBrowserInfo();let control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments"});if(control?.payment_response?.resultCode==="Authorised")return!0;Object.keys(control?.payment_request_data).length>0===!1&&(control=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes:{payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:window.location.href,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}}}}));const attributes={payment_request_data:{...state.data,payment_method:state.data.paymentMethod,return_url:window.location.href,origin:window.location.origin,redirect_from_issuer_method:"GET",browser_info:{acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",...browserInfo}},_authorize:1};delete attributes.payment_request_data.paymentMethod;try{const res=await setPaymentSource({paymentSourceId:paymentSource?.id,paymentResource:"adyen_payments",attributes}),action=res?.payment_response?.action;if(component&&action)return component.handleAction(action),!1;const resultCode=res?.payment_response?.resultCode;if(["Authorised","Pending","Received"].includes(resultCode))return placeOrderButtonRef!==null&&placeOrderButtonRef?.current!=null&&(placeOrderButtonRef.current.disabled===!0&&(placeOrderButtonRef.current.disabled=!1),placeOrderButtonRef.current?.click()),!0;if(["Cancelled"].includes(resultCode)){const message=res?.payment_response?.refusalReason;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}if(res?.payment_response?.errorType)if(res?.payment_response?.errorCode==="14_006")onSubmit(state,component);else{const message=res?.payment_response?.message;setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}])}return!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}};return useEffect(()=>{const paymentMethodsResponse=paymentSource?.payment_methods?.paymentMethods?paymentSource?.payment_methods.paymentMethods:[],[firstPaymentMethod]=paymentMethodsResponse,isOnlyCard=paymentMethodsResponse?.length===1&&firstPaymentMethod.type==="scheme";paymentMethodsResponse.length===0&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,amount:{currency:order?.currency_code||"",value:order?.total_amount_with_taxes_cents||0},countryCode:order?.country_code||"",paymentMethodsResponse:{paymentMethods:paymentMethodsResponse},showPayButton:!1,paymentMethodsConfiguration:{threeDS2:threeDSConfiguration,paypal:{showPayButton:!0,style:styles?.paypal},card:{styles:styles?.card,holderNameRequired:!1}},onAdditionalDetails:handleOnAdditionalDetails,onChange:handleChange,onSubmit};return!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&window&&!checkout&&import("@adyen/adyen-web").then(({default:AdyenCheckout})=>{const type=isOnlyCard?"card":"dropin";AdyenCheckout(options).then(adyenCheckout=>{const component=adyenCheckout.create(type,{onSelect:component2=>{const id=component2._id;id.search("scheme")===-1&&ref.current&&(id.search("paypal")===-1?ref.current.onsubmit=()=>handleSubmit(ref.current,component2):ref.current.onsubmit=null,setPaymentRef({ref}))}}).mount("#adyen-dropin");component&&(setCheckout(component),setLoadAdyen(!0))})}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",{ref,onSubmit:e=>handleSubmit(e,checkout),children:[_jsx("div",{className:cardContainerClassName,id:"adyen-dropin"}),templateCustomerSaveToWallet&&_jsx(Parent,{name:"save_payment_source_to_customer_wallet",children:templateCustomerSaveToWallet}),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"})]})}export default AdyenPayment;
|
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { IconBrand } from '../../context/PaymentSourceContext';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
4
|
+
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
5
5
|
brand: IconBrand;
|
|
6
6
|
defaultSrc: string;
|
|
7
7
|
url: string;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
declare type Props = {
|
|
10
|
-
children?:
|
|
10
|
+
children?: ChildrenFunction<ChildrenProps>;
|
|
11
11
|
width?: number;
|
|
12
12
|
height?: number;
|
|
13
13
|
} & JSX.IntrinsicElements['img'];
|
|
14
14
|
export declare function PaymentSourceBrandIcon({ src, width, children, ...p }: Props): JSX.Element;
|
|
15
|
-
export declare namespace PaymentSourceBrandIcon {
|
|
16
|
-
var propTypes: {
|
|
17
|
-
children: import("prop-types").Requireable<(...args: any[]) => any>;
|
|
18
|
-
width: import("prop-types").Requireable<number>;
|
|
19
|
-
height: import("prop-types").Requireable<number>;
|
|
20
|
-
src: import("prop-types").Requireable<string>;
|
|
21
|
-
className: import("prop-types").Requireable<string>;
|
|
22
|
-
};
|
|
23
|
-
var displayName: string;
|
|
24
|
-
}
|
|
25
15
|
export default PaymentSourceBrandIcon;
|