@commercelayer/react-components 4.2.2 → 4.2.3-beta.0
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/customers/CustomerContainer.d.ts +2 -2
- package/lib/cjs/components/customers/CustomerContainer.js +1 -1
- package/lib/cjs/components/customers/CustomerPaymentSource.d.ts +10 -0
- package/lib/cjs/components/customers/CustomerPaymentSource.js +1 -0
- package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.d.ts +13 -0
- package/lib/cjs/components/customers/CustomerPaymentSourceEmpty.js +1 -0
- package/lib/cjs/components/orders/PlaceOrderContainer.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandIcon.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceBrandName.js +1 -1
- package/lib/cjs/components/payment_source/PaymentSourceDetail.d.ts +4 -1
- package/lib/cjs/components/payment_source/PaymentSourceDetail.js +1 -1
- package/lib/cjs/components/shipments/Shipment.js +1 -1
- package/lib/cjs/components/shipments/ShipmentsContainer.js +1 -1
- package/lib/cjs/components/skus/AvailabilityContainer.js +1 -1
- package/lib/cjs/components/skus/AvailabilityTemplate.js +1 -1
- package/lib/cjs/components/utils/GenericFieldComponent.js +1 -1
- package/lib/cjs/context/CustomerContext.d.ts +5 -5
- package/lib/cjs/context/CustomerPaymentSourceContext.d.ts +11 -0
- package/lib/cjs/context/CustomerPaymentSourceContext.js +1 -0
- package/lib/cjs/context/PaymentSourceContext.d.ts +2 -2
- package/lib/cjs/reducers/AvailabilityReducer.d.ts +1 -0
- package/lib/cjs/reducers/AvailabilityReducer.js +1 -1
- package/lib/cjs/reducers/CustomerReducer.d.ts +7 -4
- package/lib/cjs/reducers/CustomerReducer.js +1 -1
- package/lib/cjs/reducers/OrderReducer.d.ts +2 -1
- package/lib/cjs/reducers/OrderReducer.js +1 -1
- package/lib/cjs/utils/getCardDetails.d.ts +5 -5
- package/lib/esm/components/customers/CustomerContainer.d.ts +2 -2
- package/lib/esm/components/customers/CustomerContainer.js +1 -1
- package/lib/esm/components/customers/CustomerPaymentSource.d.ts +10 -0
- package/lib/esm/components/customers/CustomerPaymentSource.js +1 -0
- package/lib/esm/components/customers/CustomerPaymentSourceEmpty.d.ts +13 -0
- package/lib/esm/components/customers/CustomerPaymentSourceEmpty.js +1 -0
- package/lib/esm/components/orders/PlaceOrderContainer.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandIcon.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceBrandName.js +1 -1
- package/lib/esm/components/payment_source/PaymentSourceDetail.d.ts +4 -1
- package/lib/esm/components/payment_source/PaymentSourceDetail.js +1 -1
- package/lib/esm/components/shipments/Shipment.js +1 -1
- package/lib/esm/components/shipments/ShipmentsContainer.js +1 -1
- package/lib/esm/components/skus/AvailabilityContainer.js +1 -1
- package/lib/esm/components/skus/AvailabilityTemplate.js +1 -1
- package/lib/esm/components/utils/GenericFieldComponent.js +1 -1
- package/lib/esm/context/CustomerContext.d.ts +5 -5
- package/lib/esm/context/CustomerPaymentSourceContext.d.ts +11 -0
- package/lib/esm/context/CustomerPaymentSourceContext.js +1 -0
- package/lib/esm/context/PaymentSourceContext.d.ts +2 -2
- package/lib/esm/reducers/AvailabilityReducer.d.ts +1 -0
- package/lib/esm/reducers/AvailabilityReducer.js +1 -1
- package/lib/esm/reducers/CustomerReducer.d.ts +7 -4
- package/lib/esm/reducers/CustomerReducer.js +1 -1
- package/lib/esm/reducers/OrderReducer.d.ts +2 -1
- package/lib/esm/reducers/OrderReducer.js +1 -1
- package/lib/esm/utils/getCardDetails.d.ts +5 -5
- package/lib/tsconfig.prod.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),CustomerReducer_1=tslib_1.__importStar(require("../../reducers/CustomerReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext"));function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=(0,react_1.useReducer)(CustomerReducer_1.default,CustomerReducer_1.customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include,includeLoaded]),(0,react_1.useEffect)(()=>{config.accessToken&&state.addresses==null&&!isGuest&&(0,CustomerReducer_1.getCustomerAddresses)({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),config.accessToken
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),CustomerReducer_1=tslib_1.__importStar(require("../../reducers/CustomerReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext"));function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=(0,react_1.useReducer)(CustomerReducer_1.default,CustomerReducer_1.customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include?.length,Object.keys(includeLoaded??{}).length]),(0,react_1.useEffect)(()=>{config.accessToken&&state.addresses==null&&!isGuest&&(0,CustomerReducer_1.getCustomerAddresses)({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),config.accessToken&&order==null&&include==null&&includeLoaded==null&&((0,CustomerReducer_1.getCustomerOrders)({config,dispatch}),(0,CustomerReducer_1.getCustomerPayments)({config,dispatch}))},[config.accessToken,order,isGuest]);const contextValue=(0,react_1.useMemo)(()=>({isGuest,...state,saveCustomerUser:async customerEmail=>{await(0,CustomerReducer_1.saveCustomerUser)({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>(0,CustomerReducer_1.setCustomerErrors)(errors,dispatch),setCustomerEmail:customerEmail=>(0,CustomerReducer_1.setCustomerEmail)(customerEmail,dispatch),getCustomerPaymentSources:()=>(0,CustomerReducer_1.getCustomerPaymentSources)({dispatch,order}),deleteCustomerAddress:async({customerAddressId})=>await(0,CustomerReducer_1.deleteCustomerAddress)({customerAddressId,dispatch,config,addresses:state.addresses}),createCustomerAddress:async address=>await(0,CustomerReducer_1.createCustomerAddress)({address,config,dispatch,state})}),[state,isGuest]);return(0,jsx_runtime_1.jsx)(CustomerContext_1.default.Provider,{value:contextValue,children})}exports.CustomerContainer=CustomerContainer,exports.default=CustomerContainer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DefaultChildrenType } from '../../typings/globals';
|
|
2
|
+
interface Props {
|
|
3
|
+
children?: DefaultChildrenType;
|
|
4
|
+
/**
|
|
5
|
+
* Customize the loader content.
|
|
6
|
+
*/
|
|
7
|
+
loader?: string | JSX.Element;
|
|
8
|
+
}
|
|
9
|
+
export declare function CustomerPaymentSource({ children, loader }: Props): JSX.Element;
|
|
10
|
+
export default CustomerPaymentSource;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerPaymentSource=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext")),getCardDetails_1=tslib_1.__importDefault(require("../../utils/getCardDetails")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext")),react_1=require("react");function CustomerPaymentSource({children,loader="Loading..."}){const[loading,setLoading]=(0,react_1.useState)(!0),{payments}=(0,useCustomContext_1.default)({context:CustomerContext_1.default,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSource",key:"payments"});(0,react_1.useEffect)(()=>(payments!=null&&setLoading(!1),()=>{setLoading(!0)}),[payments!=null]);const provider=payments?.filter(p=>p?.payment_source!=null).map(p=>{const paymentType=p.payment_source?.type,customerPayment=p,value={...(0,getCardDetails_1.default)({paymentType,customerPayment})};return(0,jsx_runtime_1.jsx)(CustomerPaymentSourceContext_1.default.Provider,{value,children},p.id)});return loading?(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:loader}):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:provider})}exports.CustomerPaymentSource=CustomerPaymentSource,exports.default=CustomerPaymentSource;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
2
|
+
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
3
|
+
/**
|
|
4
|
+
* Function allow you to customize the component
|
|
5
|
+
*/
|
|
6
|
+
children?: ChildrenFunction<Omit<Props, 'children'>>;
|
|
7
|
+
/**
|
|
8
|
+
* Label to show. Default: 'No payments available.'
|
|
9
|
+
*/
|
|
10
|
+
emptyText?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function CustomerPaymentSourceEmpty({ children, emptyText, ...p }: Props): JSX.Element | null;
|
|
13
|
+
export default CustomerPaymentSourceEmpty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomerPaymentSourceEmpty=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerContext_1=tslib_1.__importDefault(require("../../context/CustomerContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function CustomerPaymentSourceEmpty({children,emptyText="No payments available",...p}){const{payments}=(0,useCustomContext_1.default)({context:CustomerContext_1.default,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSourceEmpty",key:"payments"}),parentProps={emptyText,...p};return payments!=null&&payments.length>0||payments===null?null:children!==void 0?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:emptyText})}exports.CustomerPaymentSourceEmpty=CustomerPaymentSourceEmpty,exports.default=CustomerPaymentSourceEmpty;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlaceOrderContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),react_1=require("react"),PlaceOrderReducer_1=tslib_1.__importStar(require("../../reducers/PlaceOrderReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),PlaceOrderReducer_2=require("../../reducers/PlaceOrderReducer"),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=(0,react_1.useReducer)(PlaceOrderReducer_1.default,PlaceOrderReducer_1.placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=(0,useCustomContext_1.default)({context:OrderContext_1.default,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PlaceOrderContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PlaceOrderContext_1=tslib_1.__importDefault(require("../../context/PlaceOrderContext")),react_1=require("react"),PlaceOrderReducer_1=tslib_1.__importStar(require("../../reducers/PlaceOrderReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),PlaceOrderReducer_2=require("../../reducers/PlaceOrderReducer"),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=(0,react_1.useReducer)(PlaceOrderReducer_1.default,PlaceOrderReducer_1.placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=(0,useCustomContext_1.default)({context:OrderContext_1.default,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&(0,PlaceOrderReducer_1.placeOrderPermitted)({config,dispatch,order,options:{...options}})},[order,include,includeLoaded]);const contextValue={...state,setPlaceOrder:async({paymentSource})=>await(0,PlaceOrderReducer_2.setPlaceOrder)({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>(0,PlaceOrderReducer_1.placeOrderPermitted)({config,dispatch,order,options:{...options}}),setButtonRef:ref=>(0,PlaceOrderReducer_1.setButtonRef)(ref,dispatch)};return(0,jsx_runtime_1.jsx)(PlaceOrderContext_1.default.Provider,{value:contextValue,children})}exports.PlaceOrderContainer=PlaceOrderContainer,exports.default=PlaceOrderContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent"));function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandIcon=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,ref=(0,react_1.useRef)(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${cardBrand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand:cardBrand,defaultSrc,url,width,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("img",{ref,src:url,onError:handleError,width,...p})}exports.PaymentSourceBrandIcon=PaymentSourceBrandIcon,exports.default=PaymentSourceBrandIcon;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceBrandName=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),capitalize_1=tslib_1.__importDefault(require("lodash/capitalize")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceBrandName({children,label,...props}){const{brand}=(0,react_1.useContext)(PaymentSourceContext_1.default),{brand:customerCardBrand}=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardBrand=brand??customerCardBrand,brandName=cardBrand&&(0,capitalize_1.default)(cardBrand.replaceAll(/_|-/gm," ")),parentProps={brand:brandName,label,...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...props,children:label||(0,capitalize_1.default)(brandName)})}exports.PaymentSourceBrandName=PaymentSourceBrandName,exports.default=PaymentSourceBrandName;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { ChildrenFunction } from '../../typings/index';
|
|
1
|
+
import type { ChildrenFunction } from '../../typings/index';
|
|
2
2
|
export type PaymentSourceDetailType = 'last4' | 'exp_year' | 'exp_month';
|
|
3
3
|
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
text: string;
|
|
5
5
|
}
|
|
6
6
|
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
7
7
|
children?: ChildrenFunction<ChildrenProps>;
|
|
8
|
+
/**
|
|
9
|
+
* Type of detail to display
|
|
10
|
+
*/
|
|
8
11
|
type: PaymentSourceDetailType;
|
|
9
12
|
}
|
|
10
13
|
export declare function PaymentSourceDetail({ type, children, ...p }: Props): JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceDetail=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PaymentSourceDetail=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),PaymentSourceContext_1=tslib_1.__importDefault(require("../../context/PaymentSourceContext")),react_1=require("react"),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),CustomerPaymentSourceContext_1=tslib_1.__importDefault(require("../../context/CustomerPaymentSourceContext"));function PaymentSourceDetail({type,children,...p}){const card=(0,react_1.useContext)(PaymentSourceContext_1.default),customerCard=(0,react_1.useContext)(CustomerPaymentSourceContext_1.default),cardObj=card??customerCard,text=type in cardObj?cardObj[type]:type==="last4"?"****":"**",parentProps={type,text,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{...p,children:text})}exports.PaymentSourceDetail=PaymentSourceDetail,exports.default=PaymentSourceDetail;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Shipment=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),ShipmentContext_1=tslib_1.__importDefault(require("../../context/ShipmentContext")),ShipmentChildrenContext_1=tslib_1.__importDefault(require("../../context/ShipmentChildrenContext")),getLoaderComponent_1=tslib_1.__importDefault(require("../../utils/getLoaderComponent")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext"));function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=(0,react_1.useState)(!0),{shipments,deliveryLeadTimes,setShippingMethod}=(0,react_1.useContext)(ShipmentContext_1.default),{order}=(0,react_1.useContext)(OrderContext_1.default);(0,react_1.useEffect)(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.stock_line_items?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0]?.id:shipment.shipping_method?.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>time.stock_location?.id===shipment.stock_location?.id),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return(0,jsx_runtime_1.jsx)(ShipmentChildrenContext_1.default.Provider,{value:shipmentProps,children},k)});return loading?(0,getLoaderComponent_1.default)(loader):(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:components})}exports.Shipment=Shipment,exports.default=Shipment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ShipmentsContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),ShipmentContext_1=tslib_1.__importStar(require("../../context/ShipmentContext")),react_1=require("react"),ShipmentReducer_1=tslib_1.__importStar(require("../../reducers/ShipmentReducer")),OrderContext_1=tslib_1.__importDefault(require("../../context/OrderContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty"));function ShipmentsContainer(props){const{children}=props,[state,dispatch]=(0,react_1.useReducer)(ShipmentReducer_1.default,ShipmentReducer_1.shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=(0,react_1.useContext)(OrderContext_1.default),config=(0,react_1.useContext)(CommerceLayerContext_1.default);(0,react_1.useEffect)(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),(0,react_1.useEffect)(()=>{order!=null&&!(0,isEmpty_1.default)(config)&&order.shipments&&(0,ShipmentReducer_1.getShipments)({order,dispatch,config})},[order!=null,order?.shipments?.length]),(0,react_1.useEffect)(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>!!(lineItem.item?.do_not_ship||lineItem.item?.do_not_track||lineItem.item?.inventory?.quantity>=lineItem?.quantity)).includes(!1)&&(0,ShipmentReducer_1.setShipmentErrors)([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{(0,ShipmentReducer_1.setShipmentErrors)([],dispatch)}),[order?.shipments]);const contextValue=(0,react_1.useMemo)(()=>({...state,setShipmentErrors:errors=>ShipmentContext_1.defaultShipmentContext.setShipmentErrors(errors,dispatch),setShippingMethod:async(shipmentId,shippingMethodId)=>await(0,ShipmentReducer_1.setShippingMethod)({shippingMethodId,shipmentId,config,getOrder,order})}),[state]);return(0,jsx_runtime_1.jsx)(ShipmentContext_1.default.Provider,{value:contextValue,children})}exports.ShipmentsContainer=ShipmentsContainer,exports.default=ShipmentsContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),AvailabilityReducer_1=tslib_1.__importStar(require("../../reducers/AvailabilityReducer")),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),{accessToken,endpoint}=(0,useCustomContext_1.default)({context:CommerceLayerContext_1.default,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=(0,react_1.useReducer)(AvailabilityReducer_1.default,AvailabilityReducer_1.availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityContainer=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),AvailabilityReducer_1=tslib_1.__importStar(require("../../reducers/AvailabilityReducer")),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),CommerceLayerContext_1=tslib_1.__importDefault(require("../../context/CommerceLayerContext")),LineItemChildrenContext_1=tslib_1.__importDefault(require("../../context/LineItemChildrenContext")),SkuChildrenContext_1=tslib_1.__importDefault(require("../../context/SkuChildrenContext")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=(0,react_1.useContext)(LineItemChildrenContext_1.default),{sku}=(0,react_1.useContext)(SkuChildrenContext_1.default),{accessToken,endpoint}=(0,useCustomContext_1.default)({context:CommerceLayerContext_1.default,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=(0,react_1.useReducer)(AvailabilityReducer_1.default,AvailabilityReducer_1.availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;(0,react_1.useEffect)(()=>{if(accessToken!=null&&accessToken!==""){const config={accessToken,endpoint};sCode&&(0,AvailabilityReducer_1.getAvailability)({skuCode:sCode,config,dispatch})}return()=>{dispatch({type:"setAvailability",payload:{}})}},[accessToken,sCode]),(0,react_1.useEffect)(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]);const memoized=(0,react_1.useMemo)(()=>({...state,parent:!0}),[state]);return(0,jsx_runtime_1.jsx)(AvailabilityContext_1.default.Provider,{value:memoized,children})}exports.AvailabilityContainer=AvailabilityContainer,exports.default=AvailabilityContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityTemplate=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityTemplate(props){const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props,{min,max,shipping_method:shippingMethod,quantity}=(0,useCustomContext_1.default)({context:AvailabilityContext_1.default,contextComponentName:"AvailabilityContainer",currentComponentName:"AvailabilityTemplate",key:"parent"}),text=[],mn=min!=null&&timeFormat!=null?min?.[timeFormat]:"",mx=max!=null&&timeFormat!=null?max?.[timeFormat]:"",shippingMethodPrice=showShippingMethodPrice&&shippingMethod?.formatted_price_amount?`(${shippingMethod?.formatted_price_amount})`:"",name=showShippingMethodName&&shippingMethod?`with ${shippingMethod.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&timeFormat&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps={min,max,shipping_method:shippingMethod,quantity,text:text.join(" "),...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AvailabilityTemplate=void 0;const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),AvailabilityContext_1=tslib_1.__importDefault(require("../../context/AvailabilityContext")),Parent_1=tslib_1.__importDefault(require("../utils/Parent")),useCustomContext_1=tslib_1.__importDefault(require("../../utils/hooks/useCustomContext"));function AvailabilityTemplate(props){const{timeFormat,showShippingMethodName,showShippingMethodPrice,children,...p}=props,{min,max,shipping_method:shippingMethod,quantity,skuCode}=(0,useCustomContext_1.default)({context:AvailabilityContext_1.default,contextComponentName:"AvailabilityContainer",currentComponentName:"AvailabilityTemplate",key:"parent"}),text=[],mn=min!=null&&timeFormat!=null?min?.[timeFormat]:"",mx=max!=null&&timeFormat!=null?max?.[timeFormat]:"",shippingMethodPrice=showShippingMethodPrice&&shippingMethod?.formatted_price_amount?`(${shippingMethod?.formatted_price_amount})`:"",name=showShippingMethodName&&shippingMethod?`with ${shippingMethod.name}`:"";quantity&&quantity>0?(text.push("Available"),mn&&mx&&timeFormat&&text.push(`in ${mn} - ${mx} ${timeFormat} ${name} ${shippingMethodPrice}`)):quantity===0&&text.push("Out of stock");const parentProps={min,max,shipping_method:shippingMethod,quantity,text:text.join(" "),...props};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)("span",{"data-testid":skuCode?`availability-${skuCode}`:"",...p,children:text.join(" ")})}exports.AvailabilityTemplate=AvailabilityTemplate,exports.default=AvailabilityTemplate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("./Parent")),react_1=require("react"),placeholderImages_1=require("../../utils/placeholderImages");function GenericFieldComponent(props){const{children,tagElement,attribute,context,...p}=props,resourceContext=(0,react_1.useContext)(context);let attributeValue="";const keysContext=Object.keys(resourceContext).filter(key=>key===
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),Parent_1=tslib_1.__importDefault(require("./Parent")),react_1=require("react"),placeholderImages_1=require("../../utils/placeholderImages");function GenericFieldComponent(props){const{children,tagElement,attribute,context,resource,...p}=props,resourceContext=(0,react_1.useContext)(context);let attributeValue="";const keysContext=Object.keys(resourceContext).filter(key=>key===resource);if(keysContext.length===1){const[keyResource]=keysContext;keyResource&&attribute&&(attributeValue=resourceContext[keyResource][attribute])}const Tag=tagElement||"span";if(Tag==="img"&&!children){const src=attributeValue||placeholderImages_1.defaultImgUrl,name="";return(0,jsx_runtime_1.jsx)("img",{alt:name,src,...p})}const parentProps={attributeValue,tagElement,...p};return children?(0,jsx_runtime_1.jsx)(Parent_1.default,{...parentProps,children}):(0,jsx_runtime_1.jsx)(Tag,{"data-testid":attributeValue,...p,children:attributeValue},attributeValue)}exports.default=GenericFieldComponent;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { SetCustomerErrors, deleteCustomerAddress, CustomerState,
|
|
2
|
+
import { SetCustomerErrors, deleteCustomerAddress, CustomerState, getCustomerPaymentSources, setCustomerEmail, TCustomerAddress, getCustomerAddresses } from '../reducers/CustomerReducer';
|
|
3
3
|
export type InitialCustomerContext = Partial<{
|
|
4
4
|
saveCustomerUser: (customerEmail: string) => Promise<void>;
|
|
5
5
|
setCustomerErrors: SetCustomerErrors;
|
|
6
6
|
setCustomerEmail: typeof setCustomerEmail;
|
|
7
7
|
getCustomerPaymentSources: typeof getCustomerPaymentSources;
|
|
8
|
-
deleteCustomerAddress: typeof deleteCustomerAddress
|
|
9
|
-
getCustomerAddresses:
|
|
8
|
+
deleteCustomerAddress: typeof deleteCustomerAddress;
|
|
9
|
+
getCustomerAddresses: typeof getCustomerAddresses;
|
|
10
10
|
createCustomerAddress: (address: TCustomerAddress) => Promise<void>;
|
|
11
11
|
} & CustomerState>;
|
|
12
12
|
export declare const defaultCustomerContext: {};
|
|
@@ -15,8 +15,8 @@ declare const CustomerContext: import("react").Context<Partial<{
|
|
|
15
15
|
setCustomerErrors: SetCustomerErrors;
|
|
16
16
|
setCustomerEmail: typeof setCustomerEmail;
|
|
17
17
|
getCustomerPaymentSources: typeof getCustomerPaymentSources;
|
|
18
|
-
deleteCustomerAddress: typeof deleteCustomerAddress
|
|
19
|
-
getCustomerAddresses:
|
|
18
|
+
deleteCustomerAddress: typeof deleteCustomerAddress;
|
|
19
|
+
getCustomerAddresses: typeof getCustomerAddresses;
|
|
20
20
|
createCustomerAddress: (address: TCustomerAddress) => Promise<void>;
|
|
21
21
|
} & Partial<import("../reducers/CustomerReducer").CustomerActionPayload>>>;
|
|
22
22
|
export default CustomerContext;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconBrand } from './PaymentSourceContext';
|
|
3
|
+
interface DefaultContext {
|
|
4
|
+
brand?: IconBrand | string;
|
|
5
|
+
exp_month?: number | string;
|
|
6
|
+
exp_year?: number | string;
|
|
7
|
+
last4?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const defaultCustomerPaymentSourceContext: {};
|
|
10
|
+
declare const CustomerPaymentSourceContext: import("react").Context<DefaultContext>;
|
|
11
|
+
export default CustomerPaymentSourceContext;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.defaultCustomerPaymentSourceContext=void 0;const react_1=require("react");exports.defaultCustomerPaymentSourceContext={};const CustomerPaymentSourceContext=(0,react_1.createContext)(exports.defaultCustomerPaymentSourceContext);exports.default=CustomerPaymentSourceContext;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export type IconBrand = 'visa' | 'credit-card' | 'amex' | 'mastercard' | 'jcb' | 'wire-transfer' | 'maestro' | 'cirrus' | 'paypal';
|
|
3
|
-
|
|
3
|
+
interface DefaultContext {
|
|
4
4
|
brand?: IconBrand | string;
|
|
5
5
|
exp_month?: number | string;
|
|
6
6
|
exp_year?: number | string;
|
|
@@ -8,7 +8,7 @@ type DefaultContext = {
|
|
|
8
8
|
showCard?: boolean;
|
|
9
9
|
readonly?: boolean;
|
|
10
10
|
handleEditClick?: (e: MouseEvent) => void;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
export declare const defaultPaymentSourceContext: {};
|
|
13
13
|
declare const PaymentSourceContext: import("react").Context<DefaultContext>;
|
|
14
14
|
export default PaymentSourceContext;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAvailability=exports.availabilityInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.availabilityInitialState={};async function getAvailability({skuCode,dispatch,config}){const sdk=(0,getSdk_1.default)(config);try{const[sku]=await sdk.skus.list({fields:{skus:["id"]},filters:{code_in:skuCode}});if(sku){const skuInventory=await sdk.skus.retrieve(sku.id,{fields:{skus:["inventory"]}}),[level]=skuInventory.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];dispatch({type:"setAvailability",payload:{...delivery,quantity:skuInventory.inventory.quantity}})}}catch(error){console.error("Get SKU availability",error)}}exports.getAvailability=getAvailability;const typeAction=["setAvailability","setErrors"],availabilityReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,typeAction);exports.default=availabilityReducer;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAvailability=exports.availabilityInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk"));exports.availabilityInitialState={};async function getAvailability({skuCode,dispatch,config}){const sdk=(0,getSdk_1.default)(config);try{const[sku]=await sdk.skus.list({fields:{skus:["id"]},filters:{code_in:skuCode}});if(sku){const skuInventory=await sdk.skus.retrieve(sku.id,{fields:{skus:["inventory"]}}),[level]=skuInventory.inventory?.levels||[],[delivery]=level?.delivery_lead_times||[];dispatch({type:"setAvailability",payload:{...delivery,quantity:skuInventory.inventory.quantity,skuCode}})}}catch(error){console.error("Get SKU availability",error)}}exports.getAvailability=getAvailability;const typeAction=["setAvailability","setErrors"],availabilityReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,typeAction);exports.default=availabilityReducer;
|
|
@@ -6,7 +6,7 @@ import { updateOrder } from './OrderReducer';
|
|
|
6
6
|
export type CustomerActionType = 'setErrors' | 'setCustomerEmail' | 'setAddresses' | 'setPayments' | 'setOrders';
|
|
7
7
|
export interface CustomerActionPayload {
|
|
8
8
|
addresses: Address[] | null;
|
|
9
|
-
payments: CustomerPaymentSource[];
|
|
9
|
+
payments: CustomerPaymentSource[] | null;
|
|
10
10
|
customerEmail: string;
|
|
11
11
|
errors: BaseError[];
|
|
12
12
|
orders: Order[];
|
|
@@ -93,7 +93,7 @@ export interface GetCustomerPaymentSources {
|
|
|
93
93
|
order?: Order;
|
|
94
94
|
}
|
|
95
95
|
export declare function getCustomerPaymentSources(params?: GetCustomerPaymentSources): void;
|
|
96
|
-
|
|
96
|
+
interface GetCustomerOrdersProps {
|
|
97
97
|
/**
|
|
98
98
|
* The Commerce Layer config
|
|
99
99
|
*/
|
|
@@ -102,8 +102,8 @@ export type GetCustomerOrders = (params: {
|
|
|
102
102
|
* The Customer dispatch function
|
|
103
103
|
*/
|
|
104
104
|
dispatch: Dispatch<CustomerAction>;
|
|
105
|
-
}
|
|
106
|
-
export declare
|
|
105
|
+
}
|
|
106
|
+
export declare function getCustomerOrders({ config, dispatch }: GetCustomerOrdersProps): Promise<void>;
|
|
107
107
|
export type TCustomerAddress = AddressCreate & AddressUpdate;
|
|
108
108
|
interface TCreateCustomerAddress {
|
|
109
109
|
/**
|
|
@@ -124,6 +124,9 @@ interface TCreateCustomerAddress {
|
|
|
124
124
|
state?: CustomerState;
|
|
125
125
|
}
|
|
126
126
|
export declare function createCustomerAddress({ address, config, dispatch, state }: TCreateCustomerAddress): Promise<void>;
|
|
127
|
+
interface GetCustomerPaymentsParams extends GetCustomerOrdersProps {
|
|
128
|
+
}
|
|
129
|
+
export declare function getCustomerPayments({ config, dispatch }: GetCustomerPaymentsParams): Promise<void>;
|
|
127
130
|
export declare const customerInitialState: CustomerState;
|
|
128
131
|
declare const customerReducer: (state: CustomerState, reducer: CustomerAction) => CustomerState;
|
|
129
132
|
export default customerReducer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.createCustomerAddress=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=tslib_1.__importDefault(require("../utils/jwt"));async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;async function getCustomerAddresses({config,dispatch}){try{const addresses=[];(await(0,getSdk_1.default)(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=(0,getErrors_1.default)(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}}exports.getCustomerAddresses=getCustomerAddresses;async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await(0,getSdk_1.default)(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}}exports.deleteCustomerAddress=deleteCustomerAddress;function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.customerInitialState=exports.getCustomerPayments=exports.createCustomerAddress=exports.getCustomerOrders=exports.getCustomerPaymentSources=exports.deleteCustomerAddress=exports.getCustomerAddresses=exports.setCustomerEmail=exports.setCustomerErrors=exports.saveCustomerUser=void 0;const tslib_1=require("tslib"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importDefault(require("../utils/getErrors")),jwt_1=tslib_1.__importDefault(require("../utils/jwt"));async function saveCustomerUser({customerEmail,order,updateOrder}){if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}}exports.saveCustomerUser=saveCustomerUser;function setCustomerErrors(errors,dispatch){dispatch&&dispatch({type:"setErrors",payload:{errors}})}exports.setCustomerErrors=setCustomerErrors;function setCustomerEmail(customerEmail,dispatch){dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})}exports.setCustomerEmail=setCustomerEmail;async function getCustomerAddresses({config,dispatch}){try{const addresses=[];(await(0,getSdk_1.default)(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=(0,getErrors_1.default)(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}}exports.getCustomerAddresses=getCustomerAddresses;async function deleteCustomerAddress({config,dispatch,customerAddressId,addresses}){if(config&&addresses&&dispatch&&config)try{await(0,getSdk_1.default)(config).customer_addresses.delete(customerAddressId);const newAddresses=addresses.filter(({reference})=>reference!==customerAddressId);dispatch({type:"setAddresses",payload:{addresses:newAddresses}})}catch{throw new Error("Couldn't delete address")}}exports.deleteCustomerAddress=deleteCustomerAddress;function getCustomerPaymentSources(params){if(params){const{order,dispatch}=params;order?.available_customer_payment_sources&&dispatch&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})}}exports.getCustomerPaymentSources=getCustomerPaymentSources;async function getCustomerOrders({config,dispatch}){if(config.accessToken){const{owner}=(0,jwt_1.default)(config.accessToken);if(owner?.id){const customers=await(0,getSdk_1.default)(config).customers.retrieve(owner.id,{include:["orders"]}),orders=customers.orders?.filter(order=>order.status!=="pending"&&order.status!=="draft");dispatch({type:"setOrders",payload:{orders,customers}})}}}exports.getCustomerOrders=getCustomerOrders;async function createCustomerAddress({address,config,dispatch,state}){if(config&&address){const sdk=(0,getSdk_1.default)(config),{id}=address;try{if(id){const upAddress=await sdk.addresses.update(address),updatedAddresses=state?.addresses?.map(a=>a.id===upAddress.id?upAddress:a);dispatch&&dispatch({type:"setAddresses",payload:{addresses:updatedAddresses}})}else{const newAddress=await sdk.addresses.create(address);if(state?.customers?.id&&newAddress?.id){const newCustomerAddress=await sdk.customer_addresses.create({customer:sdk.customers.relationship(state?.customers?.id),address:sdk.addresses.relationship(newAddress.id)});await sdk.addresses.update({id:newAddress.id,reference:newCustomerAddress.id}),dispatch&&state?.addresses&&(newAddress.reference=newCustomerAddress.id,dispatch({type:"setAddresses",payload:{addresses:[...state.addresses,newAddress]}}))}}}catch{throw new Error("Couldn't create customer address")}}}exports.createCustomerAddress=createCustomerAddress;async function getCustomerPayments({config,dispatch}){if(config!=null&&dispatch!=null){const payments=await(0,getSdk_1.default)(config).customer_payment_sources.list({include:["payment_source"]});dispatch({type:"setPayments",payload:{payments}})}}exports.getCustomerPayments=getCustomerPayments,exports.customerInitialState={errors:[],addresses:null,payments:null};const type=["setErrors","setCustomerEmail","setAddresses","setPayments","setOrders"],customerReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=customerReducer;
|
|
@@ -26,7 +26,7 @@ export type AddToCartReturn = Promise<{
|
|
|
26
26
|
}>;
|
|
27
27
|
export type AddToCartImport = (params: AddToCartImportParams) => AddToCartReturn;
|
|
28
28
|
export type UnsetOrderState = (dispatch: Dispatch<OrderActions>) => void;
|
|
29
|
-
export 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.
|
|
29
|
+
export 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.stock_line_items.line_item' | 'shipments.shipping_method' | 'shipments.stock_location' | 'shipments.parcels' | 'shipments.parcels.parcel_line_items' | 'payment_source' | 'available_payment_methods' | 'payment_method';
|
|
30
30
|
type ResourceIncludedLoaded = Partial<Record<ResourceIncluded, boolean>>;
|
|
31
31
|
export interface OrderPayload {
|
|
32
32
|
loading?: boolean;
|
|
@@ -83,6 +83,7 @@ export interface LineItemOption {
|
|
|
83
83
|
export interface CustomLineItem {
|
|
84
84
|
name?: string;
|
|
85
85
|
imageUrl?: string | null;
|
|
86
|
+
metadata?: Record<string, string>;
|
|
86
87
|
}
|
|
87
88
|
export type AddToCartParams = Partial<{
|
|
88
89
|
bundleCode: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.orderInitialState=exports.removeGiftCardOrCouponCode=exports.setGiftCardOrCouponCode=exports.saveAddressToCustomerAddressBook=exports.setOrderErrors=exports.unsetOrderState=exports.addToCart=exports.addResourceToInclude=exports.setOrder=exports.updateOrder=exports.getApiOrder=exports.createOrder=void 0;const tslib_1=require("tslib"),localStorage_1=require("../utils/localStorage"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importStar(require("../utils/getErrors")),organization_1=tslib_1.__importDefault(require("../utils/organization")),actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"],createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=(0,getSdk_1.default)(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=(0,getErrors_1.default)(error,"orders");console.error("Create order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""};exports.createOrder=createOrder;const getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=(0,getSdk_1.default)(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.editable===!1?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=(0,getErrors_1.default)(error,"orders");console.error("Retrieve order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch});return}};exports.getApiOrder=getApiOrder;async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=(0,getSdk_1.default)(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await(0,exports.getApiOrder)({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0,order}}catch(error){const errors=(0,getErrors_1.default)(error,"orders");return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}exports.updateOrder=updateOrder;const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};exports.setOrder=setOrder;function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...new Set([...resourcesIncluded,...resources])],resources.forEach(resource=>{const includeLoaded={...payload.includeLoaded,[resource]:!0};payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded};payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}exports.addResourceToInclude=addResourceToInclude;async function addToCart(params){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=(0,getSdk_1.default)(config),id=await(0,exports.createOrder)(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items:lineItems}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&await Promise.all(lineItems.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity??1,_update_quantity:!0,bundle_code:bundleCode},newLineItem=await sdk.line_items.create(attrs);if(lineItemOption!=null){const{skuOptionId,options,quantity:quantity2}=lineItemOption,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:quantity2??1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),await(0,exports.getApiOrder)({id,...params})}else await(0,exports.getApiOrder)({id,...params,state});if(!(0,isEmpty_1.default)(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=(0,organization_1.default)(config.endpoint??""),params2=`${id}?accessToken=${config.accessToken??""}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}}return{success:!1}}catch(error){const errors2=(0,getErrors_1.default)(error,"orders");return console.error("Add to cart",errors2),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}}exports.addToCart=addToCart;const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};exports.unsetOrderState=unsetOrderState;function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}exports.setOrderErrors=setOrderErrors;const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;(0,localStorage_1.setCustomerOrderParam)(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})};exports.saveAddressToCustomerAddressBook=saveAddressToCustomerAddressBook;async function setGiftCardOrCouponCode({code,codeType,dispatch,config,order,include,state}){try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,order:currentOrder,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success,order:currentOrder}}return{success:!1}}catch(error){const errors=(0,getErrors_1.default)(error,"orders",codeType);return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}exports.setGiftCardOrCouponCode=setGiftCardOrCouponCode;async function removeGiftCardOrCouponCode({codeType,dispatch,config,order,include,state}){try{if(config&&order&&dispatch){const attributes={[codeType]:""},orderUpdated=await updateOrder({id:order.id,attributes,config,include,dispatch,state});return dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0,order:orderUpdated?.order}}return{success:!1}}catch(error){const errors=(0,getErrors_1.default)(error,"orders",codeType);return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}exports.removeGiftCardOrCouponCode=removeGiftCardOrCouponCode,exports.orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,actionType);exports.default=orderReducer;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.orderInitialState=exports.removeGiftCardOrCouponCode=exports.setGiftCardOrCouponCode=exports.saveAddressToCustomerAddressBook=exports.setOrderErrors=exports.unsetOrderState=exports.addToCart=exports.addResourceToInclude=exports.setOrder=exports.updateOrder=exports.getApiOrder=exports.createOrder=void 0;const tslib_1=require("tslib"),localStorage_1=require("../utils/localStorage"),baseReducer_1=tslib_1.__importDefault(require("../utils/baseReducer")),isEmpty_1=tslib_1.__importDefault(require("lodash/isEmpty")),getSdk_1=tslib_1.__importDefault(require("../utils/getSdk")),getErrors_1=tslib_1.__importStar(require("../utils/getErrors")),organization_1=tslib_1.__importDefault(require("../utils/organization")),actionType=["setLoading","setOrderId","setOrder","setSingleQuantity","setCurrentSkuCodes","setCurrentSkuPrices","setErrors","setCurrentItem","setSaveAddressToCustomerAddressBook","setIncludesResource"],createOrder=async params=>{if(params){const{persistKey,state,dispatch,config,orderMetadata:metadata,orderAttributes={},setLocalOrder}=params;if(state?.orderId)return state.orderId;const sdk=(0,getSdk_1.default)(config);try{const o=await sdk?.orders.create({metadata,...orderAttributes});return dispatch&&dispatch({type:"setOrderId",payload:{orderId:o?.id}}),persistKey&&setLocalOrder&&setLocalOrder(persistKey,o.id),o.id}catch(error){const errors=(0,getErrors_1.default)(error,"orders");console.error("Create order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch})}}return""};exports.createOrder=createOrder;const getApiOrder=async params=>{const{id,dispatch,config,clearWhenPlaced,persistKey,deleteLocalOrder,state}=params,sdk=(0,getSdk_1.default)(config);try{const options={};state?.include&&state.include.length>0&&(options.include=state.include);const order=await sdk.orders.retrieve(id,options);return clearWhenPlaced&&order.editable===!1?(persistKey&&deleteLocalOrder&&deleteLocalOrder(persistKey),dispatch&&dispatch({type:"setOrder",payload:{order:void 0,orderId:""}})):dispatch&&dispatch({type:"setOrder",payload:{order,orderId:order.id}}),order}catch(error){const errors=(0,getErrors_1.default)(error,"orders");console.error("Retrieve order",errors),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors,dispatch});return}};exports.getApiOrder=getApiOrder;async function updateOrder({id,attributes,dispatch,config,include,state}){const sdk=(0,getSdk_1.default)(config);try{const resource={...attributes,id};await sdk.orders.update(resource,{include});const order=await(0,exports.getApiOrder)({id,config,dispatch,state});return dispatch&&order&&dispatch({type:"setOrder",payload:{order}}),{success:!0,order}}catch(error){const errors=(0,getErrors_1.default)(error,"orders");return dispatch&&(setOrderErrors({errors,dispatch}),dispatch({type:"setErrors",payload:{errors}})),{success:!1,error}}}exports.updateOrder=updateOrder;const setOrder=(order,dispatch)=>{dispatch&&dispatch({type:"setOrder",payload:{order}})};exports.setOrder=setOrder;function addResourceToInclude({resourcesIncluded=[],dispatch,newResource,newResourceLoaded,resourceIncludedLoaded}){const payload={include:void 0,includeLoaded:void 0};if(newResource){const resources=typeof newResource=="string"?[newResource]:newResource;payload.include=[...new Set([...resourcesIncluded,...resources])],resources.forEach(resource=>{const includeLoaded={...payload.includeLoaded,[resource]:!0};payload.includeLoaded=includeLoaded})}else delete payload.include;const payloadIncludeLoaded={...resourceIncludedLoaded,...newResourceLoaded,...payload.includeLoaded&&payload.includeLoaded};payload.includeLoaded=payloadIncludeLoaded,dispatch&&dispatch({type:"setIncludesResource",payload:{...payload,withoutIncludes:!1}})}exports.addResourceToInclude=addResourceToInclude;async function addToCart(params){const{skuCode,bundleCode,quantity,config,dispatch,lineItem,state,errors=[],buyNowMode,checkoutUrl,lineItemOption}=params;try{if(config){const sdk=(0,getSdk_1.default)(config),id=await(0,exports.createOrder)(params);if(id){const order=sdk.orders.relationship(id),name=lineItem?.name,imageUrl=lineItem?.imageUrl,metadata=lineItem?.metadata;if(buyNowMode)if(state?.order?.line_items)await Promise.all(state?.order?.line_items.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}));else{const{line_items:lineItems}=await sdk.orders.retrieve(id,{fields:["line_items"],include:["line_items"]});lineItems&&lineItems?.length>0&&await Promise.all(lineItems.map(async lineItem2=>{await sdk.line_items.delete(lineItem2.id)}))}const attrs={order,sku_code:skuCode,name,image_url:imageUrl,quantity:quantity??1,_update_quantity:!0,bundle_code:bundleCode,metadata},newLineItem=await sdk.line_items.create(attrs);if(lineItemOption!=null){const{skuOptionId,options,quantity:quantity2}=lineItemOption,skuOption=sdk.sku_options.relationship(skuOptionId),lineItemRel=sdk.line_items.relationship(newLineItem.id),lineItemOptionsAttributes={quantity:quantity2??1,options,sku_option:skuOption,line_item:lineItemRel};await sdk.line_item_options.create(lineItemOptionsAttributes),await(0,exports.getApiOrder)({id,...params})}else await(0,exports.getApiOrder)({id,...params,state});if(!(0,isEmpty_1.default)(errors)&&dispatch&&dispatch({type:"setErrors",payload:{errors:[]}}),buyNowMode){const{organization}=(0,organization_1.default)(config.endpoint??""),params2=`${id}?accessToken=${config.accessToken??""}`,redirectUrl=checkoutUrl?`${checkoutUrl}/${params2}`:`https://${organization}.checkout.commercelayer.app/${params2}`;location.href=redirectUrl}return{success:!0,orderId:id}}}return{success:!1}}catch(error){const errors2=(0,getErrors_1.default)(error,"orders");return console.error("Add to cart",errors2),dispatch&&(0,getErrors_1.setErrors)({currentErrors:state?.errors,newErrors:errors2,dispatch}),{success:!1}}}exports.addToCart=addToCart;const unsetOrderState=dispatch=>{dispatch({type:"setOrderId",payload:{orderId:""}}),dispatch({type:"setOrder",payload:{order:void 0}})};exports.unsetOrderState=unsetOrderState;function setOrderErrors({dispatch,errors=[]}){return dispatch&&dispatch({type:"setErrors",payload:{errors}}),{success:!1}}exports.setOrderErrors=setOrderErrors;const saveAddressToCustomerAddressBook=({type,value,dispatch})=>{const k=`_save_${type}_to_customer_address_book`,v=`${value.toString()}`;(0,localStorage_1.setCustomerOrderParam)(k,v),dispatch&&dispatch({type:"setSaveAddressToCustomerAddressBook",payload:{[k]:v}})};exports.saveAddressToCustomerAddressBook=saveAddressToCustomerAddressBook;async function setGiftCardOrCouponCode({code,codeType,dispatch,config,order,include,state}){try{if(config&&order&&code&&dispatch){const attributes={[codeType]:code},{success,order:currentOrder,error}=await updateOrder({id:order.id,attributes,config,include,dispatch,state});if(!success)throw error;return dispatch({type:"setErrors",payload:{errors:[]}}),{success,order:currentOrder}}return{success:!1}}catch(error){const errors=(0,getErrors_1.default)(error,"orders",codeType);return dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}exports.setGiftCardOrCouponCode=setGiftCardOrCouponCode;async function removeGiftCardOrCouponCode({codeType,dispatch,config,order,include,state}){try{if(config&&order&&dispatch){const attributes={[codeType]:""},orderUpdated=await updateOrder({id:order.id,attributes,config,include,dispatch,state});return dispatch({type:"setErrors",payload:{errors:[]}}),{success:!0,order:orderUpdated?.order}}return{success:!1}}catch(error){const errors=(0,getErrors_1.default)(error,"orders",codeType);return console.error("Remove gift card o coupon code",errors),dispatch&&setOrderErrors({errors,dispatch}),{success:!1}}}exports.removeGiftCardOrCouponCode=removeGiftCardOrCouponCode,exports.orderInitialState={loading:!0,orderId:"",order:void 0,errors:[],include:void 0,withoutIncludes:!0};const orderReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,actionType);exports.default=orderReducer;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { IconBrand } from '../context/PaymentSourceContext';
|
|
2
2
|
import { PaymentResource } from '../reducers/PaymentMethodReducer';
|
|
3
3
|
import { CustomerPaymentSource } from '@commercelayer/sdk';
|
|
4
|
-
|
|
4
|
+
interface CardDetails {
|
|
5
5
|
brand: IconBrand | string;
|
|
6
6
|
last4: string;
|
|
7
7
|
exp_month: number | string;
|
|
8
8
|
exp_year: number | string;
|
|
9
|
-
}
|
|
10
|
-
|
|
9
|
+
}
|
|
10
|
+
interface Args {
|
|
11
11
|
paymentType: PaymentResource;
|
|
12
12
|
customerPayment: Partial<CustomerPaymentSource>;
|
|
13
|
-
}
|
|
14
|
-
export default function getCardDetails({ paymentType, customerPayment
|
|
13
|
+
}
|
|
14
|
+
export default function getCardDetails({ paymentType, customerPayment }: Args): CardDetails;
|
|
15
15
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useReducer}from"react";import customerReducer,{customerInitialState,getCustomerAddresses,getCustomerOrders,getCustomerPaymentSources,setCustomerEmail,setCustomerErrors,deleteCustomerAddress,createCustomerAddress,saveCustomerUser}from"../../reducers/CustomerReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";export function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=useReducer(customerReducer,customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include,includeLoaded]),useEffect(()=>{config.accessToken&&state.addresses==null&&!isGuest&&getCustomerAddresses({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&getCustomerPaymentSources({dispatch,order}),config.accessToken
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useReducer,useMemo}from"react";import customerReducer,{customerInitialState,getCustomerAddresses,getCustomerOrders,getCustomerPaymentSources,setCustomerEmail,setCustomerErrors,deleteCustomerAddress,createCustomerAddress,saveCustomerUser,getCustomerPayments}from"../../reducers/CustomerReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import CustomerContext from"../../context/CustomerContext";export function CustomerContainer(props){const{children,isGuest=!1}=props,[state,dispatch]=useReducer(customerReducer,customerInitialState),{order,addResourceToInclude,include,updateOrder,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{!include?.includes("available_customer_payment_sources.payment_source")&&!isGuest?addResourceToInclude({newResource:"available_customer_payment_sources.payment_source"}):!includeLoaded?.["available_customer_payment_sources.payment_source"]&&!isGuest&&addResourceToInclude({newResourceLoaded:{"available_customer_payment_sources.payment_source":!0}})},[include?.length,Object.keys(includeLoaded??{}).length]),useEffect(()=>{config.accessToken&&state.addresses==null&&!isGuest&&getCustomerAddresses({config,dispatch}),order?.available_customer_payment_sources&&!isGuest&&getCustomerPaymentSources({dispatch,order}),config.accessToken&&order==null&&include==null&&includeLoaded==null&&(getCustomerOrders({config,dispatch}),getCustomerPayments({config,dispatch}))},[config.accessToken,order,isGuest]);const contextValue=useMemo(()=>({isGuest,...state,saveCustomerUser:async customerEmail=>{await saveCustomerUser({config,customerEmail,dispatch,updateOrder,order})},setCustomerErrors:errors=>setCustomerErrors(errors,dispatch),setCustomerEmail:customerEmail=>setCustomerEmail(customerEmail,dispatch),getCustomerPaymentSources:()=>getCustomerPaymentSources({dispatch,order}),deleteCustomerAddress:async({customerAddressId})=>await deleteCustomerAddress({customerAddressId,dispatch,config,addresses:state.addresses}),createCustomerAddress:async address=>await createCustomerAddress({address,config,dispatch,state})}),[state,isGuest]);return _jsx(CustomerContext.Provider,{value:contextValue,children})}export default CustomerContainer;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DefaultChildrenType } from '../../typings/globals';
|
|
2
|
+
interface Props {
|
|
3
|
+
children?: DefaultChildrenType;
|
|
4
|
+
/**
|
|
5
|
+
* Customize the loader content.
|
|
6
|
+
*/
|
|
7
|
+
loader?: string | JSX.Element;
|
|
8
|
+
}
|
|
9
|
+
export declare function CustomerPaymentSource({ children, loader }: Props): JSX.Element;
|
|
10
|
+
export default CustomerPaymentSource;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import CustomerContext from"../../context/CustomerContext";import CustomerPaymentSourceContext from"../../context/CustomerPaymentSourceContext";import getCardDetails from"../../utils/getCardDetails";import useCustomContext from"../../utils/hooks/useCustomContext";import{useEffect,useState}from"react";export function CustomerPaymentSource({children,loader="Loading..."}){const[loading,setLoading]=useState(!0),{payments}=useCustomContext({context:CustomerContext,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSource",key:"payments"});useEffect(()=>(payments!=null&&setLoading(!1),()=>{setLoading(!0)}),[payments!=null]);const provider=payments?.filter(p=>p?.payment_source!=null).map(p=>{const paymentType=p.payment_source?.type,value={...getCardDetails({paymentType,customerPayment:p})};return _jsx(CustomerPaymentSourceContext.Provider,{value,children},p.id)});return loading?_jsx(_Fragment,{children:loader}):_jsx(_Fragment,{children:provider})}export default CustomerPaymentSource;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ChildrenFunction } from '../../typings/index';
|
|
2
|
+
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
3
|
+
/**
|
|
4
|
+
* Function allow you to customize the component
|
|
5
|
+
*/
|
|
6
|
+
children?: ChildrenFunction<Omit<Props, 'children'>>;
|
|
7
|
+
/**
|
|
8
|
+
* Label to show. Default: 'No payments available.'
|
|
9
|
+
*/
|
|
10
|
+
emptyText?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function CustomerPaymentSourceEmpty({ children, emptyText, ...p }: Props): JSX.Element | null;
|
|
13
|
+
export default CustomerPaymentSourceEmpty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import CustomerContext from"../../context/CustomerContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function CustomerPaymentSourceEmpty({children,emptyText="No payments available",...p}){const{payments}=useCustomContext({context:CustomerContext,contextComponentName:"CustomerContainer",currentComponentName:"CustomerPaymentSourceEmpty",key:"payments"}),parentProps={emptyText,...p};return payments!=null&&payments.length>0||payments===null?null:children!==void 0?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:emptyText})}export default CustomerPaymentSourceEmpty;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import PlaceOrderContext from"../../context/PlaceOrderContext";import{useContext,useEffect,useReducer}from"react";import placeOrderReducer,{placeOrderInitialState,placeOrderPermitted,setButtonRef}from"../../reducers/PlaceOrderReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import{setPlaceOrder}from"../../reducers/PlaceOrderReducer";import useCustomContext from"../../utils/hooks/useCustomContext";export function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=useReducer(placeOrderReducer,placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import PlaceOrderContext from"../../context/PlaceOrderContext";import{useContext,useEffect,useReducer}from"react";import placeOrderReducer,{placeOrderInitialState,placeOrderPermitted,setButtonRef}from"../../reducers/PlaceOrderReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import{setPlaceOrder}from"../../reducers/PlaceOrderReducer";import useCustomContext from"../../utils/hooks/useCustomContext";export function PlaceOrderContainer(props){const{children,options}=props,[state,dispatch]=useReducer(placeOrderReducer,placeOrderInitialState),{order,setOrder,setOrderErrors,include,addResourceToInclude,includeLoaded}=useCustomContext({context:OrderContext,contextComponentName:"OrderContainer",currentComponentName:"PlaceOrderContainer",key:"order"}),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location"]}),include?.includes("billing_address")?includeLoaded?.billing_address||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),include?.includes("shipping_address")?includeLoaded?.shipping_address||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address",resourcesIncluded:include}),order&&placeOrderPermitted({config,dispatch,order,options:{...options}})},[order,include,includeLoaded]);const contextValue={...state,setPlaceOrder:async({paymentSource})=>await setPlaceOrder({config,order,state,setOrderErrors,paymentSource,include,setOrder}),placeOrderPermitted:()=>placeOrderPermitted({config,dispatch,order,options:{...options}}),setButtonRef:ref=>setButtonRef(ref,dispatch)};return _jsx(PlaceOrderContext.Provider,{value:contextValue,children})}export default PlaceOrderContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../../context/PaymentSourceContext";import{useContext,useRef}from"react";import Parent from"../utils/Parent";export function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=useContext(PaymentSourceContext),ref=useRef(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../../context/PaymentSourceContext";import{useContext,useRef}from"react";import Parent from"../utils/Parent";import CustomerPaymentSourceContext from"../../context/CustomerPaymentSourceContext";export function PaymentSourceBrandIcon({src,width=32,children,...p}){const{brand}=useContext(PaymentSourceContext),{brand:customerCardBrand}=useContext(CustomerPaymentSourceContext),cardBrand=brand??customerCardBrand,ref=useRef(null),defaultSrc="//data.commercelayer.app/assets/images/icons/credit-cards/color/credit-card.svg",url=src||`//data.commercelayer.app/assets/images/icons/credit-cards/color/${cardBrand??"credit-card"}.svg`,handleError=()=>{ref.current&&(ref.current.src=defaultSrc)},parentProps={brand:cardBrand,defaultSrc,url,width,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("img",{ref,src:url,onError:handleError,width,...p})}export default PaymentSourceBrandIcon;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../../context/PaymentSourceContext";import
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../../context/PaymentSourceContext";import capitalize from"lodash/capitalize";import{useContext}from"react";import Parent from"../utils/Parent";import CustomerPaymentSourceContext from"../../context/CustomerPaymentSourceContext";export function PaymentSourceBrandName({children,label,...props}){const{brand}=useContext(PaymentSourceContext),{brand:customerCardBrand}=useContext(CustomerPaymentSourceContext),cardBrand=brand??customerCardBrand,brandName=cardBrand&&capitalize(cardBrand.replaceAll(/_|-/gm," ")),parentProps={brand:brandName,label,...props};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...props,children:label||capitalize(brandName)})}export default PaymentSourceBrandName;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { ChildrenFunction } from '../../typings/index';
|
|
1
|
+
import type { ChildrenFunction } from '../../typings/index';
|
|
2
2
|
export type PaymentSourceDetailType = 'last4' | 'exp_year' | 'exp_month';
|
|
3
3
|
interface ChildrenProps extends Omit<Props, 'children'> {
|
|
4
4
|
text: string;
|
|
5
5
|
}
|
|
6
6
|
interface Props extends Omit<JSX.IntrinsicElements['span'], 'children'> {
|
|
7
7
|
children?: ChildrenFunction<ChildrenProps>;
|
|
8
|
+
/**
|
|
9
|
+
* Type of detail to display
|
|
10
|
+
*/
|
|
8
11
|
type: PaymentSourceDetailType;
|
|
9
12
|
}
|
|
10
13
|
export declare function PaymentSourceDetail({ type, children, ...p }: Props): JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../../context/PaymentSourceContext";import{
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import PaymentSourceContext from"../../context/PaymentSourceContext";import{useContext}from"react";import Parent from"../utils/Parent";import CustomerPaymentSourceContext from"../../context/CustomerPaymentSourceContext";export function PaymentSourceDetail({type,children,...p}){const card=useContext(PaymentSourceContext),customerCard=useContext(CustomerPaymentSourceContext),cardObj=card??customerCard,text=type in cardObj?cardObj[type]:type==="last4"?"****":"**",parentProps={type,text,...p};return children?_jsx(Parent,{...parentProps,children}):_jsx("span",{...p,children:text})}export default PaymentSourceDetail;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShipmentContext from"../../context/ShipmentContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import getLoaderComponent from"../../utils/getLoaderComponent";import OrderContext from"../../context/OrderContext";export function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=useState(!0),{shipments,deliveryLeadTimes,setShippingMethod}=useContext(ShipmentContext),{order}=useContext(OrderContext);useEffect(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.
|
|
1
|
+
import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShipmentContext from"../../context/ShipmentContext";import ShipmentChildrenContext from"../../context/ShipmentChildrenContext";import getLoaderComponent from"../../utils/getLoaderComponent";import OrderContext from"../../context/OrderContext";export function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=useState(!0),{shipments,deliveryLeadTimes,setShippingMethod}=useContext(ShipmentContext),{order}=useContext(OrderContext);useEffect(()=>(shipments!=null&&(autoSelectSingleShippingMethod?(async()=>{for(const shipment of shipments){const isSingle=shipment?.available_shipping_methods?.length===1;if(!shipment?.shipping_method&&isSingle){const[shippingMethod]=shipment?.available_shipping_methods||[];if(shippingMethod&&setShippingMethod!=null){const{success,order:order2}=await setShippingMethod(shipment.id,shippingMethod.id);typeof autoSelectSingleShippingMethod=="function"&&success&&autoSelectSingleShippingMethod(order2)}}else setTimeout(()=>{setLoading(!1)},200)}})():setLoading(!1)),()=>{setLoading(!0)}),[shipments!=null,shipments?.length,order?.gift_card_or_coupon_code]);const components=shipments?.map((shipment,k)=>{const lineItems=shipment.stock_line_items?.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0]?.id:shipment.shipping_method?.id,stockTransfers=shipment.stock_transfers,parcels=shipment.parcels,times=deliveryLeadTimes?.filter(time=>time.stock_location?.id===shipment.stock_location?.id),shipmentProps={parcels,lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return _jsx(ShipmentChildrenContext.Provider,{value:shipmentProps,children},k)});return loading?getLoaderComponent(loader):_jsx(_Fragment,{children:components})}export default Shipment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import ShipmentContext,{defaultShipmentContext}from"../../context/ShipmentContext";import{useContext,useEffect,useMemo,useReducer}from"react";import shipmentReducer,{shipmentInitialState,setShipmentErrors,getShipments,setShippingMethod}from"../../reducers/ShipmentReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import isEmpty from"lodash/isEmpty";export function ShipmentsContainer(props){const{children}=props,[state,dispatch]=useReducer(shipmentReducer,shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import ShipmentContext,{defaultShipmentContext}from"../../context/ShipmentContext";import{useContext,useEffect,useMemo,useReducer}from"react";import shipmentReducer,{shipmentInitialState,setShipmentErrors,getShipments,setShippingMethod}from"../../reducers/ShipmentReducer";import OrderContext from"../../context/OrderContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import isEmpty from"lodash/isEmpty";export function ShipmentsContainer(props){const{children}=props,[state,dispatch]=useReducer(shipmentReducer,shipmentInitialState),{order,getOrder,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>{include?.includes("shipments.available_shipping_methods")?includeLoaded?.["shipments.available_shipping_methods"]||addResourceToInclude({newResourceLoaded:{"shipments.available_shipping_methods":!0,"shipments.stock_line_items.line_item":!0,"shipments.shipping_method":!0,"shipments.stock_transfers.line_item":!0,"shipments.stock_location":!0,"shipments.parcels.parcel_line_items":!0}}):addResourceToInclude({newResource:["shipments.available_shipping_methods","shipments.stock_line_items.line_item","shipments.shipping_method","shipments.stock_transfers.line_item","shipments.stock_location","shipments.parcels.parcel_line_items"]})},[include?.length,includeLoaded!=null]),useEffect(()=>{order!=null&&!isEmpty(config)&&order.shipments&&getShipments({order,dispatch,config})},[order!=null,order?.shipments?.length]),useEffect(()=>(order&&(order.shipments&&order.shipments.length>0&&order.shipments.map(shipment=>shipment.available_shipping_methods&&shipment.available_shipping_methods.length>0).includes(!1)&&setShipmentErrors([...state.errors||[],{code:"NO_SHIPPING_METHODS",message:"No shipping methods",resource:"shipments"}],dispatch),order.line_items&&order.line_items.length>0&&order.line_items.filter(({item_type:itemType})=>itemType==="skus").map(lineItem=>!!(lineItem.item?.do_not_ship||lineItem.item?.do_not_track||lineItem.item?.inventory?.quantity>=lineItem?.quantity)).includes(!1)&&setShipmentErrors([...state.errors||[],{code:"OUT_OF_STOCK",message:"No stock available",resource:"line_items"}],dispatch)),()=>{setShipmentErrors([],dispatch)}),[order?.shipments]);const contextValue=useMemo(()=>({...state,setShipmentErrors:errors=>defaultShipmentContext.setShipmentErrors(errors,dispatch),setShippingMethod:async(shipmentId,shippingMethodId)=>await setShippingMethod({shippingMethodId,shipmentId,config,getOrder,order})}),[state]);return _jsx(ShipmentContext.Provider,{value:contextValue,children})}export default ShipmentsContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect}from"react";import availabilityReducer,{availabilityInitialState,getAvailability}from"../../reducers/AvailabilityReducer";import AvailabilityContext from"../../context/AvailabilityContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=useContext(LineItemChildrenContext),{sku}=useContext(SkuChildrenContext),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useReducer,useEffect,useMemo}from"react";import availabilityReducer,{availabilityInitialState,getAvailability}from"../../reducers/AvailabilityReducer";import AvailabilityContext from"../../context/AvailabilityContext";import CommerceLayerContext from"../../context/CommerceLayerContext";import LineItemChildrenContext from"../../context/LineItemChildrenContext";import SkuChildrenContext from"../../context/SkuChildrenContext";import useCustomContext from"../../utils/hooks/useCustomContext";export function AvailabilityContainer({children,skuCode,getQuantity}){const{lineItem}=useContext(LineItemChildrenContext),{sku}=useContext(SkuChildrenContext),{accessToken,endpoint}=useCustomContext({context:CommerceLayerContext,contextComponentName:"CommerceLayer",currentComponentName:"AvailabilityContainer",key:"accessToken"}),[state,dispatch]=useReducer(availabilityReducer,availabilityInitialState),sCode=skuCode||lineItem?.sku_code||sku?.code;useEffect(()=>(accessToken!=null&&accessToken!==""&&sCode&&getAvailability({skuCode:sCode,config:{accessToken,endpoint},dispatch}),()=>{dispatch({type:"setAvailability",payload:{}})}),[accessToken,sCode]),useEffect(()=>{getQuantity!=null&&state?.quantity!=null&&getQuantity(state?.quantity)},[state.quantity]);const memoized=useMemo(()=>({...state,parent:!0}),[state]);return _jsx(AvailabilityContext.Provider,{value:memoized,children})}export default AvailabilityContainer;
|