@shipengine/elements 0.10.1 → 0.10.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.
@@ -9,6 +9,6 @@ export type UseAddressProps = {
9
9
  export declare const useAddress: ({ onChange, onValidation, salesOrder, shipment }: UseAddressProps) => {
10
10
  addressErrors: SE.CodedError[] | undefined;
11
11
  addressPreference: Templates.AddressPreference | undefined;
12
- handleChangeAddress: (shipTo: SE.Address, { shouldValidate }: Templates.OnChangeAddressOptions) => Promise<void>;
12
+ handleChangeAddress: (shipTo: SE.Address, { shouldValidate }: Templates.OnChangeAddressOptions) => Promise<SE.SalesOrderShipment | undefined>;
13
13
  handleParseShipTo: ({ fullAddress }: Templates.AddressParserPayload) => Promise<SE.AddressParseResponse | undefined>;
14
14
  };
@@ -17,7 +17,7 @@ export declare const useShipmentForm: ({ onAddressValidation, onApplyPreset, onC
17
17
  customPackageTypes: SE.Package[] | undefined;
18
18
  errors: SE.CodedError[] | undefined;
19
19
  onApplyPreset: (preset: ShippingPreset) => Promise<void>;
20
- onChangeAddress: (shipTo: SE.Address, { shouldValidate }: import("dist/elements-ui/components/templates").OnChangeAddressOptions) => Promise<void>;
20
+ onChangeAddress: (shipTo: SE.Address, { shouldValidate }: import("dist/elements-ui/components/templates").OnChangeAddressOptions) => Promise<SE.SalesOrderShipment | undefined>;
21
21
  onSubmit: (values: Partial<SE.SalesOrderShipment>) => Promise<SE.SalesOrderShipment | undefined>;
22
22
  onSubmitParseShipTo: ({ fullAddress }: {
23
23
  fullAddress: string;
package/index.cjs CHANGED
@@ -18962,7 +18962,7 @@ const useAddress = ({
18962
18962
  shouldValidate
18963
18963
  }) => __awaiter(void 0, void 0, void 0, function* () {
18964
18964
  if (!shipment) return;
18965
- yield updateShipment(Object.assign(Object.assign({}, shipment), {
18965
+ const updatedShipment = yield updateShipment(Object.assign(Object.assign({}, shipment), {
18966
18966
  shipTo
18967
18967
  }));
18968
18968
  yield onChange === null || onChange === void 0 ? void 0 : onChange(shipment, Object.assign(Object.assign({}, shipment), {
@@ -18971,6 +18971,7 @@ const useAddress = ({
18971
18971
  if (shouldValidate) {
18972
18972
  yield handleValidateAddress(shipTo);
18973
18973
  }
18974
+ return updatedShipment;
18974
18975
  }), [handleValidateAddress, onChange, shipment, updateShipment]);
18975
18976
  react.useEffect(() => {
18976
18977
  if (!addressPreference && (shipment === null || shipment === void 0 ? void 0 : shipment.shipTo)) {
@@ -19391,10 +19392,11 @@ const useRatesForm = ({
19391
19392
  serviceCode
19392
19393
  }));
19393
19394
  if (updatedShipment) {
19395
+ yield requestRates(updatedShipment);
19394
19396
  yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(updatedShipment);
19395
19397
  yield onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
19396
19398
  }
19397
- }), [onRateSaved, onShipmentUpdated, shipment, updateShipment]);
19399
+ }), [onRateSaved, onShipmentUpdated, requestRates, shipment, updateShipment]);
19398
19400
  let errors = [...(ratesErrors !== null && ratesErrors !== void 0 ? ratesErrors : []), ...((_a = ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.errors) !== null && _a !== void 0 ? _a : [])];
19399
19401
  if (beforeCreateError) errors = [...errors, beforeCreateError];
19400
19402
  // Sometimes no rates are returned and no top-level errors are returned
@@ -19520,11 +19522,16 @@ const ConfigureShipment = _a => {
19520
19522
  shipment
19521
19523
  } = _a,
19522
19524
  props = __rest(_a, ["features", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "salesOrder", "shipment"]);
19525
+ const hydrateRef = react.useRef();
19523
19526
  const _b = useRatesForm({
19524
19527
  onBeforeLabelCreate,
19525
19528
  onLabelCreateFailure,
19526
19529
  onLabelCreateSuccess,
19527
- onRateSaved,
19530
+ onRateSaved: updatedShipment => {
19531
+ var _a;
19532
+ (_a = hydrateRef.current) === null || _a === void 0 ? void 0 : _a.call(hydrateRef, updatedShipment);
19533
+ onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
19534
+ },
19528
19535
  onRatesCalculated,
19529
19536
  onShipmentUpdated,
19530
19537
  printLabelLayout,
@@ -19565,6 +19572,7 @@ const ConfigureShipment = _a => {
19565
19572
  }, [resetRates, resetLabel]);
19566
19573
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
19567
19574
  children: [jsxRuntime.jsx(elementsUi.Templates.ShipmentForm, Object.assign({}, shipmentFormProps, props, {
19575
+ hydrateRef: hydrateRef,
19568
19576
  onDirty: handleOnDirty,
19569
19577
  onCharsetWarning: handleCharsetWarning,
19570
19578
  features: features === null || features === void 0 ? void 0 : features.shipmentForm
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useValidateAddresses, useUpdateShipment, useParseAddress, isDomesticAddress, useListCarriers, useListCustomPackageTypes, useCalculateRates, useCreateLabel, useListWarehouses, useListShipments, useCreateShipment, getPendingShipment, getIsCustomsRequiredForSalesOrder, getCustomsFromSalesOrder, useListSalesOrders, useListOrderSources, useRefreshOrderSource, registerElement, useGetShipment, useListLabels, useGetLabel, useVoidLabel } from '@shipengine/elements-core';
2
2
  import { jsxs, Fragment, jsx } from '@emotion/react/jsx-runtime';
3
3
  import { Templates, Loader } from '@shipengine/elements-ui';
4
- import { useState, useCallback, useEffect } from 'react';
4
+ import { useState, useCallback, useEffect, useRef } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
 
7
7
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -18958,7 +18958,7 @@ const useAddress = ({
18958
18958
  shouldValidate
18959
18959
  }) => __awaiter(void 0, void 0, void 0, function* () {
18960
18960
  if (!shipment) return;
18961
- yield updateShipment(Object.assign(Object.assign({}, shipment), {
18961
+ const updatedShipment = yield updateShipment(Object.assign(Object.assign({}, shipment), {
18962
18962
  shipTo
18963
18963
  }));
18964
18964
  yield onChange === null || onChange === void 0 ? void 0 : onChange(shipment, Object.assign(Object.assign({}, shipment), {
@@ -18967,6 +18967,7 @@ const useAddress = ({
18967
18967
  if (shouldValidate) {
18968
18968
  yield handleValidateAddress(shipTo);
18969
18969
  }
18970
+ return updatedShipment;
18970
18971
  }), [handleValidateAddress, onChange, shipment, updateShipment]);
18971
18972
  useEffect(() => {
18972
18973
  if (!addressPreference && (shipment === null || shipment === void 0 ? void 0 : shipment.shipTo)) {
@@ -19387,10 +19388,11 @@ const useRatesForm = ({
19387
19388
  serviceCode
19388
19389
  }));
19389
19390
  if (updatedShipment) {
19391
+ yield requestRates(updatedShipment);
19390
19392
  yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(updatedShipment);
19391
19393
  yield onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
19392
19394
  }
19393
- }), [onRateSaved, onShipmentUpdated, shipment, updateShipment]);
19395
+ }), [onRateSaved, onShipmentUpdated, requestRates, shipment, updateShipment]);
19394
19396
  let errors = [...(ratesErrors !== null && ratesErrors !== void 0 ? ratesErrors : []), ...((_a = ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.errors) !== null && _a !== void 0 ? _a : [])];
19395
19397
  if (beforeCreateError) errors = [...errors, beforeCreateError];
19396
19398
  // Sometimes no rates are returned and no top-level errors are returned
@@ -19516,11 +19518,16 @@ const ConfigureShipment = _a => {
19516
19518
  shipment
19517
19519
  } = _a,
19518
19520
  props = __rest(_a, ["features", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "salesOrder", "shipment"]);
19521
+ const hydrateRef = useRef();
19519
19522
  const _b = useRatesForm({
19520
19523
  onBeforeLabelCreate,
19521
19524
  onLabelCreateFailure,
19522
19525
  onLabelCreateSuccess,
19523
- onRateSaved,
19526
+ onRateSaved: updatedShipment => {
19527
+ var _a;
19528
+ (_a = hydrateRef.current) === null || _a === void 0 ? void 0 : _a.call(hydrateRef, updatedShipment);
19529
+ onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
19530
+ },
19524
19531
  onRatesCalculated,
19525
19532
  onShipmentUpdated,
19526
19533
  printLabelLayout,
@@ -19561,6 +19568,7 @@ const ConfigureShipment = _a => {
19561
19568
  }, [resetRates, resetLabel]);
19562
19569
  return jsxs(Fragment, {
19563
19570
  children: [jsx(Templates.ShipmentForm, Object.assign({}, shipmentFormProps, props, {
19571
+ hydrateRef: hydrateRef,
19564
19572
  onDirty: handleOnDirty,
19565
19573
  onCharsetWarning: handleCharsetWarning,
19566
19574
  features: features === null || features === void 0 ? void 0 : features.shipmentForm
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shipengine/elements",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "peerDependencies": {
5
5
  "@packlink/giger": "*",
6
6
  "react-i18next": "*",
@@ -12,9 +12,9 @@
12
12
  "types": "./index.d.ts",
13
13
  "dependencies": {
14
14
  "react": "^18.2.0",
15
- "@shipengine/elements-core": "0.10.1",
16
- "@shipengine/elements-ui": "0.10.1",
17
- "@shipengine/types": "0.10.1",
15
+ "@shipengine/elements-core": "0.10.2",
16
+ "@shipengine/elements-ui": "0.10.2",
17
+ "@shipengine/types": "0.10.2",
18
18
  "@emotion/react": "^11.10.0",
19
19
  "@packlink/brands": "^3.18.0"
20
20
  }