@commercelayer/react-components 2.50.3 → 2.50.4

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=(0,tslib_1.__importDefault)(require("./utils/Parent")),components_1=(0,tslib_1.__importDefault)(require("../config/components")),OrderContext_1=(0,tslib_1.__importDefault)(require("../context/OrderContext")),lodash_1=require("lodash"),propTypes=components_1.default.GiftCardOrCouponRemoveButton.propTypes,displayName=components_1.default.GiftCardOrCouponRemoveButton.displayName,GiftCardOrCouponRemoveButton=props=>{const{children,label="Remove",onClick,type}=props,p=(0,tslib_1.__rest)(props,["children","label","onClick","type"]),{order,removeGiftCardOrCouponCode}=(0,react_1.useContext)(OrderContext_1.default);let codeType=`${type}Code`;!type&&order&&(0,lodash_1.has)(order,"couponCode")&&!(0,lodash_1.isEmpty)(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=()=>{removeGiftCardOrCouponCode&&removeGiftCardOrCouponCode({codeType}),onClick&&onClick()},parentProps=Object.assign(Object.assign({},p),{label,handleClick,codeType});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children}),void 0):hide?null:(0,jsx_runtime_1.jsx)("button",Object.assign({type:"button",onClick:handleClick},p,{children:label}),void 0)};GiftCardOrCouponRemoveButton.propTypes=propTypes,GiftCardOrCouponRemoveButton.displayName=displayName,exports.default=GiftCardOrCouponRemoveButton;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),react_1=require("react"),Parent_1=(0,tslib_1.__importDefault)(require("./utils/Parent")),components_1=(0,tslib_1.__importDefault)(require("../config/components")),OrderContext_1=(0,tslib_1.__importDefault)(require("../context/OrderContext")),lodash_1=require("lodash"),propTypes=components_1.default.GiftCardOrCouponRemoveButton.propTypes,displayName=components_1.default.GiftCardOrCouponRemoveButton.displayName,GiftCardOrCouponRemoveButton=props=>{const{children,label="Remove",onClick,type}=props,p=(0,tslib_1.__rest)(props,["children","label","onClick","type"]),{order,removeGiftCardOrCouponCode}=(0,react_1.useContext)(OrderContext_1.default);let codeType=`${type}_code`;!type&&order&&(0,lodash_1.has)(order,"coupon_code")&&!(0,lodash_1.isEmpty)(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=()=>{removeGiftCardOrCouponCode&&removeGiftCardOrCouponCode({codeType}),onClick&&onClick()},parentProps=Object.assign(Object.assign({},p),{label,handleClick,codeType});return children?(0,jsx_runtime_1.jsx)(Parent_1.default,Object.assign({},parentProps,{children}),void 0):hide?null:(0,jsx_runtime_1.jsx)("button",Object.assign({type:"button",onClick:handleClick},p,{children:label}),void 0)};GiftCardOrCouponRemoveButton.propTypes=propTypes,GiftCardOrCouponRemoveButton.displayName=displayName,exports.default=GiftCardOrCouponRemoveButton;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setPlaceOrder=exports.placeOrderPermitted=exports.setPlaceOrderErrors=exports.placeOrderInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=(0,tslib_1.__importDefault)(require("../utils/baseReducer")),isEmpty_1=(0,tslib_1.__importDefault)(require("lodash/isEmpty")),shipments_1=require("../utils/shipments"),customerOrderOptions_1=require("../utils/customerOrderOptions"),getSdk_1=(0,tslib_1.__importDefault)(require("../utils/getSdk")),getErrors_1=(0,tslib_1.__importDefault)(require("../utils/getErrors"));exports.placeOrderInitialState={errors:[],isPermitted:!1};const setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})};exports.setPlaceOrderErrors=setPlaceOrderErrors;const placeOrderPermitted=async({config,order,dispatch,options})=>{var _a;if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address;(0,isEmpty_1.default)(billingAddress)&&(isPermitted=!1);const shippingAddress=order.shipping_address;(0,isEmpty_1.default)(shippingAddress)&&(isPermitted=!1);const shipments=order.shipments,shipment=shipments&&(0,shipments_1.shipmentsFilled)(shipments);!(0,isEmpty_1.default)(shipments)&&!shipment&&(isPermitted=!1);const paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&(0,isEmpty_1.default)(paymentMethod==null?void 0:paymentMethod.id)&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSecret:paymentSource==null?void 0:paymentSource.client_secret,paymentId:(_a=paymentSource==null?void 0:paymentSource.options)===null||_a===void 0?void 0:_a.id,paymentSource,options}})}};exports.placeOrderPermitted=placeOrderPermitted;const setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource})=>{const response={placed:!1};try{if(state&&order&&config&&paymentSource){const sdk=(0,getSdk_1.default)(config),{options,paymentType}=state;if(paymentType==="paypal_payments"){if(!(options==null?void 0:options.paypalPayerId)&&(paymentSource==null?void 0:paymentSource.approval_url))return window.location.href=paymentSource==null?void 0:paymentSource.approval_url,response;await sdk.paypal_payments.update({id:paymentSource.id,paypal_payer_id:options==null?void 0:options.paypalPayerId})}const updateAttributes={id:order.id,_place:!0};switch((0,customerOrderOptions_1.saveBillingAddress)()&&await sdk.orders.update({id:order.id,_save_billing_address_to_customer_address_book:!0}),(0,customerOrderOptions_1.saveShippingAddress)()&&await sdk.orders.update({id:order.id,_save_shipping_address_to_customer_address_book:!0}),paymentType){case"braintree_payments":return(0,customerOrderOptions_1.saveToWallet)()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0};default:return(0,customerOrderOptions_1.saveToWallet)()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0}}}return response}catch(error){const errors=(0,getErrors_1.default)(error,"orders");return setOrderErrors&&setOrderErrors(errors),Object.assign(Object.assign({},response),{errors})}};exports.setPlaceOrder=setPlaceOrder;const type=["setErrors","setPlaceOrderPermitted"],placeOrderReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=placeOrderReducer;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setPlaceOrder=exports.placeOrderPermitted=exports.setPlaceOrderErrors=exports.placeOrderInitialState=void 0;const tslib_1=require("tslib"),baseReducer_1=(0,tslib_1.__importDefault)(require("../utils/baseReducer")),isEmpty_1=(0,tslib_1.__importDefault)(require("lodash/isEmpty")),shipments_1=require("../utils/shipments"),customerOrderOptions_1=require("../utils/customerOrderOptions"),getSdk_1=(0,tslib_1.__importDefault)(require("../utils/getSdk")),getErrors_1=(0,tslib_1.__importDefault)(require("../utils/getErrors"));exports.placeOrderInitialState={errors:[],isPermitted:!1};const setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})};exports.setPlaceOrderErrors=setPlaceOrderErrors;const placeOrderPermitted=async({config,order,dispatch,options})=>{var _a;if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address;(0,isEmpty_1.default)(billingAddress)&&(isPermitted=!1);const shippingAddress=order.shipping_address;(0,isEmpty_1.default)(shippingAddress)&&(isPermitted=!1);const shipments=order.shipments,shipment=shipments&&(0,shipments_1.shipmentsFilled)(shipments);!(0,isEmpty_1.default)(shipments)&&!shipment&&(isPermitted=!1);const paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&(0,isEmpty_1.default)(paymentMethod==null?void 0:paymentMethod.id)&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSecret:paymentSource==null?void 0:paymentSource.client_secret,paymentId:(_a=paymentSource==null?void 0:paymentSource.options)===null||_a===void 0?void 0:_a.id,paymentSource,options}})}};exports.placeOrderPermitted=placeOrderPermitted;const setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource})=>{const response={placed:!1};try{if(state&&order&&config){const sdk=(0,getSdk_1.default)(config),{options,paymentType}=state;if(paymentType==="paypal_payments"&&paymentSource){if(!(options==null?void 0:options.paypalPayerId)&&(paymentSource==null?void 0:paymentSource.approval_url))return window.location.href=paymentSource==null?void 0:paymentSource.approval_url,response;await sdk.paypal_payments.update({id:paymentSource.id,paypal_payer_id:options==null?void 0:options.paypalPayerId})}const updateAttributes={id:order.id,_place:!0};switch((0,customerOrderOptions_1.saveBillingAddress)()&&await sdk.orders.update({id:order.id,_save_billing_address_to_customer_address_book:!0}),(0,customerOrderOptions_1.saveShippingAddress)()&&await sdk.orders.update({id:order.id,_save_shipping_address_to_customer_address_book:!0}),paymentType){case"braintree_payments":return(0,customerOrderOptions_1.saveToWallet)()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0};default:return(0,customerOrderOptions_1.saveToWallet)()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0}}}return response}catch(error){const errors=(0,getErrors_1.default)(error,"orders");return setOrderErrors&&setOrderErrors(errors),Object.assign(Object.assign({},response),{errors})}};exports.setPlaceOrder=setPlaceOrder;const type=["setErrors","setPlaceOrderPermitted"],placeOrderReducer=(state,reducer)=>(0,baseReducer_1.default)(state,reducer,type);exports.default=placeOrderReducer;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.countryLockController=exports.shippingAddressController=exports.billingAddressController=void 0;const lodash_1=require("lodash"),validateFormFields_1=require("./validateFormFields"),AddressReducer_1=require("../reducers/AddressReducer"),billingAddressController=({billing_address,billingAddressId,errors,requiresBillingInfo})=>{let billingDisable=!(0,lodash_1.isEmpty)(errors)||(0,lodash_1.isEmpty)(billing_address);if((0,lodash_1.isEmpty)(errors)&&!(0,lodash_1.isEmpty)(billing_address)){let billingInfo=[...AddressReducer_1.addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),billingDisable=!!(billing_address&&(0,validateFormFields_1.fieldsExist)(billing_address,billingInfo))}return billingDisable&&!(0,lodash_1.isEmpty)(billingAddressId)&&(0,lodash_1.isEmpty)(billing_address)&&(billingDisable=!1),billingDisable};exports.billingAddressController=billingAddressController;const shippingAddressController=({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId})=>{let shippingDisable=!!(!billingDisable&&shipToDifferentAddress);return shippingDisable&&(0,lodash_1.isEmpty)(errors)&&!(0,lodash_1.isEmpty)(shipping_address)&&(shippingDisable=!!(shipping_address&&(0,validateFormFields_1.fieldsExist)(shipping_address))),shippingDisable&&!(0,lodash_1.isEmpty)(shippingAddressId)&&(0,lodash_1.isEmpty)(shipping_address)&&(shippingDisable=!1),shippingDisable};exports.shippingAddressController=shippingAddressController;const countryLockController=({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId})=>{if(countryCodeLock&&!(0,lodash_1.isEmpty)(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===billingAddressId||a.reference===billingAddressId)&&a.countryCode!==countryCodeLock);if(!(0,lodash_1.isEmpty)(addressLocked))return!0}if(countryCodeLock&&!(0,lodash_1.isEmpty)(billing_address)&&!shipToDifferentAddress)return(billing_address==null?void 0:billing_address.country_code)!==countryCodeLock;if(countryCodeLock&&!(0,lodash_1.isEmpty)(shipping_address)&&shipToDifferentAddress)return(shipping_address==null?void 0:shipping_address.country_code)!==countryCodeLock;if(countryCodeLock&&!(0,lodash_1.isEmpty)(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===shippingAddressId||a.reference===shippingAddressId)&&a.countryCode!==countryCodeLock);if(!(0,lodash_1.isEmpty)(addressLocked))return!0}return!1};exports.countryLockController=countryLockController;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.countryLockController=exports.shippingAddressController=exports.billingAddressController=void 0;const lodash_1=require("lodash"),validateFormFields_1=require("./validateFormFields"),AddressReducer_1=require("../reducers/AddressReducer"),billingAddressController=({billing_address,billingAddressId,errors,requiresBillingInfo})=>{let billingDisable=!(0,lodash_1.isEmpty)(errors)||(0,lodash_1.isEmpty)(billing_address);if((0,lodash_1.isEmpty)(errors)&&!(0,lodash_1.isEmpty)(billing_address)){let billingInfo=[...AddressReducer_1.addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),billingDisable=!!(billing_address&&(0,validateFormFields_1.fieldsExist)(billing_address,billingInfo))}return billingDisable&&!(0,lodash_1.isEmpty)(billingAddressId)&&(0,lodash_1.isEmpty)(billing_address)&&(billingDisable=!1),billingDisable};exports.billingAddressController=billingAddressController;const shippingAddressController=({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId})=>{let shippingDisable=!!(!billingDisable&&shipToDifferentAddress);return shippingDisable&&(0,lodash_1.isEmpty)(errors)&&!(0,lodash_1.isEmpty)(shipping_address)&&(shippingDisable=!!(shipping_address&&(0,validateFormFields_1.fieldsExist)(shipping_address))),shippingDisable&&!(0,lodash_1.isEmpty)(shippingAddressId)&&(0,lodash_1.isEmpty)(shipping_address)&&(shippingDisable=!1),shippingDisable};exports.shippingAddressController=shippingAddressController;const countryLockController=({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId})=>{if(countryCodeLock&&!(0,lodash_1.isEmpty)(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===billingAddressId||a.reference===billingAddressId)&&a.country_code!==countryCodeLock);if(!(0,lodash_1.isEmpty)(addressLocked))return!0}if(countryCodeLock&&!(0,lodash_1.isEmpty)(billing_address)&&!shipToDifferentAddress)return(billing_address==null?void 0:billing_address.country_code)!==countryCodeLock;if(countryCodeLock&&!(0,lodash_1.isEmpty)(shipping_address)&&shipToDifferentAddress)return(shipping_address==null?void 0:shipping_address.country_code)!==countryCodeLock;if(countryCodeLock&&!(0,lodash_1.isEmpty)(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===shippingAddressId||a.reference===shippingAddressId)&&a.country_code!==countryCodeLock);if(!(0,lodash_1.isEmpty)(addressLocked))return!0}return!1};exports.countryLockController=countryLockController;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import OrderContext from"../context/OrderContext";import{has,isEmpty}from"lodash";const propTypes=components.GiftCardOrCouponRemoveButton.propTypes,displayName=components.GiftCardOrCouponRemoveButton.displayName,GiftCardOrCouponRemoveButton=props=>{const{children,label="Remove",onClick,type}=props,p=__rest(props,["children","label","onClick","type"]),{order,removeGiftCardOrCouponCode}=useContext(OrderContext);let codeType=`${type}Code`;!type&&order&&has(order,"couponCode")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=()=>{removeGiftCardOrCouponCode&&removeGiftCardOrCouponCode({codeType}),onClick&&onClick()},parentProps=Object.assign(Object.assign({},p),{label,handleClick,codeType});return children?_jsx(Parent,Object.assign({},parentProps,{children}),void 0):hide?null:_jsx("button",Object.assign({type:"button",onClick:handleClick},p,{children:label}),void 0)};GiftCardOrCouponRemoveButton.propTypes=propTypes,GiftCardOrCouponRemoveButton.displayName=displayName;export default GiftCardOrCouponRemoveButton;
1
+ import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import Parent from"./utils/Parent";import components from"../config/components";import OrderContext from"../context/OrderContext";import{has,isEmpty}from"lodash";const propTypes=components.GiftCardOrCouponRemoveButton.propTypes,displayName=components.GiftCardOrCouponRemoveButton.displayName,GiftCardOrCouponRemoveButton=props=>{const{children,label="Remove",onClick,type}=props,p=__rest(props,["children","label","onClick","type"]),{order,removeGiftCardOrCouponCode}=useContext(OrderContext);let codeType=`${type}_code`;!type&&order&&has(order,"coupon_code")&&!isEmpty(order.coupon_code)?codeType="coupon_code":type||(codeType="gift_card_code");const code=order&&codeType?order[codeType]:"",hide=!(order&&code),handleClick=()=>{removeGiftCardOrCouponCode&&removeGiftCardOrCouponCode({codeType}),onClick&&onClick()},parentProps=Object.assign(Object.assign({},p),{label,handleClick,codeType});return children?_jsx(Parent,Object.assign({},parentProps,{children}),void 0):hide?null:_jsx("button",Object.assign({type:"button",onClick:handleClick},p,{children:label}),void 0)};GiftCardOrCouponRemoveButton.propTypes=propTypes,GiftCardOrCouponRemoveButton.displayName=displayName;export default GiftCardOrCouponRemoveButton;
@@ -1 +1 @@
1
- import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:!1},setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},placeOrderPermitted=async({config,order,dispatch,options})=>{var _a;if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address;isEmpty(billingAddress)&&(isPermitted=!1);const shippingAddress=order.shipping_address;isEmpty(shippingAddress)&&(isPermitted=!1);const shipments=order.shipments,shipment=shipments&&shipmentsFilled(shipments);!isEmpty(shipments)&&!shipment&&(isPermitted=!1);const paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&isEmpty(paymentMethod==null?void 0:paymentMethod.id)&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSecret:paymentSource==null?void 0:paymentSource.client_secret,paymentId:(_a=paymentSource==null?void 0:paymentSource.options)===null||_a===void 0?void 0:_a.id,paymentSource,options}})}},setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource})=>{const response={placed:!1};try{if(state&&order&&config&&paymentSource){const sdk=getSdk(config),{options,paymentType}=state;if(paymentType==="paypal_payments"){if(!(options==null?void 0:options.paypalPayerId)&&(paymentSource==null?void 0:paymentSource.approval_url))return window.location.href=paymentSource==null?void 0:paymentSource.approval_url,response;await sdk.paypal_payments.update({id:paymentSource.id,paypal_payer_id:options==null?void 0:options.paypalPayerId})}const updateAttributes={id:order.id,_place:!0};switch(saveBillingAddress()&&await sdk.orders.update({id:order.id,_save_billing_address_to_customer_address_book:!0}),saveShippingAddress()&&await sdk.orders.update({id:order.id,_save_shipping_address_to_customer_address_book:!0}),paymentType){case"braintree_payments":return saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0};default:return saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0}}}return response}catch(error){const errors=getErrors(error,"orders");return setOrderErrors&&setOrderErrors(errors),Object.assign(Object.assign({},response),{errors})}};const type=["setErrors","setPlaceOrderPermitted"],placeOrderReducer=(state,reducer)=>baseReducer(state,reducer,type);export default placeOrderReducer;
1
+ import baseReducer from"../utils/baseReducer";import isEmpty from"lodash/isEmpty";import{shipmentsFilled}from"../utils/shipments";import{saveBillingAddress,saveShippingAddress,saveToWallet}from"../utils/customerOrderOptions";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const placeOrderInitialState={errors:[],isPermitted:!1},setPlaceOrderErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},placeOrderPermitted=async({config,order,dispatch,options})=>{var _a;if(order&&config){let isPermitted=!0;order.privacy_url&&order.terms_url&&(isPermitted=localStorage.getItem("privacy-terms")==="true");const billingAddress=order.billing_address;isEmpty(billingAddress)&&(isPermitted=!1);const shippingAddress=order.shipping_address;isEmpty(shippingAddress)&&(isPermitted=!1);const shipments=order.shipments,shipment=shipments&&shipmentsFilled(shipments);!isEmpty(shipments)&&!shipment&&(isPermitted=!1);const paymentMethod=order.payment_method,paymentSource=order.payment_source;order.total_amount_with_taxes_cents!==0&&isEmpty(paymentMethod==null?void 0:paymentMethod.id)&&(isPermitted=!1),dispatch({type:"setPlaceOrderPermitted",payload:{isPermitted,paymentType:paymentMethod==null?void 0:paymentMethod.payment_source_type,paymentSecret:paymentSource==null?void 0:paymentSource.client_secret,paymentId:(_a=paymentSource==null?void 0:paymentSource.options)===null||_a===void 0?void 0:_a.id,paymentSource,options}})}},setPlaceOrder=async({state,order,config,setOrderErrors,paymentSource})=>{const response={placed:!1};try{if(state&&order&&config){const sdk=getSdk(config),{options,paymentType}=state;if(paymentType==="paypal_payments"&&paymentSource){if(!(options==null?void 0:options.paypalPayerId)&&(paymentSource==null?void 0:paymentSource.approval_url))return window.location.href=paymentSource==null?void 0:paymentSource.approval_url,response;await sdk.paypal_payments.update({id:paymentSource.id,paypal_payer_id:options==null?void 0:options.paypalPayerId})}const updateAttributes={id:order.id,_place:!0};switch(saveBillingAddress()&&await sdk.orders.update({id:order.id,_save_billing_address_to_customer_address_book:!0}),saveShippingAddress()&&await sdk.orders.update({id:order.id,_save_shipping_address_to_customer_address_book:!0}),paymentType){case"braintree_payments":return saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0};default:return saveToWallet()&&await sdk.orders.update({id:order.id,_save_payment_source_to_customer_wallet:!0}),await sdk.orders.update(updateAttributes),setOrderErrors&&setOrderErrors([]),{placed:!0}}}return response}catch(error){const errors=getErrors(error,"orders");return setOrderErrors&&setOrderErrors(errors),Object.assign(Object.assign({},response),{errors})}};const type=["setErrors","setPlaceOrderPermitted"],placeOrderReducer=(state,reducer)=>baseReducer(state,reducer,type);export default placeOrderReducer;
@@ -1 +1 @@
1
- import{isEmpty}from"lodash";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export const billingAddressController=({billing_address,billingAddressId,errors,requiresBillingInfo})=>{let billingDisable=!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address)){let billingInfo=[...addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),billingDisable=!!(billing_address&&fieldsExist(billing_address,billingInfo))}return billingDisable&&!isEmpty(billingAddressId)&&isEmpty(billing_address)&&(billingDisable=!1),billingDisable},shippingAddressController=({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId})=>{let shippingDisable=!!(!billingDisable&&shipToDifferentAddress);return shippingDisable&&isEmpty(errors)&&!isEmpty(shipping_address)&&(shippingDisable=!!(shipping_address&&fieldsExist(shipping_address))),shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable},countryLockController=({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId})=>{if(countryCodeLock&&!isEmpty(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===billingAddressId||a.reference===billingAddressId)&&a.countryCode!==countryCodeLock);if(!isEmpty(addressLocked))return!0}if(countryCodeLock&&!isEmpty(billing_address)&&!shipToDifferentAddress)return(billing_address==null?void 0:billing_address.country_code)!==countryCodeLock;if(countryCodeLock&&!isEmpty(shipping_address)&&shipToDifferentAddress)return(shipping_address==null?void 0:shipping_address.country_code)!==countryCodeLock;if(countryCodeLock&&!isEmpty(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===shippingAddressId||a.reference===shippingAddressId)&&a.countryCode!==countryCodeLock);if(!isEmpty(addressLocked))return!0}return!1};
1
+ import{isEmpty}from"lodash";import{fieldsExist}from"./validateFormFields";import{addressFields}from"../reducers/AddressReducer";export const billingAddressController=({billing_address,billingAddressId,errors,requiresBillingInfo})=>{let billingDisable=!isEmpty(errors)||isEmpty(billing_address);if(isEmpty(errors)&&!isEmpty(billing_address)){let billingInfo=[...addressFields];requiresBillingInfo&&(billingInfo=[...billingInfo,"billing_info"]),billingDisable=!!(billing_address&&fieldsExist(billing_address,billingInfo))}return billingDisable&&!isEmpty(billingAddressId)&&isEmpty(billing_address)&&(billingDisable=!1),billingDisable},shippingAddressController=({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId})=>{let shippingDisable=!!(!billingDisable&&shipToDifferentAddress);return shippingDisable&&isEmpty(errors)&&!isEmpty(shipping_address)&&(shippingDisable=!!(shipping_address&&fieldsExist(shipping_address))),shippingDisable&&!isEmpty(shippingAddressId)&&isEmpty(shipping_address)&&(shippingDisable=!1),shippingDisable},countryLockController=({addresses,billing_address,billingAddressId,countryCodeLock,shipToDifferentAddress,shipping_address,shippingAddressId})=>{if(countryCodeLock&&!isEmpty(addresses)&&billingAddressId&&!shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===billingAddressId||a.reference===billingAddressId)&&a.country_code!==countryCodeLock);if(!isEmpty(addressLocked))return!0}if(countryCodeLock&&!isEmpty(billing_address)&&!shipToDifferentAddress)return(billing_address==null?void 0:billing_address.country_code)!==countryCodeLock;if(countryCodeLock&&!isEmpty(shipping_address)&&shipToDifferentAddress)return(shipping_address==null?void 0:shipping_address.country_code)!==countryCodeLock;if(countryCodeLock&&!isEmpty(addresses)&&shippingAddressId&&shipToDifferentAddress){const addressLocked=addresses==null?void 0:addresses.find(a=>(a.id===shippingAddressId||a.reference===shippingAddressId)&&a.country_code!==countryCodeLock);if(!isEmpty(addressLocked))return!0}return!1};