@commercelayer/react-components 3.11.1 → 3.11.2
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/Errors.js +1 -1
- package/lib/components/PaymentGateway.js +1 -1
- package/lib/components/PaymentMethodRadioButton.d.ts +1 -1
- package/lib/components/PaymentMethodRadioButton.js +1 -1
- package/lib/components/PlaceOrderButton.d.ts +1 -1
- package/lib/components/ShippingMethodPrice.js +1 -1
- package/lib/components/utils/getAllErrors.js +1 -1
- package/package.json +1 -1
package/lib/components/Errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,Fragment,useMemo}from"react";import Parent from"./utils/Parent";import GiftCardContext from"../context/GiftCardContext";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";import getAllErrors from"./utils/getAllErrors";import LineItemContext from"../context/LineItemContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import PaymentMethodContext from"../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import ShipmentContext from"../context/ShipmentContext";const propTypes=components.Errors.propTypes,displayName=components.Errors.displayName,Errors=props=>{const{children,messages=[],resource,field}=props,p=__rest(props,["children","messages","resource","field"]),{payment}=useContext(PaymentMethodChildrenContext),{errors:orderErrors}=useContext(OrderContext),{errors:giftCardErrors}=useContext(GiftCardContext),{errors:lineItemErrors}=useContext(LineItemContext),{errors:addressErrors}=useContext(AddressContext),{errors:customerErrors}=useContext(CustomerContext),{errors:shipmentErrors}=useContext(ShipmentContext),{errors:paymentMethodErrors,currentPaymentMethodType,currentPaymentMethodId}=useContext(PaymentMethodContext),{lineItem}=useContext(LineItemChildrenContext),allErrors=useMemo(()=>[...giftCardErrors||[],...orderErrors||[],...lineItemErrors||[],...addressErrors||[],...customerErrors||[],...shipmentErrors||[],...(paymentMethodErrors==null?void 0:paymentMethodErrors.filter(v=>v.field===currentPaymentMethodType&&(payment==null?void 0:payment.id)===currentPaymentMethodId))||[]],[giftCardErrors,orderErrors,lineItemErrors,addressErrors,customerErrors,shipmentErrors,paymentMethodErrors]),msgErrors=getAllErrors({allErrors,field,messages,props:p,lineItem,resource,returnHtml:!children}),parentProps=Object.assign({messages,resource,field,errors:msgErrors},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx(Fragment,{children:msgErrors})};Errors.propTypes=propTypes,Errors.displayName=displayName;export default Errors;
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext,Fragment,useMemo}from"react";import Parent from"./utils/Parent";import GiftCardContext from"../context/GiftCardContext";import OrderContext from"../context/OrderContext";import AddressContext from"../context/AddressContext";import getAllErrors from"./utils/getAllErrors";import LineItemContext from"../context/LineItemContext";import LineItemChildrenContext from"../context/LineItemChildrenContext";import components from"../config/components";import CustomerContext from"../context/CustomerContext";import PaymentMethodContext from"../context/PaymentMethodContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import ShipmentContext from"../context/ShipmentContext";const propTypes=components.Errors.propTypes,displayName=components.Errors.displayName,Errors=props=>{const{children,messages=[],resource,field}=props,p=__rest(props,["children","messages","resource","field"]),{payment}=useContext(PaymentMethodChildrenContext),{errors:orderErrors}=useContext(OrderContext),{errors:giftCardErrors}=useContext(GiftCardContext),{errors:lineItemErrors}=useContext(LineItemContext),{errors:addressErrors}=useContext(AddressContext),{errors:customerErrors}=useContext(CustomerContext),{errors:shipmentErrors}=useContext(ShipmentContext),{errors:paymentMethodErrors,currentPaymentMethodType,currentPaymentMethodId}=useContext(PaymentMethodContext),{lineItem}=useContext(LineItemChildrenContext),allErrors=useMemo(()=>[...giftCardErrors||[],...orderErrors||[],...lineItemErrors||[],...addressErrors||[],...customerErrors||[],...shipmentErrors||[],...(paymentMethodErrors==null?void 0:paymentMethodErrors.filter(v=>v.field===currentPaymentMethodType&&(payment==null?void 0:payment.id)===currentPaymentMethodId))||[]],[giftCardErrors,orderErrors,lineItemErrors,addressErrors,customerErrors,shipmentErrors,paymentMethodErrors]).filter((v,k,a)=>{var _a;return(v==null?void 0:v.code)!==((_a=a[k-1])===null||_a===void 0?void 0:_a.code)}),msgErrors=getAllErrors({allErrors,field,messages,props:p,lineItem,resource,returnHtml:!children}),parentProps=Object.assign({messages,resource,field,errors:msgErrors},p);return children?_jsx(Parent,Object.assign({},parentProps,{children})):_jsx(Fragment,{children:msgErrors})};Errors.propTypes=propTypes,Errors.displayName=displayName;export default Errors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../context/OrderContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../context/PaymentMethodContext";import getPaypalConfig from"../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../utils/getLoaderComponent";import AdyenGateway from"./gateways/AdyenGateway";import StripeGateway from"./gateways/StripeGateway";import BraintreeGateway from"./gateways/BraintreeGateway";import PaypalGateway from"./gateways/PaypalGateway";import WireTransferGateway from"./gateways/WireTransferGateway";import CustomerContext from"../context/CustomerContext";import CheckoutComGateway from"./gateways/CheckoutComGateway";import KlarnaGateway from"./gateways/KlarnaGateway";const PaymentGateway=_a=>{var _b,{readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading..."}=_a,p=__rest(_a,["readonly","showCard","handleEditClick","children","templateCustomerCards","templateCustomerSaveToWallet","onClickCustomerCards","show","loader"]);const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment==null?void 0:payment.payment_source_type;useEffect(()=>{var _a2;if((payment==null?void 0:payment.id)===currentPaymentMethodId&&paymentResource&&((_a2=order==null?void 0:order.payment_method)===null||_a2===void 0?void 0:_a2.payment_source_type)===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&await getCustomerPaymentSources()}
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import OrderContext from"../context/OrderContext";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import PaymentMethodContext from"../context/PaymentMethodContext";import getPaypalConfig from"../utils/paypalPayment";import{useContext,useEffect,useState}from"react";import getLoaderComponent from"../utils/getLoaderComponent";import AdyenGateway from"./gateways/AdyenGateway";import StripeGateway from"./gateways/StripeGateway";import BraintreeGateway from"./gateways/BraintreeGateway";import PaypalGateway from"./gateways/PaypalGateway";import WireTransferGateway from"./gateways/WireTransferGateway";import CustomerContext from"../context/CustomerContext";import CheckoutComGateway from"./gateways/CheckoutComGateway";import KlarnaGateway from"./gateways/KlarnaGateway";const PaymentGateway=_a=>{var _b,{readonly,showCard,handleEditClick,children,templateCustomerCards,templateCustomerSaveToWallet,onClickCustomerCards,show,loader="Loading..."}=_a,p=__rest(_a,["readonly","showCard","handleEditClick","children","templateCustomerCards","templateCustomerSaveToWallet","onClickCustomerCards","show","loader"]);const loaderComponent=getLoaderComponent(loader),[loading,setLoading]=useState(!0),{payment}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{getCustomerPaymentSources}=useContext(CustomerContext),{currentPaymentMethodId,config,currentPaymentMethodType,setPaymentSource,paymentSource}=useContext(PaymentMethodContext),paymentResource=readonly?currentPaymentMethodType:payment==null?void 0:payment.payment_source_type;useEffect(()=>{var _a2;if((payment==null?void 0:payment.id)===currentPaymentMethodId&&paymentResource&&((_a2=order==null?void 0:order.payment_method)===null||_a2===void 0?void 0:_a2.payment_source_type)===paymentResource){const attributes=config&&paymentResource==="paypal_payments"?getPaypalConfig(paymentResource,config):{},setPaymentSources=async()=>{await setPaymentSource({paymentResource,order,attributes}),getCustomerPaymentSources&&await getCustomerPaymentSources()};(!paymentSource&&(order==null?void 0:order.payment_method.id)&&show||!paymentSource||paymentSource.type!==paymentResource)&&setPaymentSources(),(paymentSource==null?void 0:paymentSource.mismatched_amounts)&&show&&setPaymentSources(),setLoading(!1)}return()=>{setLoading(!0)}},[(_b=order==null?void 0:order.payment_method)===null||_b===void 0?void 0:_b.id,show,paymentSource]);const gatewayConfig=Object.assign({readonly,showCard,handleEditClick,children,templateCustomerCards,show,loading,onClickCustomerCards,loaderComponent,templateCustomerSaveToWallet},p);switch(paymentResource){case"stripe_payments":return _jsx(StripeGateway,Object.assign({},gatewayConfig,{children}));case"klarna_payments":return _jsx(KlarnaGateway,Object.assign({},gatewayConfig,{children}));case"adyen_payments":return _jsx(AdyenGateway,Object.assign({},gatewayConfig,{children}));case"braintree_payments":return _jsx(BraintreeGateway,Object.assign({},gatewayConfig,{children}));case"wire_transfers":return _jsx(WireTransferGateway,Object.assign({},gatewayConfig,{children}));case"paypal_payments":return _jsx(PaypalGateway,Object.assign({},gatewayConfig,{children}));case"checkout_com_payments":return _jsx(CheckoutComGateway,Object.assign({},gatewayConfig,{children}));default:return null}};export default PaymentGateway;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FunctionComponent,ReactNode}from'react';import{PaymentMethod}from'@commercelayer/sdk';declare type ShippingMethodRadioButtonChildrenProps=Omit<ShippingMethodRadioButtonProps,'children'>&{checked:boolean;};declare type ShippingMethodRadioButtonProps={children?:(props:ShippingMethodRadioButtonChildrenProps)=>ReactNode;onChange?:(payment?:PaymentMethod|Record<string,any>)=>void;}&JSX.IntrinsicElements['input'];declare const PaymentMethodRadioButton:FunctionComponent<ShippingMethodRadioButtonProps>;export default PaymentMethodRadioButton;
|
|
1
|
+
import{FunctionComponent,ReactNode,ChangeEvent}from'react';import{PaymentMethod}from'@commercelayer/sdk';declare type ShippingMethodRadioButtonChildrenProps=Omit<ShippingMethodRadioButtonProps,'children'>&{checked:boolean;handleOnChange:(event:ChangeEvent<HTMLInputElement>)=>Promise<void>;};declare type ShippingMethodRadioButtonProps={children?:(props:ShippingMethodRadioButtonChildrenProps)=>ReactNode;onChange?:(payment?:PaymentMethod|Record<string,any>)=>void;}&JSX.IntrinsicElements['input'];declare const PaymentMethodRadioButton:FunctionComponent<ShippingMethodRadioButtonProps>;export default PaymentMethodRadioButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentMethodRadioButton.propTypes,displayName=components.PaymentMethodRadioButton.displayName,PaymentMethodRadioButton=props=>{const{onChange}=props,p=__rest(props,["onChange"]),{payment,paymentSelected,setPaymentSelected,clickableContainer}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=(order==null?void 0:order.id)||"",paymentResource=payment==null?void 0:payment.payment_source_type,paymentMethodId=payment==null?void 0:payment.id,name=`payment-${orderId}`,checked=paymentSelected===(payment==null?void 0:payment.id),handleOnChange=async e=>{e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer&&await setPaymentMethod({paymentResource,paymentMethodId}),onChange&&onChange(payment),setLoading({loading:!1})},id=payment==null?void 0:payment.payment_source_type,parentProps=Object.assign({handleOnChange,checked,id,name},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("input",Object.assign({type:"radio",id,onChange:handleOnChange,checked},p))};PaymentMethodRadioButton.propTypes=propTypes,PaymentMethodRadioButton.displayName=displayName;export default PaymentMethodRadioButton;
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useContext}from"react";import PaymentMethodChildrenContext from"../context/PaymentMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import PaymentMethodContext from"../context/PaymentMethodContext";import OrderContext from"../context/OrderContext";const propTypes=components.PaymentMethodRadioButton.propTypes,displayName=components.PaymentMethodRadioButton.displayName,PaymentMethodRadioButton=props=>{const{onChange}=props,p=__rest(props,["onChange"]),{payment,paymentSelected,setPaymentSelected,clickableContainer}=useContext(PaymentMethodChildrenContext),{order}=useContext(OrderContext),{setPaymentMethod,setLoading}=useContext(PaymentMethodContext),orderId=(order==null?void 0:order.id)||"",paymentResource=payment==null?void 0:payment.payment_source_type,paymentMethodId=payment==null?void 0:payment.id,name=`payment-${orderId}`,checked=paymentSelected===(payment==null?void 0:payment.id),handleOnChange=async e=>{e.stopPropagation(),setPaymentSelected&&setPaymentSelected(paymentMethodId),setLoading({loading:!0}),!clickableContainer&&await setPaymentMethod({paymentResource,paymentMethodId}),onChange&&onChange(payment),setLoading({loading:!1})},id=payment==null?void 0:payment.payment_source_type,parentProps=Object.assign({handleOnChange,checked,id,name},props);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("input",Object.assign({title:name,type:"radio",id,onChange:handleOnChange,checked},p))};PaymentMethodRadioButton.propTypes=propTypes,PaymentMethodRadioButton.displayName=displayName;export default PaymentMethodRadioButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{FunctionComponent,ReactNode}from'react';import{FunctionChildren}from'../typings/index';declare type PlaceOrderButtonChildrenProps=FunctionChildren<Omit<PlaceOrderButtonProps,'children'
|
|
1
|
+
import{FunctionComponent,ReactNode}from'react';import{FunctionChildren}from'../typings/index';declare type PlaceOrderButtonChildrenProps=FunctionChildren<Omit<PlaceOrderButtonProps,'children'>&{handleClick:()=>Promise<void>;}>;declare type PlaceOrderButtonProps={children?:PlaceOrderButtonChildrenProps;label?:string|ReactNode;onClick?:(response:{placed:boolean;})=>void;}&JSX.IntrinsicElements['button'];declare const PlaceOrderButton:FunctionComponent<PlaceOrderButtonProps>;export default PlaceOrderButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import OrderContext from"../context/OrderContext";import{isNumber}from"lodash";const propTypes=components.ShippingMethodPrice.propTypes,displayName=components.ShippingMethodPrice.displayName,ShippingMethodPrice=props=>{const{format="formatted",type="amount",base="price",labelFreeOver="Free"}=props,p=__rest(props,["format","type","base","labelFreeOver"]),{shippingMethod}=useContext(ShippingMethodChildrenContext),{order}=useContext(OrderContext),[price,setPrice]=useState(""),[freeOverAmountCents,setFreeOverAmountCents]=useState(0);useEffect(()=>{if(shippingMethod){const p2=getAmount({base,type,format,obj:shippingMethod});setPrice(p2);const c=getAmount({base:"free_over",type,format:"cents",obj:shippingMethod});setFreeOverAmountCents(c)}return()=>{setPrice(""),setFreeOverAmountCents(0)}},[shippingMethod]);const parentProps=Object.assign({price},p);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("span",Object.assign({},p,{children:(order==null?void 0:order.total_amount_cents)&&isNumber(freeOverAmountCents)&&freeOverAmountCents<order.total_amount_cents?labelFreeOver:price}))};ShippingMethodPrice.propTypes=propTypes,ShippingMethodPrice.displayName=displayName;export default ShippingMethodPrice;
|
|
1
|
+
import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import{useState,useEffect,useContext}from"react";import getAmount from"../utils/getAmount";import ShippingMethodChildrenContext from"../context/ShippingMethodChildrenContext";import Parent from"./utils/Parent";import components from"../config/components";import OrderContext from"../context/OrderContext";import{isNumber}from"lodash";const propTypes=components.ShippingMethodPrice.propTypes,displayName=components.ShippingMethodPrice.displayName,ShippingMethodPrice=props=>{const{format="formatted",type="amount",base="price",labelFreeOver="Free"}=props,p=__rest(props,["format","type","base","labelFreeOver"]),{shippingMethod}=useContext(ShippingMethodChildrenContext),{order}=useContext(OrderContext),[price,setPrice]=useState(""),[freeOverAmountCents,setFreeOverAmountCents]=useState(0);useEffect(()=>{if(shippingMethod){const p2=getAmount({base,type,format,obj:shippingMethod});setPrice(p2);const c=getAmount({base:"free_over",type,format:"cents",obj:shippingMethod});setFreeOverAmountCents(c)}return()=>{setPrice(""),setFreeOverAmountCents(0)}},[shippingMethod]);const parentProps=Object.assign({price},p);return props.children?_jsx(Parent,Object.assign({},parentProps,{children:props.children})):_jsx("span",Object.assign({},p,{children:(order==null?void 0:order.total_amount_cents)&&isNumber(freeOverAmountCents)&&freeOverAmountCents<order.total_amount_cents||(order==null?void 0:order.total_amount_cents)===0?labelFreeOver:price}))};ShippingMethodPrice.propTypes=propTypes,ShippingMethodPrice.displayName=displayName;export default ShippingMethodPrice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import customMessages from"../../utils/customMessages";const getAllErrors=params=>{const{allErrors,messages,field,props,lineItem,resource,returnHtml=!0}=params;return allErrors.map((v,k)=>{var _a;const objMsg=customMessages(messages,v);let text=(v==null?void 0:v.title)&&!((_a=v.detail)===null||_a===void 0?void 0:_a.includes(v.title))?`${v.title} - ${v.detail}`:`${v.detail}`;if((objMsg==null?void 0:objMsg.message)&&(text=objMsg==null?void 0:objMsg.message),field){if(v.resource==="line_items"&&lineItem&&v.id===lineItem.id)return returnHtml?_jsx("span",Object.assign({},props,{children:text}),k):text;if(field===v.field&&resource===v.resource)return returnHtml?_jsx("span",Object.assign({},props,{children:text}),k):text}if(resource===v.resource&&!field)return returnHtml?_jsx("span",Object.assign({},props,{children:text}),k):text})};export default getAllErrors;
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import customMessages from"../../utils/customMessages";const getAllErrors=params=>{const{allErrors,messages,field,props,lineItem,resource,returnHtml=!0}=params;return allErrors.map((v,k)=>{var _a;const objMsg=customMessages(messages,v);let text=(v==null?void 0:v.title)&&!((_a=v.detail)===null||_a===void 0?void 0:_a.includes(v.title))?`${v.title} - ${v.detail}`:`${v.detail}`;if((objMsg==null?void 0:objMsg.message)&&(text=objMsg==null?void 0:objMsg.message),field){if(v.resource==="line_items"&&lineItem&&v.id===lineItem.id)return returnHtml?_jsx("span",Object.assign({},props,{children:text}),k):text;if(field===v.field&&resource===v.resource)return returnHtml?_jsx("span",Object.assign({},props,{children:text}),k):text}if(resource===v.resource&&!field)return returnHtml?_jsx("span",Object.assign({},props,{children:text}),k):text}).filter(v=>v!==void 0)};export default getAllErrors;
|