@shipengine/elements 0.3.4 → 0.3.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,9 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import SE from "@shipengine/elements-core";
3
3
  export declare type RateFormProps = {
4
- rates?: SE.Rate[];
5
- loading?: boolean;
6
4
  errors?: SE.CodedError[];
5
+ loading?: boolean;
7
6
  onLabelCreated?: (label: SE.Label) => void;
7
+ onRateSaved?: (shipment: SE.SalesOrderShipment) => void;
8
+ rates?: SE.Rate[];
9
+ shipment?: SE.SalesOrderShipment;
8
10
  };
9
- export declare const RateForm: ({ rates, loading, errors, onLabelCreated }: RateFormProps) => JSX.Element;
11
+ export declare const RateForm: ({ errors, loading, onLabelCreated, onRateSaved, rates, shipment, }: RateFormProps) => JSX.Element;
package/index.cjs CHANGED
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var elementsCore = require('@shipengine/elements-core');
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var react = require('react');
8
+ var deprecatedUi = require('@shipengine/deprecated-ui');
8
9
  var elementsUi = require('@shipengine/elements-ui');
9
- var elementsUncontrolled = require('@shipengine/elements-uncontrolled');
10
10
 
11
11
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
12
12
 
@@ -2782,7 +2782,7 @@ const ShipmentForm = ({
2782
2782
  }
2783
2783
  }, [validateAddresses, salesOrder]);
2784
2784
  const errors = [...(updateShipment.errors || []), ...(createShipment.errors || [])];
2785
- return jsxRuntime.jsx(elementsUncontrolled.UncontrolledShipmentForm, {
2785
+ return jsxRuntime.jsx(elementsUi.Templates.ShipmentForm, {
2786
2786
  errors: errors,
2787
2787
  onDirty: onShipmentDirty,
2788
2788
  shipToValidationStatus: (_a = validateAddresses.data) === null || _a === void 0 ? void 0 : _a[0].status,
@@ -2795,28 +2795,45 @@ const ShipmentForm = ({
2795
2795
  };
2796
2796
 
2797
2797
  const RateForm = ({
2798
- rates,
2799
- loading: _loading = false,
2800
2798
  errors,
2801
- onLabelCreated
2799
+ loading: _loading = false,
2800
+ onLabelCreated,
2801
+ onRateSaved,
2802
+ rates,
2803
+ shipment
2802
2804
  }) => {
2803
2805
  var _a;
2804
2806
 
2805
2807
  const createLabel = elementsCore.useCreateLabel();
2808
+ const updateShipment = elementsCore.useUpdateShipment({
2809
+ shipmentId: shipment === null || shipment === void 0 ? void 0 : shipment.shipmentId
2810
+ });
2806
2811
 
2807
2812
  const handleSubmit = values => __awaiter(void 0, void 0, void 0, function* () {
2808
2813
  const label = yield createLabel.trigger(values);
2809
2814
  if (label) onLabelCreated === null || onLabelCreated === void 0 ? void 0 : onLabelCreated(label);
2810
2815
  });
2811
2816
 
2817
+ const handleSave = rate => __awaiter(void 0, void 0, void 0, function* () {
2818
+ if (shipment) {
2819
+ const updatedShipment = yield updateShipment.trigger(Object.assign(Object.assign({}, shipment), {
2820
+ carrierId: rate.carrierId,
2821
+ serviceCode: rate.serviceCode
2822
+ }));
2823
+ if (updatedShipment) onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
2824
+ }
2825
+ });
2826
+
2812
2827
  const carriers = elementsCore.useListCarriers();
2813
2828
  const mergedErrors = [...(errors !== null && errors !== void 0 ? errors : []), ...((_a = createLabel.errors) !== null && _a !== void 0 ? _a : [])];
2814
- return jsxRuntime.jsx(elementsUncontrolled.UncontrolledRateForm, {
2815
- errors: mergedErrors,
2816
- rates: rates,
2829
+ return jsxRuntime.jsx(elementsUi.Templates.RateForm, {
2817
2830
  carriers: carriers.data,
2831
+ errors: mergedErrors,
2832
+ loading: _loading,
2833
+ onSave: handleSave,
2818
2834
  onSubmit: handleSubmit,
2819
- loading: _loading
2835
+ rates: rates,
2836
+ shipment: shipment
2820
2837
  });
2821
2838
  };
2822
2839
 
@@ -2880,6 +2897,7 @@ const SalesOrder = ({
2880
2897
  const handleShipmentUpdated = react.useCallback(shipment => __awaiter(void 0, void 0, void 0, function* () {
2881
2898
  var _e, _f;
2882
2899
 
2900
+ yield shipments.mutate();
2883
2901
  const result = yield calculateRates.trigger({
2884
2902
  shipmentId: shipment.shipmentId,
2885
2903
  rateOptions: {
@@ -2895,33 +2913,33 @@ const SalesOrder = ({
2895
2913
  obj: result.errors
2896
2914
  }, `Rate response had errors`);
2897
2915
  }
2898
- }), [calculateRates, carriers.data, logger]);
2916
+ }), [calculateRates, carriers.data, logger, shipments]);
2899
2917
  const handleShipmentDirty = react.useCallback(() => {
2900
2918
  calculateRates.reset();
2901
2919
  }, [calculateRates]);
2902
2920
  const handleLabelCreated = react.useCallback(label => __awaiter(void 0, void 0, void 0, function* () {
2903
2921
  if (label) onPurchase === null || onPurchase === void 0 ? void 0 : onPurchase(label);
2904
2922
  }), [onPurchase]);
2905
- if (salesOrders.isLoading) return jsxRuntime.jsx(elementsUi.Spinner, {
2923
+ if (salesOrders.isLoading) return jsxRuntime.jsx(deprecatedUi.Spinner, {
2906
2924
  children: t("loading.salesOrder")
2907
2925
  });
2908
2926
  if (salesOrders.errors) throw new Error(salesOrders.errors.map(e => e.message).join(", "));
2909
- if (orderSources.isLoading) return jsxRuntime.jsx(elementsUi.Spinner, {
2927
+ if (orderSources.isLoading) return jsxRuntime.jsx(deprecatedUi.Spinner, {
2910
2928
  children: t("loading.importingSalesOrder")
2911
2929
  });
2912
2930
  if (orderSources.errors) throw new Error(orderSources.errors.map(e => e.message).join(", "));
2913
2931
  if (!salesOrders.data) throw new Error(t("errorMessages.unableToLoad.salesOrder"));
2914
- if (salesOrders.data.length === 0) return jsxRuntime.jsx(elementsUi.Spinner, {
2932
+ if (salesOrders.data.length === 0) return jsxRuntime.jsx(deprecatedUi.Spinner, {
2915
2933
  children: t("loading.importingSalesOrder")
2916
2934
  });
2917
- if (shipments.isLoading) return jsxRuntime.jsx(elementsUi.Spinner, {
2935
+ if (shipments.isLoading) return jsxRuntime.jsx(deprecatedUi.Spinner, {
2918
2936
  children: t("loading.shipment")
2919
2937
  });
2920
2938
  if (shipments.errors) throw new Error(shipments.errors.map(e => e.message).join(", "));
2921
2939
  if (!shipments.data) throw new Error(t("errorMessages.unableToLoad.shipment"));
2922
2940
  const salesOrder = salesOrders.data[0];
2923
2941
  const shipment = shipments.data.find(s => s.shipmentStatus === "pending");
2924
- return jsxRuntime.jsxs(elementsUncontrolled.UncontrolledSalesOrder, Object.assign({
2942
+ return jsxRuntime.jsxs(elementsUi.Templates.SalesOrder, Object.assign({
2925
2943
  salesOrder: salesOrder
2926
2944
  }, {
2927
2945
  children: [jsxRuntime.jsx(ShipmentForm, {
@@ -2933,16 +2951,14 @@ const SalesOrder = ({
2933
2951
  errors: [...((_a = calculateRates.errors) !== null && _a !== void 0 ? _a : []), ...((_c = (_b = calculateRates.data) === null || _b === void 0 ? void 0 : _b.errors) !== null && _c !== void 0 ? _c : [])],
2934
2952
  loading: calculateRates.isMutating,
2935
2953
  onLabelCreated: handleLabelCreated,
2936
- rates: (_d = calculateRates.data) === null || _d === void 0 ? void 0 : _d.rates
2954
+ onRateSaved: handleShipmentUpdated,
2955
+ rates: (_d = calculateRates.data) === null || _d === void 0 ? void 0 : _d.rates,
2956
+ shipment: shipment
2937
2957
  })]
2938
2958
  }));
2939
2959
  };
2940
2960
 
2941
- var config = {
2942
- sentryDSN: "https://94ade54a9f5046d5a9c84a93874fcc75@o106853.ingest.sentry.io/6624796"
2943
- };
2944
-
2945
- const Element$2 = elementsCore.registerElement("purchase-label", SalesOrder, config);
2961
+ const Element$2 = elementsCore.registerElement("purchase-label", SalesOrder);
2946
2962
 
2947
2963
  const Shipment = ({
2948
2964
  shipmentId,
@@ -2965,7 +2981,7 @@ const Shipment = ({
2965
2981
  });
2966
2982
  const warehouses = elementsCore.useListWarehouses();
2967
2983
  const carriers = elementsCore.useListCarriers();
2968
- if (!shipment.data && !shipment.errors) return jsxRuntime.jsx(elementsUi.Spinner, {
2984
+ if (!shipment.data && !shipment.errors) return jsxRuntime.jsx(deprecatedUi.Spinner, {
2969
2985
  children: t("loading.shipment")
2970
2986
  });
2971
2987
  if (shipment.errors) throw new Error(shipment.errors.map(e => e.message).join(", "));
@@ -2976,7 +2992,7 @@ const Shipment = ({
2976
2992
  return w.warehouseId === ((_a = shipment.data) === null || _a === void 0 ? void 0 : _a.warehouseId);
2977
2993
  });
2978
2994
  const salesOrder = (_c = salesOrders.data) === null || _c === void 0 ? void 0 : _c[0];
2979
- return jsxRuntime.jsx(elementsUncontrolled.UncontrolledShipment, {
2995
+ return jsxRuntime.jsx(elementsUi.Templates.Shipment, {
2980
2996
  carriers: carriers.data,
2981
2997
  labels: labels.data,
2982
2998
  onClickPurchaseLabel: onClickPurchaseLabel,
@@ -3011,7 +3027,7 @@ const VoidLabel = ({
3011
3027
  yield voidLabel.trigger(label.data);
3012
3028
  });
3013
3029
 
3014
- return jsxRuntime.jsx(elementsUncontrolled.UncontrolledVoidLabel, {
3030
+ return jsxRuntime.jsx(elementsUi.Templates.VoidLabel, {
3015
3031
  salesOrder: (_c = salesOrders.data) === null || _c === void 0 ? void 0 : _c[0],
3016
3032
  shipment: shipment.data,
3017
3033
  onComplete: onComplete,
@@ -3021,9 +3037,9 @@ const VoidLabel = ({
3021
3037
  });
3022
3038
  };
3023
3039
 
3024
- const Element$1 = elementsCore.registerElement("view-shipment", Shipment, config);
3040
+ const Element$1 = elementsCore.registerElement("view-shipment", Shipment);
3025
3041
 
3026
- const Element = elementsCore.registerElement("void-label", VoidLabel, config);
3042
+ const Element = elementsCore.registerElement("void-label", VoidLabel);
3027
3043
 
3028
3044
  exports.PurchaseLabel = Element$2;
3029
3045
  exports.ViewShipment = Element$1;
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { useTranslation, useLogger, useListWarehouses, useListCarriers, useCreateShipment, useUpdateShipment, useValidateAddresses, useCreateLabel, useListSalesOrders, useListOrderSources, useRefreshOrderSource, useCalculateRates, useListShipments, registerElement, useGetShipment, useListLabels, useGetLabel, useVoidLabel } from '@shipengine/elements-core';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { useEffect, useCallback } from 'react';
4
- import { Spinner } from '@shipengine/elements-ui';
5
- import { UncontrolledShipmentForm, UncontrolledRateForm, UncontrolledSalesOrder, UncontrolledShipment, UncontrolledVoidLabel } from '@shipengine/elements-uncontrolled';
4
+ import { Spinner } from '@shipengine/deprecated-ui';
5
+ import { Templates } from '@shipengine/elements-ui';
6
6
 
7
7
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
8
 
@@ -2778,7 +2778,7 @@ const ShipmentForm = ({
2778
2778
  }
2779
2779
  }, [validateAddresses, salesOrder]);
2780
2780
  const errors = [...(updateShipment.errors || []), ...(createShipment.errors || [])];
2781
- return jsx(UncontrolledShipmentForm, {
2781
+ return jsx(Templates.ShipmentForm, {
2782
2782
  errors: errors,
2783
2783
  onDirty: onShipmentDirty,
2784
2784
  shipToValidationStatus: (_a = validateAddresses.data) === null || _a === void 0 ? void 0 : _a[0].status,
@@ -2791,28 +2791,45 @@ const ShipmentForm = ({
2791
2791
  };
2792
2792
 
2793
2793
  const RateForm = ({
2794
- rates,
2795
- loading: _loading = false,
2796
2794
  errors,
2797
- onLabelCreated
2795
+ loading: _loading = false,
2796
+ onLabelCreated,
2797
+ onRateSaved,
2798
+ rates,
2799
+ shipment
2798
2800
  }) => {
2799
2801
  var _a;
2800
2802
 
2801
2803
  const createLabel = useCreateLabel();
2804
+ const updateShipment = useUpdateShipment({
2805
+ shipmentId: shipment === null || shipment === void 0 ? void 0 : shipment.shipmentId
2806
+ });
2802
2807
 
2803
2808
  const handleSubmit = values => __awaiter(void 0, void 0, void 0, function* () {
2804
2809
  const label = yield createLabel.trigger(values);
2805
2810
  if (label) onLabelCreated === null || onLabelCreated === void 0 ? void 0 : onLabelCreated(label);
2806
2811
  });
2807
2812
 
2813
+ const handleSave = rate => __awaiter(void 0, void 0, void 0, function* () {
2814
+ if (shipment) {
2815
+ const updatedShipment = yield updateShipment.trigger(Object.assign(Object.assign({}, shipment), {
2816
+ carrierId: rate.carrierId,
2817
+ serviceCode: rate.serviceCode
2818
+ }));
2819
+ if (updatedShipment) onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
2820
+ }
2821
+ });
2822
+
2808
2823
  const carriers = useListCarriers();
2809
2824
  const mergedErrors = [...(errors !== null && errors !== void 0 ? errors : []), ...((_a = createLabel.errors) !== null && _a !== void 0 ? _a : [])];
2810
- return jsx(UncontrolledRateForm, {
2811
- errors: mergedErrors,
2812
- rates: rates,
2825
+ return jsx(Templates.RateForm, {
2813
2826
  carriers: carriers.data,
2827
+ errors: mergedErrors,
2828
+ loading: _loading,
2829
+ onSave: handleSave,
2814
2830
  onSubmit: handleSubmit,
2815
- loading: _loading
2831
+ rates: rates,
2832
+ shipment: shipment
2816
2833
  });
2817
2834
  };
2818
2835
 
@@ -2876,6 +2893,7 @@ const SalesOrder = ({
2876
2893
  const handleShipmentUpdated = useCallback(shipment => __awaiter(void 0, void 0, void 0, function* () {
2877
2894
  var _e, _f;
2878
2895
 
2896
+ yield shipments.mutate();
2879
2897
  const result = yield calculateRates.trigger({
2880
2898
  shipmentId: shipment.shipmentId,
2881
2899
  rateOptions: {
@@ -2891,7 +2909,7 @@ const SalesOrder = ({
2891
2909
  obj: result.errors
2892
2910
  }, `Rate response had errors`);
2893
2911
  }
2894
- }), [calculateRates, carriers.data, logger]);
2912
+ }), [calculateRates, carriers.data, logger, shipments]);
2895
2913
  const handleShipmentDirty = useCallback(() => {
2896
2914
  calculateRates.reset();
2897
2915
  }, [calculateRates]);
@@ -2917,7 +2935,7 @@ const SalesOrder = ({
2917
2935
  if (!shipments.data) throw new Error(t("errorMessages.unableToLoad.shipment"));
2918
2936
  const salesOrder = salesOrders.data[0];
2919
2937
  const shipment = shipments.data.find(s => s.shipmentStatus === "pending");
2920
- return jsxs(UncontrolledSalesOrder, Object.assign({
2938
+ return jsxs(Templates.SalesOrder, Object.assign({
2921
2939
  salesOrder: salesOrder
2922
2940
  }, {
2923
2941
  children: [jsx(ShipmentForm, {
@@ -2929,16 +2947,14 @@ const SalesOrder = ({
2929
2947
  errors: [...((_a = calculateRates.errors) !== null && _a !== void 0 ? _a : []), ...((_c = (_b = calculateRates.data) === null || _b === void 0 ? void 0 : _b.errors) !== null && _c !== void 0 ? _c : [])],
2930
2948
  loading: calculateRates.isMutating,
2931
2949
  onLabelCreated: handleLabelCreated,
2932
- rates: (_d = calculateRates.data) === null || _d === void 0 ? void 0 : _d.rates
2950
+ onRateSaved: handleShipmentUpdated,
2951
+ rates: (_d = calculateRates.data) === null || _d === void 0 ? void 0 : _d.rates,
2952
+ shipment: shipment
2933
2953
  })]
2934
2954
  }));
2935
2955
  };
2936
2956
 
2937
- var config = {
2938
- sentryDSN: "https://94ade54a9f5046d5a9c84a93874fcc75@o106853.ingest.sentry.io/6624796"
2939
- };
2940
-
2941
- const Element$2 = registerElement("purchase-label", SalesOrder, config);
2957
+ const Element$2 = registerElement("purchase-label", SalesOrder);
2942
2958
 
2943
2959
  const Shipment = ({
2944
2960
  shipmentId,
@@ -2972,7 +2988,7 @@ const Shipment = ({
2972
2988
  return w.warehouseId === ((_a = shipment.data) === null || _a === void 0 ? void 0 : _a.warehouseId);
2973
2989
  });
2974
2990
  const salesOrder = (_c = salesOrders.data) === null || _c === void 0 ? void 0 : _c[0];
2975
- return jsx(UncontrolledShipment, {
2991
+ return jsx(Templates.Shipment, {
2976
2992
  carriers: carriers.data,
2977
2993
  labels: labels.data,
2978
2994
  onClickPurchaseLabel: onClickPurchaseLabel,
@@ -3007,7 +3023,7 @@ const VoidLabel = ({
3007
3023
  yield voidLabel.trigger(label.data);
3008
3024
  });
3009
3025
 
3010
- return jsx(UncontrolledVoidLabel, {
3026
+ return jsx(Templates.VoidLabel, {
3011
3027
  salesOrder: (_c = salesOrders.data) === null || _c === void 0 ? void 0 : _c[0],
3012
3028
  shipment: shipment.data,
3013
3029
  onComplete: onComplete,
@@ -3017,8 +3033,8 @@ const VoidLabel = ({
3017
3033
  });
3018
3034
  };
3019
3035
 
3020
- const Element$1 = registerElement("view-shipment", Shipment, config);
3036
+ const Element$1 = registerElement("view-shipment", Shipment);
3021
3037
 
3022
- const Element = registerElement("void-label", VoidLabel, config);
3038
+ const Element = registerElement("void-label", VoidLabel);
3023
3039
 
3024
3040
  export { Element$2 as PurchaseLabel, Element$1 as ViewShipment, Element as VoidLabel };
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@shipengine/elements",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "@shipengine/elements-core": "0.3.4",
10
- "@shipengine/elements-uncontrolled": "0.3.4",
9
+ "@shipengine/elements-core": "0.3.6",
10
+ "@shipengine/elements-ui": "0.3.6",
11
11
  "react": "^18.2.0",
12
- "@shipengine/elements-ui": "0.3.4"
12
+ "@shipengine/deprecated-ui": "0.3.6"
13
13
  },
14
14
  "peerDependencies": {}
15
15
  }
package/config.d.ts DELETED
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- sentryDSN: string;
3
- };
4
- export default _default;