@commercelayer/react-components 3.12.5 → 3.12.6

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,8 +1,15 @@
1
- import React, { ReactNode } from 'react';
1
+ import { ReactNode } from 'react';
2
2
  import { LoaderType } from '../typings/index';
3
3
  declare type ShipmentProps = {
4
4
  children: ReactNode;
5
5
  loader?: LoaderType;
6
+ autoSelectSingleShippingMethod?: boolean;
6
7
  };
7
- declare const Shipment: React.FunctionComponent<ShipmentProps>;
8
+ declare function Shipment({ children, loader, autoSelectSingleShippingMethod, }: ShipmentProps): JSX.Element;
9
+ declare namespace Shipment {
10
+ var propTypes: {
11
+ children: import("prop-types").Validator<boolean | import("react").ReactChild | import("react").ReactFragment | import("react").ReactPortal | (() => ReactNode)>;
12
+ };
13
+ var displayName: string;
14
+ }
8
15
  export default Shipment;
@@ -1 +1 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{Fragment,useContext,useState,useEffect}from"react";import ShipmentContext from"../context/ShipmentContext";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";import components from"../config/components";import getLoaderComponent from"../utils/getLoaderComponent";const propTypes=components.Shipment.propTypes,displayName=components.Shipment.displayName,Shipment=({children,loader="Loading..."})=>{const[loading,setLoading]=useState(!0),{shipments,deliveryLeadTimes}=useContext(ShipmentContext);useEffect(()=>(shipments&&setLoading(!1),()=>{setLoading(!0)}),[shipments]);const components2=shipments&&shipments.map((shipment,k)=>{var _a;const shipmentLineItems=shipment.shipment_line_items,lineItems=shipmentLineItems==null?void 0:shipmentLineItems.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=(_a=shipment.shipping_method)===null||_a===void 0?void 0:_a.id,stockTransfers=shipment.stock_transfers,times=deliveryLeadTimes==null?void 0:deliveryLeadTimes.filter(time=>{var _a2,_b;return((_a2=time.stock_location)===null||_a2===void 0?void 0:_a2.id)===((_b=shipment.stock_location)===null||_b===void 0?void 0:_b.id)}),shipmentProps={lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return _jsx(ShipmentChildrenContext.Provider,Object.assign({value:shipmentProps},{children}),k)});return loading?getLoaderComponent(loader):_jsx(Fragment,{children:components2})};Shipment.propTypes=propTypes,Shipment.displayName=displayName;export default Shipment;
1
+ import{jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{useContext,useState,useEffect}from"react";import ShipmentContext from"../context/ShipmentContext";import ShipmentChildrenContext from"../context/ShipmentChildrenContext";import components from"../config/components";import getLoaderComponent from"../utils/getLoaderComponent";const propTypes=components.Shipment.propTypes,displayName=components.Shipment.displayName;export default function Shipment({children,loader="Loading...",autoSelectSingleShippingMethod=!1}){const[loading,setLoading]=useState(!0),{shipments,deliveryLeadTimes,setShippingMethod}=useContext(ShipmentContext);useEffect(()=>(shipments&&setLoading(!1),autoSelectSingleShippingMethod&&shipments&&shipments.forEach(shipment=>{var _a;const isSingle=((_a=shipment==null?void 0:shipment.available_shipping_methods)===null||_a===void 0?void 0:_a.length)===1;if(!(shipment==null?void 0:shipment.shipping_method)&&isSingle){const[shippingMethod]=(shipment==null?void 0:shipment.available_shipping_methods)||[];setShippingMethod(shipment==null?void 0:shipment.id,shippingMethod==null?void 0:shippingMethod.id)}}),()=>{setLoading(!0)}),[shipments]);const components2=shipments&&shipments.map((shipment,k)=>{var _a;const shipmentLineItems=shipment.shipment_line_items,lineItems=shipmentLineItems==null?void 0:shipmentLineItems.map(shipmentLineItem=>{const l=shipmentLineItem.line_item;return l&&(l.quantity=shipmentLineItem.quantity),l}),shippingMethods=shipment.available_shipping_methods,currentShippingMethodId=autoSelectSingleShippingMethod&&shippingMethods&&shippingMethods.length===1?shippingMethods[0].id:(_a=shipment.shipping_method)===null||_a===void 0?void 0:_a.id,stockTransfers=shipment.stock_transfers,times=deliveryLeadTimes==null?void 0:deliveryLeadTimes.filter(time=>{var _a2,_b;return((_a2=time.stock_location)===null||_a2===void 0?void 0:_a2.id)===((_b=shipment.stock_location)===null||_b===void 0?void 0:_b.id)}),shipmentProps={lineItems,shippingMethods,currentShippingMethodId,stockTransfers,deliveryLeadTimes:times,shipment,keyNumber:k+1};return _jsx(ShipmentChildrenContext.Provider,Object.assign({value:shipmentProps},{children}),k)});return loading?getLoaderComponent(loader):_jsx(_Fragment,{children:components2})}Shipment.propTypes=propTypes,Shipment.displayName=displayName;
@@ -1,5 +1,5 @@
1
1
  import { FunctionComponent, ReactNode } from 'react';
2
- import { ShippingMethod } from '@commercelayer/sdk';
2
+ import type { ShippingMethod } from '@commercelayer/sdk';
3
3
  export declare type ShippingMethodRadioButtonType = Omit<ShippingMethodRadioButtonProps, 'children'> & {
4
4
  shippingMethod: ShippingMethod;
5
5
  shipmentId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/react-components",
3
- "version": "3.12.5",
3
+ "version": "3.12.6",
4
4
  "description": "The Official Commerce Layer React Components",
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/index.d.ts",