@commercelayer/react-components 3.5.2 → 3.6.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.
@@ -1 +1 @@
1
- import{FunctionComponent,ReactNode}from'react';declare type GiftCardOrCouponFormProps={children:ReactNode;reset?:boolean;onSubmit?:(response:{success:boolean;})=>void;}&Omit<JSX.IntrinsicElements['form'],'onSubmit'>;declare const GiftCardOrCouponForm:FunctionComponent<GiftCardOrCouponFormProps>;export default GiftCardOrCouponForm;
1
+ import{FunctionComponent,ReactNode}from'react';declare type GiftCardOrCouponFormProps={children:ReactNode;onSubmit?:(response:{success:boolean;})=>void;}&Omit<JSX.IntrinsicElements['form'],'onSubmit'>;declare const GiftCardOrCouponForm:FunctionComponent<GiftCardOrCouponFormProps>;export default GiftCardOrCouponForm;
@@ -1 +1 @@
1
- import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import components from"../config/components";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import{findIndex}from"lodash";const propTypes=components.GiftCardOrCouponForm.propTypes,GiftCardOrCouponForm=props=>{const{children,autoComplete="on",reset=!1,onSubmit}=props,p=__rest(props,["children","autoComplete","reset","onSubmit"]),{validation,values}=useRapidForm(),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{var _a;if(((_a=values[inputName])===null||_a===void 0?void 0:_a.value)===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors({errors:err}),onSubmit&&onSubmit({success:!0})}},[values]);const handleSubmit=async e=>{e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code){const{success}=await setGiftCardOrCouponCode({code});onSubmit&&onSubmit({success}),success&&e.target.reset()}};return(order==null?void 0:order.gift_card_or_coupon_code)||isEmpty(order)?null:_jsx(CouponAndGiftCardFormContext.Provider,Object.assign({value:{validation}},{children:_jsx("form",Object.assign({ref,autoComplete,onSubmit:handleSubmit},p,{children}))}))};GiftCardOrCouponForm.propTypes=propTypes;export default GiftCardOrCouponForm;
1
+ import{__rest}from"tslib";import{jsx as _jsx}from"react/jsx-runtime";import useRapidForm from"rapid-form";import{useContext,useEffect,useRef}from"react";import CouponAndGiftCardFormContext from"../context/CouponAndGiftCardFormContext";import OrderContext from"../context/OrderContext";import isEmpty from"lodash/isEmpty";import components from"../config/components";import camelCase from"lodash/camelCase";import dropWhile from"lodash/dropWhile";import has from"lodash/has";import{findIndex}from"lodash";const propTypes=components.GiftCardOrCouponForm.propTypes,GiftCardOrCouponForm=props=>{const{children,autoComplete="on",onSubmit}=props,p=__rest(props,["children","autoComplete","onSubmit"]),{validation,values}=useRapidForm(),{setGiftCardOrCouponCode,order,errors,setOrderErrors}=useContext(OrderContext),ref=useRef(null),inputName="gift_card_or_coupon_code";useEffect(()=>{var _a;if(((_a=values[inputName])===null||_a===void 0?void 0:_a.value)===""&&findIndex(errors,{field:camelCase(inputName)})!==-1){const err=dropWhile(errors,i=>i.field===camelCase(inputName));setOrderErrors({errors:err}),onSubmit&&onSubmit({success:!0})}},[values]);const handleSubmit=async e=>{e.preventDefault();const code=has(values,inputName)?values[inputName].value:void 0;if(code){const{success}=await setGiftCardOrCouponCode({code});onSubmit&&onSubmit({success}),success&&e.target.reset()}};return(order==null?void 0:order.gift_card_or_coupon_code)||isEmpty(order)?null:_jsx(CouponAndGiftCardFormContext.Provider,Object.assign({value:{validation}},{children:_jsx("form",Object.assign({ref,autoComplete,onSubmit:handleSubmit},p,{children}))}))};GiftCardOrCouponForm.propTypes=propTypes;export default GiftCardOrCouponForm;
@@ -1 +1 @@
1
- import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const saveCustomerUser=async({customerEmail,order,updateOrder})=>{if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}},setCustomerErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},setCustomerEmail=(customerEmail,dispatch)=>{dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})},getCustomerAddresses=async({config,dispatch})=>{try{const addresses=[];(await getSdk(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=getErrors(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}},getCustomerPaymentSources=async({dispatch,order})=>{(order==null?void 0:order.available_customer_payment_sources)&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})},customerInitialState={errors:[],addresses:[],payments:[]};const type=["setErrors","setCustomerEmail","setAddresses","setPayments"],customerReducer=(state,reducer)=>baseReducer(state,reducer,type);export default customerReducer;
1
+ import baseReducer from"../utils/baseReducer";import getSdk from"../utils/getSdk";import getErrors from"../utils/getErrors";export const saveCustomerUser=async({customerEmail,order,updateOrder})=>{if(order){const attributes={customer_email:customerEmail,id:order.id};await updateOrder({id:order.id,attributes})}},setCustomerErrors=(errors,dispatch)=>{dispatch&&dispatch({type:"setErrors",payload:{errors}})},setCustomerEmail=(customerEmail,dispatch)=>{dispatch&&dispatch({type:"setCustomerEmail",payload:{customerEmail}})},getCustomerAddresses=async({config,dispatch})=>{try{const addresses=[];(await getSdk(config).customer_addresses.list({include:["address"]})).forEach(customerAddress=>{customerAddress.address&&addresses.push(customerAddress.address)}),addresses.sort((a,b)=>a.full_name&&b.full_name?a.full_name.localeCompare(b.full_name):0),dispatch({type:"setAddresses",payload:{addresses}})}catch(error){const errors=getErrors(error,"addresses");dispatch({type:"setErrors",payload:{errors}})}},getCustomerPaymentSources=async({dispatch,order})=>{(order==null?void 0:order.available_customer_payment_sources)&&dispatch({type:"setPayments",payload:{payments:order.available_customer_payment_sources}})},customerInitialState={errors:[],addresses:[],payments:[]};const type=["setErrors","setCustomerEmail","setAddresses","setPayments"],customerReducer=(state,reducer)=>baseReducer(state,reducer,type);export default customerReducer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "3.5.2",
3
+ "version": "3.6.0",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/index.d.ts",