@commercelayer/react-components 3.1.0 → 3.2.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/components/Address.d.ts +1 -1
- package/lib/components/Address.js +1 -1
- package/lib/components/AddressInput.js +1 -1
- package/lib/components/AddressesContainer.js +1 -1
- package/lib/components/AdyenPayment.js +1 -1
- package/lib/components/BillingAddressForm.js +1 -1
- package/lib/components/SaveAddressesButton.js +1 -1
- package/lib/components/ShippingAddressForm.js +1 -1
- package/lib/components/utils/AddressCardsTemplate.d.ts +1 -1
- package/lib/components/utils/AddressCardsTemplate.js +1 -1
- package/lib/typings/index.d.ts +1 -0
- package/lib/utils/addressesManager.js +1 -1
- package/lib/utils/validateFormFields.js +1 -1
- package/package.json +2 -1
|
@@ -5,7 +5,7 @@ declare type Props = {
|
|
|
5
5
|
children: ReactNode | AddressCardsTemplateChildren;
|
|
6
6
|
selectedClassName?: string;
|
|
7
7
|
disabledClassName?: string;
|
|
8
|
-
onSelect?: () => void;
|
|
8
|
+
onSelect?: (address: AddressType) => void;
|
|
9
9
|
addresses?: AddressType[];
|
|
10
10
|
deselect?: boolean;
|
|
11
11
|
} & JSX.IntrinsicElements['div'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import BillingAddressContext from"../context/BillingAddressContext";import ShippingAddressContext from"../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../context/AddressContext";import OrderContext from"../context/OrderContext";import AddressCardsTemplate from"./utils/AddressCardsTemplate";const propTypes=components.Address.propTypes,Address=props=>{const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1}=props,p=__rest(props,["children","className","selectedClassName","disabledClassName","onSelect","addresses","deselect"]),{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.map((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>{setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")})()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect()},countryLock=order==null?void 0:order.shipping_country_code_lock,components2=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,customerAddressId=(address==null?void 0:address.reference)||"",finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,Object.assign({value:addressProps},{children:_jsx("div",Object.assign({className:finalClassName,onClick:()=>handleSelect(k,address.id,customerAddressId,disabled),"data-disabled":disabled},p,{children}),void 0)}),k)}),parentProps=Object.assign({customerAddresses:items,selected,handleSelect,countryLock},props);return typeof children=="function"?_jsx(AddressCardsTemplate,Object.assign({},parentProps,{children}),void 0):_jsx(Fragment,{children:components2},void 0)};Address.propTypes=propTypes;export default Address;
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import AddressChildrenContext from"../context/AddressChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import BillingAddressContext from"../context/BillingAddressContext";import ShippingAddressContext from"../context/ShippingAddressContext";import isEmpty from"lodash/isEmpty";import AddressContext from"../context/AddressContext";import OrderContext from"../context/OrderContext";import AddressCardsTemplate from"./utils/AddressCardsTemplate";const propTypes=components.Address.propTypes,Address=props=>{const{children,className,selectedClassName="",disabledClassName="",onSelect,addresses=[],deselect=!1}=props,p=__rest(props,["children","className","selectedClassName","disabledClassName","onSelect","addresses","deselect"]),{addresses:addressesContext}=useContext(CustomerContext),{setBillingAddress,billingCustomerAddressId}=useContext(BillingAddressContext),{setShippingAddress,shippingCustomerAddressId}=useContext(ShippingAddressContext),{shipToDifferentAddress,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),[selected,setSelected]=useState(null),items=isEmpty(addresses)?addressesContext&&addressesContext||[]:addresses;useEffect(()=>{items&&!deselect&&items.map((address,k)=>{billingCustomerAddressId&&address.reference===billingCustomerAddressId&&selected===null&&setSelected(k),!billingAddressId&&k===selected&&setBillingAddress&&setBillingAddress(address.id,{customerAddressId:address.reference}),shippingCustomerAddressId&&address.reference===shippingCustomerAddressId&&selected===null&&setSelected(k),!shippingAddressId&&k===selected&&setShippingAddress&&setShippingAddress(address.id,{customerAddressId:address.reference})}),deselect&&(async()=>{setBillingAddress&&await setBillingAddress(""),setShippingAddress&&await setShippingAddress("")})()},[deselect,billingCustomerAddressId,shippingCustomerAddressId,addressesContext,shipToDifferentAddress]);const handleSelect=async(k,addressId,customerAddressId,disabled,address)=>{!disabled&&setSelected(k),setBillingAddress&&await setBillingAddress(addressId,{customerAddressId}),!disabled&&setShippingAddress&&await setShippingAddress(addressId,{customerAddressId}),onSelect&&onSelect(address)},countryLock=order==null?void 0:order.shipping_country_code_lock,components2=typeof children=="function"?[]:items.filter(address=>!(setShippingAddress&&countryLock&&countryLock!==address.country_code)).map((address,k)=>{const addressProps={address},disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,customerAddressId=(address==null?void 0:address.reference)||"",finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass;return _jsx(AddressChildrenContext.Provider,Object.assign({value:addressProps},{children:_jsx("div",Object.assign({className:finalClassName,onClick:()=>handleSelect(k,address.id,customerAddressId,disabled,address),"data-disabled":disabled},p,{children}),void 0)}),k)}),parentProps=Object.assign({customerAddresses:items,selected,handleSelect,countryLock},props);return typeof children=="function"?_jsx(AddressCardsTemplate,Object.assign({},parentProps,{children}),void 0):_jsx(Fragment,{children:components2},void 0)};Address.propTypes=propTypes;export default Address;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.AddressInput.propTypes,displayName=components.AddressInput.displayName,AddressInput=props=>{const{placeholder="",required,value,className}=props,p=__rest(props,["placeholder","required","value","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(p.name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(p.name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[p.name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),!isEmpty(billingAddress)&&isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[p.name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[p.name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),!isEmpty(shippingAddress)&&isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useEffect,useState}from"react";import BaseInput from"./utils/BaseInput";import components from"../config/components";import BillingAddressFormContext from"../context/BillingAddressFormContext";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import isEmpty from"lodash/isEmpty";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.AddressInput.propTypes,displayName=components.AddressInput.displayName,AddressInput=props=>{const{placeholder="",required,value,className}=props,p=__rest(props,["placeholder","required","value","className"]),billingAddress=useContext(BillingAddressFormContext),shippingAddress=useContext(ShippingAddressFormContext),[hasError,setHasError]=useState(!1);useEffect(()=>{var _a,_b,_c,_d,_e,_f;return value&&(billingAddress==null?void 0:billingAddress.setValue)&&billingAddress.setValue(p.name,value),value&&(shippingAddress==null?void 0:shippingAddress.setValue)&&shippingAddress.setValue(p.name,value),!isEmpty(billingAddress.errors)&&((_b=(_a=billingAddress==null?void 0:billingAddress.errors)===null||_a===void 0?void 0:_a[p.name])===null||_b===void 0?void 0:_b.error)&&setHasError(!0),!isEmpty(billingAddress)&&isEmpty((_c=billingAddress==null?void 0:billingAddress.errors)===null||_c===void 0?void 0:_c[p.name])&&hasError&&setHasError(!1),!isEmpty(shippingAddress.errors)&&((_e=(_d=shippingAddress==null?void 0:shippingAddress.errors)===null||_d===void 0?void 0:_d[p.name])===null||_e===void 0?void 0:_e.error)&&setHasError(!0),!isEmpty(shippingAddress)&&isEmpty((_f=shippingAddress==null?void 0:shippingAddress.errors)===null||_f===void 0?void 0:_f[p.name])&&hasError&&setHasError(!1),()=>{setHasError(!1)}},[value,billingAddress==null?void 0:billingAddress.errors,shippingAddress==null?void 0:shippingAddress.errors]);const mandatoryField=(billingAddress==null?void 0:billingAddress.isBusiness)?businessMandatoryField(p.name,billingAddress.isBusiness):businessMandatoryField(p.name,shippingAddress.isBusiness),reqField=required!==void 0?required:mandatoryField,errorClassName=(billingAddress==null?void 0:billingAddress.errorClassName)||(shippingAddress==null?void 0:shippingAddress.errorClassName),classNameComputed=`${className} ${hasError?errorClassName:""}`;return p.name==="billing_address_billing_info"&&!billingAddress.requiresBillingInfo?null:_jsx(BaseInput,Object.assign({ref:(billingAddress==null?void 0:billingAddress.validation)||(shippingAddress==null?void 0:shippingAddress.validation),className:classNameComputed,required:reqField,placeholder,defaultValue:value},p),void 0)};AddressInput.propTypes=propTypes,AddressInput.displayName=displayName;export default AddressInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext,{defaultAddressContext}from"../context/AddressContext";import{useContext,useEffect,useReducer}from"react";import addressReducer,{addressInitialState,setAddressErrors,setCloneAddress}from"../reducers/AddressReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import{saveAddresses}from"../reducers/AddressReducer";import components from"../config/components";const propTypes=components.AddressesContainer.propTypes,displayName=components.AddressesContainer.displayName,AddressesContainer=props=>{const{children,shipToDifferentAddress=!1,isBusiness
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext,{defaultAddressContext}from"../context/AddressContext";import{useContext,useEffect,useReducer}from"react";import addressReducer,{addressInitialState,setAddressErrors,setCloneAddress}from"../reducers/AddressReducer";import OrderContext from"../context/OrderContext";import CommerceLayerContext from"../context/CommerceLayerContext";import{saveAddresses}from"../reducers/AddressReducer";import components from"../config/components";const propTypes=components.AddressesContainer.propTypes,displayName=components.AddressesContainer.displayName,AddressesContainer=props=>{const{children,shipToDifferentAddress=!1,isBusiness}=props,[state,dispatch]=useReducer(addressReducer,addressInitialState),{order,orderId,updateOrder}=useContext(OrderContext),config=useContext(CommerceLayerContext);useEffect(()=>(dispatch({type:"setShipToDifferentAddress",payload:{shipToDifferentAddress,isBusiness}}),()=>{dispatch({type:"cleanup",payload:{}})}),[shipToDifferentAddress,isBusiness]);const contextValue=Object.assign(Object.assign({},state),{setAddressErrors:(errors,resource)=>setAddressErrors({errors,resource,dispatch,currentErrors:state.errors}),setAddress:params=>defaultAddressContext.setAddress(Object.assign(Object.assign({},params),{dispatch})),saveAddresses:async()=>await saveAddresses({config,dispatch,updateOrder,order,orderId,state}),setCloneAddress:(id,resource)=>setCloneAddress(id,resource,dispatch)});return _jsx(AddressesContext.Provider,Object.assign({value:contextValue},{children}),void 0)};AddressesContainer.propTypes=propTypes,AddressesContainer.displayName=displayName;export default AddressesContainer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import{setCustomerOrderParam}from"../utils/localStorage";import Parent from"./utils/Parent";import getBrowserInfo from"../utils/browserInfo";import PlaceOrderContext from"../context/PlaceOrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={},AdyenPayment=({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"})=>{const{cardContainerClassName,threeDSecureContainerClassName,placeOrderCallback,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState({}),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{setPlaceOrder}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,checkout2)=>{var _a,_b,_c,_d,_e,_f,_g;const savePaymentSourceToCustomerWallet=(_b=(_a=e==null?void 0:e.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet);const attributes={_authorize:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_c=pSource==null?void 0:pSource.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource==null?void 0:pSource.payment_response)===null||_d===void 0?void 0:_d.resultCode;if(adyenAction&&["IdentifyShopper","RedirectShopper"].includes(resultCode))checkout2.createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action");else if(["Authorised","Pending","Received"].includes(resultCode)){const brand=(_f=(_e=pSource==null?void 0:pSource.payment_request_data)===null||_e===void 0?void 0:_e.payment_method)===null||_f===void 0?void 0:_f.brand;if(brand){const attributes2={metadata:{card:{brand}}};await setPaymentSource({paymentSourceId:pSource==null?void 0:pSource.id,paymentResource:"adyen_payments",attributes:attributes2})}return!0}const message=(_g=pSource==null?void 0:pSource.payment_response)===null||_g===void 0?void 0:_g.refusalReason;return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}},handleChange=async(state,_component,config2,paySource)=>{if(state.isValid){if(ref.current){const adyenCheckout=await require("@adyen/adyen-web")(config2);ref.current.onsubmit=()=>handleSubmit(ref.current,adyenCheckout),setPaymentRef({ref})}
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useContext,useEffect,useRef,useState}from"react";import PaymentMethodContext from"../context/PaymentMethodContext";import isEmpty from"lodash/isEmpty";import{setCustomerOrderParam}from"../utils/localStorage";import Parent from"./utils/Parent";import getBrowserInfo from"../utils/browserInfo";import PlaceOrderContext from"../context/PlaceOrderContext";const threeDSConfiguration={challengeWindowSize:"05"},defaultConfig={},AdyenPayment=({clientKey,config,templateCustomerSaveToWallet,environment="test",locale="en_US"})=>{const{cardContainerClassName,threeDSecureContainerClassName,placeOrderCallback,styles}=Object.assign(Object.assign({},defaultConfig),config),[loadAdyen,setLoadAdyen]=useState(!1),[checkout,setCheckout]=useState({}),{setPaymentSource,paymentSource,setPaymentMethodErrors,currentPaymentMethodType,setPaymentRef}=useContext(PaymentMethodContext),{setPlaceOrder}=useContext(PlaceOrderContext),ref=useRef(null),handleSubmit=async(e,checkout2)=>{var _a,_b,_c,_d,_e,_f,_g;const savePaymentSourceToCustomerWallet=(_b=(_a=e==null?void 0:e.elements)===null||_a===void 0?void 0:_a.save_payment_source_to_customer_wallet)===null||_b===void 0?void 0:_b.checked;savePaymentSourceToCustomerWallet&&setCustomerOrderParam("_save_payment_source_to_customer_wallet",savePaymentSourceToCustomerWallet);const attributes={_authorize:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_c=pSource==null?void 0:pSource.payment_response)===null||_c===void 0?void 0:_c.action,resultCode=(_d=pSource==null?void 0:pSource.payment_response)===null||_d===void 0?void 0:_d.resultCode;if(adyenAction&&["IdentifyShopper","RedirectShopper"].includes(resultCode))checkout2.createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action");else if(["Authorised","Pending","Received"].includes(resultCode)){const brand=(_f=(_e=pSource==null?void 0:pSource.payment_request_data)===null||_e===void 0?void 0:_e.payment_method)===null||_f===void 0?void 0:_f.brand;if(brand){const attributes2={metadata:{card:{brand}}};await setPaymentSource({paymentSourceId:pSource==null?void 0:pSource.id,paymentResource:"adyen_payments",attributes:attributes2})}return!0}const message=(_g=pSource==null?void 0:pSource.payment_response)===null||_g===void 0?void 0:_g.refusalReason;return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message}]),!1}catch(error){return setPaymentMethodErrors([{code:"PAYMENT_INTENT_AUTHENTICATION_FAILURE",resource:"payment_methods",field:currentPaymentMethodType,message:error.message}]),!1}},handleChange=async(state,_component,config2,paySource)=>{if(state.isValid){if(ref.current){const adyenCheckout=await require("@adyen/adyen-web")(config2);ref.current.onsubmit=()=>handleSubmit(ref.current,adyenCheckout),setPaymentRef({ref})}const browserInfo=getBrowserInfo(),attributes={payment_request_data:{payment_method:state.data.paymentMethod,shopperInteraction:"Ecommerce",recurringProcessingModel:"CardOnFile",origin:window.location.origin,return_url:window.location.href,redirect_from_issuer_method:"GET",browser_info:Object.assign({acceptHeader:"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"},browserInfo)}};paySource&&await setPaymentSource({paymentSourceId:paySource.id,paymentResource:"adyen_payments",attributes})}},handleOnAdditionalDetails=async(state,_component,config2)=>{var _a,_b;const attributes={payment_request_details:state.data,_details:1};try{const pSource=paymentSource&&await setPaymentSource({paymentSourceId:paymentSource.id,paymentResource:"adyen_payments",attributes}),adyenAction=(_a=pSource==null?void 0:pSource.payment_response)===null||_a===void 0?void 0:_a.action,resultCode=(_b=pSource==null?void 0:pSource.payment_response)===null||_b===void 0?void 0:_b.resultCode,AdyenCheckout=require("@adyen/adyen-web");if(adyenAction&&(await AdyenCheckout(config2)).createFromAction(adyenAction,threeDSConfiguration).mount("#adyen-action"),["Authorised","Pending","Received"].includes(resultCode)){const{placed}=setPlaceOrder&&await setPlaceOrder({paymentSource:pSource})||{placed:!1};placed&&placeOrderCallback&&placeOrderCallback({placed})}}catch(error){console.error("Adyen additional details error:",error)}};return useEffect(()=>{const paymentMethodsResponse=isEmpty(paymentSource==null?void 0:paymentSource.payment_methods)?{}:paymentSource==null?void 0:paymentSource.payment_methods;isEmpty(paymentMethodsResponse)&&console.error("Payment methods are not available. Please, check your Adyen configuration.");const options={locale,environment,clientKey,paymentMethodsResponse};return options.onChange=(s,c)=>handleChange(s,c,options,paymentSource),options.onAdditionalDetails=(s,c)=>handleOnAdditionalDetails(s,c,options),!ref&&clientKey&&setCustomerOrderParam("_save_payment_source_to_customer_wallet","false"),clientKey&&!loadAdyen&&!isEmpty(window)&&require("@adyen/adyen-web")(options).then(adyenCheckout=>{adyenCheckout.create("card",{styles}).mount("#adyen-card")&&(setCheckout(adyenCheckout),setLoadAdyen(!0))}),()=>{setPaymentRef({ref:{current:null}}),setLoadAdyen(!1)}},[clientKey,ref]),!clientKey&&!loadAdyen&&!checkout?null:_jsxs("form",Object.assign({ref,onSubmit:e=>handleSubmit(e,checkout)},{children:[_jsx("div",{className:cardContainerClassName,id:"adyen-card"},void 0),templateCustomerSaveToWallet&&_jsx(Parent,Object.assign({},{name:"save_payment_source_to_customer_wallet"},{children:templateCustomerSaveToWallet}),void 0),_jsx("div",{className:threeDSecureContainerClassName,id:"adyen-action"},void 0)]}),void 0)};export default AdyenPayment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../context/BillingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../utils/localStorage";const propTypes=components.BillingAddressForm.propTypes,BillingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c;if((include==null?void 0:include.includes("billing_address"))?(includeLoaded==null?void 0:includeLoaded.billing_address)||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(!isEmpty(values)){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];(field==null?void 0:field.value)&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];["billing_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message,resource:"billing_address",field:fieldName}):formErrors.push({code,message,resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=((_b=(_a=ref.current)===null||_a===void 0?void 0:_a.querySelector('[name="billing_address_save_to_customer_book"]'))===null||_b===void 0?void 0:_b.checked)||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&((_c=ref.current)===null||_c===void 0||_c.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import BillingAddressFormContext from"../context/BillingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveBillingAddressToAddressBook}from"../utils/localStorage";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.BillingAddressForm.propTypes,BillingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,order,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c;if((include==null?void 0:include.includes("billing_address"))?(includeLoaded==null?void 0:includeLoaded.billing_address)||addResourceToInclude({newResourceLoaded:{billing_address:!0}}):addResourceToInclude({newResource:"billing_address"}),isEmpty(errors)){if(!isEmpty(values)){setAddressErrors([],"billing_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field==null?void 0:field.value)&&(values[name.replace("billing_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"billing_address",value:field.checked}))}console.log("values",values),setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"billing_address"})}}else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];["billing_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message,resource:"billing_address",field:fieldName}):formErrors.push({code,message,resource:"billing_address",field:fieldName})}setAddressErrors(formErrors,"billing_address")}const checkboxChecked=((_b=(_a=ref.current)===null||_a===void 0?void 0:_a.querySelector('[name="billing_address_save_to_customer_book"]'))===null||_b===void 0?void 0:_b.checked)||getSaveBillingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"billing_address",value:!1}),ref&&((_c=ref.current)===null||_c===void 0||_c.reset(),resetForm({target:ref.current}),setAddressErrors([],"billing_address"),setAddress({values:{},resource:"billing_address"})))},[errors,values,reset,include,includeLoaded,isBusiness]);const providerValues={isBusiness,values,validation,setValue:(name,value)=>{const field={[name.replace("billing_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"billing_address"})},errorClassName,requiresBillingInfo:(order==null?void 0:order.requires_billing_info)||!1,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(BillingAddressFormContext.Provider,Object.assign({value:providerValues},{children:_jsx("form",Object.assign({ref,autoComplete},p,{children}),void 0)}),void 0)};BillingAddressForm.propTypes=propTypes;export default BillingAddressForm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import AddressContext from"../context/AddressContext";import{isEmpty}from"lodash";import{billingAddressController,shippingAddressController,countryLockController}from"../utils/addressesManager";import OrderContext from"../context/OrderContext";import CustomerContext from"../context/CustomerContext";import isFunction from"lodash/isFunction";const propTypes=components.SaveAddressesButton.propTypes,defaultProps=components.SaveAddressesButton.defaultProps,displayName=components.SaveAddressesButton.displayName,SaveAddressesButton=props=>{const{children,label="Continue to delivery",resource,disabled=!1,onClick}=props,p=__rest(props,["children","label","resource","disabled","onClick"]),{errors,billing_address,shipToDifferentAddress,shipping_address,saveAddresses,billingAddressId,shippingAddressId
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,useState}from"react";import Parent from"./utils/Parent";import components from"../config/components";import AddressContext from"../context/AddressContext";import{isEmpty}from"lodash";import{billingAddressController,shippingAddressController,countryLockController}from"../utils/addressesManager";import OrderContext from"../context/OrderContext";import CustomerContext from"../context/CustomerContext";import isFunction from"lodash/isFunction";const propTypes=components.SaveAddressesButton.propTypes,defaultProps=components.SaveAddressesButton.defaultProps,displayName=components.SaveAddressesButton.displayName,SaveAddressesButton=props=>{const{children,label="Continue to delivery",resource,disabled=!1,onClick}=props,p=__rest(props,["children","label","resource","disabled","onClick"]),{errors,billing_address,shipToDifferentAddress,shipping_address,saveAddresses,billingAddressId,shippingAddressId}=useContext(AddressContext),{order}=useContext(OrderContext),{addresses,isGuest}=useContext(CustomerContext),[forceDisable,setForceDisable]=useState(disabled),customerEmail=(isGuest===!0||typeof isGuest=="undefined")&&!(order==null?void 0:order.customer_email),billingDisable=billingAddressController({billing_address,errors,billingAddressId,requiresBillingInfo:order==null?void 0:order.requires_billing_info}),shippingDisable=shippingAddressController({billingDisable,errors,shipToDifferentAddress,shipping_address,shippingAddressId}),countryLockDisable=countryLockController({countryCodeLock:order==null?void 0:order.shipping_country_code_lock,addresses,shipToDifferentAddress,billingAddressId,billing_address,shipping_address,shippingAddressId}),disable=disabled||customerEmail||billingDisable||shippingDisable||countryLockDisable,handleClick=async()=>{isEmpty(errors)&&!disable&&(setForceDisable(!0),await saveAddresses(),setForceDisable(!1),onClick&&onClick())},parentProps=Object.assign(Object.assign({},p),{label,resource,handleClick,disabled:disable});return children?_jsx(Parent,Object.assign({},parentProps,{children}),void 0):_jsx("button",Object.assign({type:"button",disabled:disable||forceDisable,onClick:handleClick},p,{children:isFunction(label)?label():label}),void 0)};SaveAddressesButton.propTypes=propTypes,SaveAddressesButton.defaultProps=defaultProps,SaveAddressesButton.displayName=displayName;export default SaveAddressesButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveShippingAddressToAddressBook}from"../utils/localStorage";const propTypes=components.ShippingAddressForm.propTypes,ShippingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,shipToDifferentAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c;if((include==null?void 0:include.includes("shipping_address"))?(includeLoaded==null?void 0:includeLoaded.shipping_address)||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address"}),isEmpty(errors)){if(!isEmpty(values)&&shipToDifferentAddress){setAddressErrors([],"shipping_address");for(const name in values){const field=values[name];(field==null?void 0:field.value)&&(values[name.replace("shipping_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"shipping_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"shipping_address"})}}else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];["shipping_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message,resource:"shipping_address",field:fieldName}):formErrors.push({code,message,resource:"shipping_address",field:fieldName})}shipToDifferentAddress&&setAddressErrors(formErrors,"shipping_address")}const checkboxChecked=((_b=(_a=ref.current)===null||_a===void 0?void 0:_a.querySelector('[name="shipping_address_save_to_customer_book"]'))===null||_b===void 0?void 0:_b.checked)||getSaveShippingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"shipping_address",value:!1}),ref&&((_c=ref.current)===null||_c===void 0||_c.reset(),resetForm({target:ref.current}),setAddressErrors([],"shipping_address"),setAddress({values:{},resource:"shipping_address"})))},[values,errors,shipToDifferentAddress,reset,include,includeLoaded]),useEffect(()=>{var _a;ref&&((_a=ref.current)===null||_a===void 0||_a.reset(),resetForm({target:ref.current}),setAddressErrors([],"shipping_address"),setAddress({values:{},resource:"shipping_address"}))},[isBusiness]);const providerValues={values,validation,setValue:(name,value)=>{const field={[name.replace("shipping_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"shipping_address"})},errorClassName,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(ShippingAddressFormContext.Provider,Object.assign({value:providerValues},{children:_jsx("form",Object.assign({ref,autoComplete},p,{children}),void 0)}),void 0)};ShippingAddressForm.propTypes=propTypes;export default ShippingAddressForm;
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import AddressesContext from"../context/AddressContext";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import ShippingAddressFormContext from"../context/ShippingAddressFormContext";import{isEmpty}from"lodash";import components from"../config/components";import OrderContext from"../context/OrderContext";import{getSaveShippingAddressToAddressBook}from"../utils/localStorage";import{businessMandatoryField}from"../utils/validateFormFields";const propTypes=components.ShippingAddressForm.propTypes,ShippingAddressForm=props=>{const{children,errorClassName,autoComplete="on",reset=!1}=props,p=__rest(props,["children","errorClassName","autoComplete","reset"]),{validation,values,errors,reset:resetForm}=useRapidForm(),{setAddressErrors,setAddress,shipToDifferentAddress,isBusiness}=useContext(AddressesContext),{saveAddressToCustomerAddressBook,include,addResourceToInclude,includeLoaded}=useContext(OrderContext),ref=useRef(null);useEffect(()=>{var _a,_b,_c;if((include==null?void 0:include.includes("shipping_address"))?(includeLoaded==null?void 0:includeLoaded.shipping_address)||addResourceToInclude({newResourceLoaded:{shipping_address:!0}}):addResourceToInclude({newResource:"shipping_address"}),isEmpty(errors)){if(!isEmpty(values)&&shipToDifferentAddress){setAddressErrors([],"shipping_address");for(const name in values){const field=values[name];businessMandatoryField(name,isBusiness)||delete values[name],(field==null?void 0:field.value)&&(values[name.replace("shipping_address_","")]=field.value,delete values[name]),(field==null?void 0:field.type)==="checkbox"&&(delete values[name],saveAddressToCustomerAddressBook({type:"shipping_address",value:field.checked}))}setAddress({values:Object.assign(Object.assign({},values),isBusiness&&{business:isBusiness}),resource:"shipping_address"})}}else{const formErrors=[];for(const fieldName in errors){const{code,message}=errors[fieldName];["shipping_address_state_code"].includes(fieldName)?isEmpty(values.state_code)?delete errors[fieldName]:formErrors.push({code,message,resource:"shipping_address",field:fieldName}):formErrors.push({code,message,resource:"shipping_address",field:fieldName})}shipToDifferentAddress&&setAddressErrors(formErrors,"shipping_address")}const checkboxChecked=((_b=(_a=ref.current)===null||_a===void 0?void 0:_a.querySelector('[name="shipping_address_save_to_customer_book"]'))===null||_b===void 0?void 0:_b.checked)||getSaveShippingAddressToAddressBook();reset&&(!isEmpty(values)||!isEmpty(errors)||checkboxChecked)&&(saveAddressToCustomerAddressBook&&saveAddressToCustomerAddressBook({type:"shipping_address",value:!1}),ref&&((_c=ref.current)===null||_c===void 0||_c.reset(),resetForm({target:ref.current}),setAddressErrors([],"shipping_address"),setAddress({values:{},resource:"shipping_address"})))},[values,errors,shipToDifferentAddress,reset,include,includeLoaded,isBusiness]),useEffect(()=>{var _a;ref&&((_a=ref.current)===null||_a===void 0||_a.reset(),resetForm({target:ref.current}),setAddressErrors([],"shipping_address"),setAddress({values:{},resource:"shipping_address"}))},[isBusiness]);const providerValues={values,validation,setValue:(name,value)=>{const field={[name.replace("shipping_address_","")]:value};setAddress({values:Object.assign(Object.assign(Object.assign({},values),field),isBusiness&&{business:isBusiness}),resource:"shipping_address"})},errorClassName,errors,resetField:name=>resetForm({currentTarget:ref.current},name)};return _jsx(ShippingAddressFormContext.Provider,Object.assign({value:providerValues},{children:_jsx("form",Object.assign({ref,autoComplete},p,{children}),void 0)}),void 0)};ShippingAddressForm.propTypes=propTypes;export default ShippingAddressForm;
|
|
@@ -11,7 +11,7 @@ export declare type CustomerAddress = Address & {
|
|
|
11
11
|
};
|
|
12
12
|
export declare type AddressCardsTemplateChildren = FunctionChildren<ChildrenProps>;
|
|
13
13
|
export declare type AddressCardsType = ChildrenProps;
|
|
14
|
-
declare type HandleSelect = (k: number, addressId: string, customerAddressId: string, disabled: boolean) => void;
|
|
14
|
+
export declare type HandleSelect = (k: number, addressId: string, customerAddressId: string, disabled: boolean, address: Address) => void;
|
|
15
15
|
declare type Props = {
|
|
16
16
|
customerAddresses: CustomerAddress[];
|
|
17
17
|
countryLock?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import{useContext}from"react";import AddressChildrenContext from"../../context/AddressChildrenContext";import ShippingAddressContext from"../../context/ShippingAddressContext";export default function AddressCardsTemplate({customerAddresses,children,deselect,countryLock,selected,selectedClassName,className,disabledClassName,handleSelect}){const{setShippingAddress}=useContext(ShippingAddressContext),value={customerAddresses:customerAddresses.map((address,k)=>{const attributes=address,disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass,customerAddressId=(address==null?void 0:address.reference)||"",onClick=()=>handleSelect(k,address.id,customerAddressId,disabled);return Object.assign(Object.assign({},attributes),{className:finalClassName,onClick})}),AddressProvider:AddressChildrenContext.Provider};return _jsx(Parent,Object.assign({},value,{children}),void 0)}
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import Parent from"../utils/Parent";import{useContext}from"react";import AddressChildrenContext from"../../context/AddressChildrenContext";import ShippingAddressContext from"../../context/ShippingAddressContext";export default function AddressCardsTemplate({customerAddresses,children,deselect,countryLock,selected,selectedClassName,className,disabledClassName,handleSelect}){const{setShippingAddress}=useContext(ShippingAddressContext),value={customerAddresses:customerAddresses.map((address,k)=>{const attributes=address,disabled=setShippingAddress&&countryLock&&countryLock!==address.country_code||!1,addressSelectedClass=selected===k?`${className} ${deselect?"":selectedClassName}`:className,finalClassName=disabled?`${className} ${disabledClassName}`:addressSelectedClass,customerAddressId=(address==null?void 0:address.reference)||"",onClick=()=>handleSelect(k,address.id,customerAddressId,disabled,address);return Object.assign(Object.assign({},attributes),{className:finalClassName,onClick})}),AddressProvider:AddressChildrenContext.Provider};return _jsx(Parent,Object.assign({},value,{children}),void 0)}
|
package/lib/typings/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface BaseSelectComponentProps {
|
|
|
37
37
|
className?: string;
|
|
38
38
|
required?: boolean;
|
|
39
39
|
name: string;
|
|
40
|
+
onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void;
|
|
40
41
|
}
|
|
41
42
|
export declare const BaseInputComponentPropTypes: {
|
|
42
43
|
children: PropTypes.Requireable<(...args: any[]) => any>;
|
|
@@ -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);
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import isEmpty from"lodash/isEmpty";import isString from"lodash/isString";import without from"lodash/without";import keys from"lodash/keys";import map from"lodash/map";import get from"lodash/get";import{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/;export const validateValue=(val,name,type,resourceType)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:`${name} - is not valid`,resourceType}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resourceType};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const isTick=!!get(v,"checked"),val=isTick||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.indexOf(attrName)!==-1||v.required){const error=validateValue(val,v.name,v.type,resourceType);isEmpty(error)||errors.push(error),values=Object.assign(Object.assign({},values),{[`${v.name}`]:val})}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?Object.assign(Object.assign({},values),{metadata:Object.assign(Object.assign({},values.metadata),{[`${v.name}`]:val})}):Object.assign(Object.assign({},values),{[`${v.name}`]:val}))}),{errors,values}};export const fieldsExist=(address,schema=addressFields)=>{if(
|
|
1
|
+
import isEmpty from"lodash/isEmpty";import isString from"lodash/isString";import without from"lodash/without";import keys from"lodash/keys";import map from"lodash/map";import get from"lodash/get";import{addressFields}from"../reducers/AddressReducer";const EMAIL_PATTERN=/[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$/;export const validateValue=(val,name,type,resourceType)=>val?type==="email"&&isString(val)&&!val.match(EMAIL_PATTERN)?{field:name,code:"VALIDATION_ERROR",message:`${name} - is not valid`,resourceType}:{}:{field:name,code:"VALIDATION_ERROR",message:`${name} - is required`,resourceType};const validateFormFields=(fields,required,resourceType)=>{const errors=[];let values={metadata:{}};return map(fields,v=>{const isTick=!!get(v,"checked"),val=isTick||(v.value==="on"?!1:v.value),attrName=v.getAttribute("name");if(attrName&&required.indexOf(attrName)!==-1||v.required){const error=validateValue(val,v.name,v.type,resourceType);isEmpty(error)||errors.push(error),values=Object.assign(Object.assign({},values),{[`${v.name}`]:val})}v.getAttribute("name")&&(values=!!v.getAttribute("data-metadata")?Object.assign(Object.assign({},values),{metadata:Object.assign(Object.assign({},values.metadata),{[`${v.name}`]:val})}):Object.assign(Object.assign({},values),{[`${v.name}`]:val}))}),{errors,values}};export const fieldsExist=(address,schema=addressFields)=>{if(address.business){const required=without(schema,"first_name","last_name"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}else{const required=without(schema,"line_2","company"),validAddress=keys(address).filter(k=>required.includes(k));return required.length>validAddress.length}};const businessOptionalFields=["billing_address_first_name","billing_address_last_name","shipping_address_first_name","shipping_address_last_name","first_name","last_name"],customerOptionalFields=["billing_address_company","billing_address_line_2","shipping_address_company","shipping_address_line_2","company","line_2"];export function businessMandatoryField(fieldName,isBusiness){return!(isBusiness&&businessOptionalFields.includes(fieldName)||!isBusiness&&customerOptionalFields.includes(fieldName))}export default validateFormFields;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercelayer/react-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "The Official Commerce Layer React Components",
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"test": "jest",
|
|
46
46
|
"test:coverage": "jest --coverage",
|
|
47
47
|
"test:playwright": "playwright test",
|
|
48
|
+
"lint": "eslint src",
|
|
48
49
|
"build": "tsc -b tsconfig.prod.json --verbose",
|
|
49
50
|
"postbuild": "tsc-alias -p tsconfig.prod.json && minimize-js lib -w -s",
|
|
50
51
|
"start": "NODE_OPTIONS='--inspect' next dev",
|