@shipengine/elements 0.5.6 → 0.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.
@@ -6,18 +6,20 @@ import { RateFormProps } from "../rate-form";
6
6
  export declare type SalesOrderProps = {
7
7
  externalOrderId?: string;
8
8
  externalOrderNumber?: string;
9
- onAddressValidation?: (addressPreference: Templates.AddressPreference) => void;
10
- onChangeAddress?: ShipmentFormProps["onChangeAddress"];
9
+ onAddressValidation?: (addressPreference: Templates.AddressPreference) => Promise<void> | void;
10
+ onApplyPreset?: ShipmentFormProps["onApplyPreset"];
11
11
  onBeforeLabelCreate?: RateFormProps["onBeforeLabelCreate"];
12
+ onChangeAddress?: ShipmentFormProps["onChangeAddress"];
13
+ onChangeShipmentFormMode?: ShipmentFormProps["onChangeShipmentFormMode"];
12
14
  onLabelCreateFailure?: RateFormProps["onLabelCreateFailure"];
13
15
  onLabelCreateSuccess?: RateFormProps["onLabelCreateSuccess"];
14
- onLoad?: (salesOrder: SE.SalesOrder, shipments: SE.SalesOrderShipment[]) => void;
16
+ onLoad?: (salesOrder: SE.SalesOrder, shipments: SE.SalesOrderShipment[]) => Promise<void> | void;
15
17
  onRateSaved?: RateFormProps["onRateSaved"];
16
- onRatesReturned?: (rates: SE.Rate[], shipment: SE.SalesOrderShipment) => void;
17
- onChangeShipmentFormMode?: ShipmentFormProps["onChangeShipmentFormMode"];
18
+ onRatesReturned?: (rates: SE.Rate[], shipment: SE.SalesOrderShipment) => Promise<void> | void;
19
+ onShipmentUpdated?: (shipment: SE.SalesOrderShipment) => Promise<void> | void;
18
20
  onToggleAddressPreferenceDisclosure?: ShipmentFormProps["onToggleAddressPreferenceDisclosure"];
19
21
  orderSourceCode?: string;
20
22
  salesOrderId?: string;
21
23
  shippingPresets?: UseShippingPresetsOptionsProps;
22
24
  };
23
- export declare const SalesOrder: ({ externalOrderId, externalOrderNumber, onAddressValidation, onChangeAddress, onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, onLoad, onRateSaved, onRatesReturned, onChangeShipmentFormMode, onToggleAddressPreferenceDisclosure, orderSourceCode, salesOrderId, shippingPresets, }: SalesOrderProps) => JSX.Element;
25
+ export declare const SalesOrder: ({ externalOrderId, externalOrderNumber, onAddressValidation, onApplyPreset, onBeforeLabelCreate, onChangeAddress, onChangeShipmentFormMode, onLabelCreateFailure, onLabelCreateSuccess, onLoad, onRateSaved, onRatesReturned, onShipmentUpdated, onToggleAddressPreferenceDisclosure, orderSourceCode, salesOrderId, shippingPresets, }: SalesOrderProps) => JSX.Element;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Templates } from "@shipengine/elements-ui";
3
- import SE from "@shipengine/elements-core";
3
+ import SE, { ShippingPreset } from "@shipengine/elements-core";
4
4
  import { UseShippingPresetsOptionsProps } from "@shipengine/elements-ui";
5
5
  export declare type ShipmentFormMode = "browse_rates" | "select_service";
6
6
  export declare type ShipmentUpdatedOptions = {
@@ -10,14 +10,15 @@ export declare type ShipmentUpdatedOptions = {
10
10
  declare type ShipmentFormTemplateProps = React.ComponentProps<typeof Templates.ShipmentForm>;
11
11
  export declare type ShipmentFormProps = {
12
12
  addressPreference?: Templates.AddressPreference;
13
+ onApplyPreset?: (preset: ShippingPreset, shipment?: SE.SalesOrderShipment) => Promise<void> | void;
13
14
  onChangeAddress?: (addressPreference: Templates.AddressPreference) => any | void;
14
15
  onChangeShipmentFormMode?: ShipmentFormTemplateProps["onChangeMode"];
15
16
  onShipmentDirty: () => void;
16
- onShipmentUpdated: (shipment: SE.SalesOrderShipment, options?: ShipmentUpdatedOptions) => void;
17
+ onShipmentUpdated: (shipment: SE.SalesOrderShipment, options?: ShipmentUpdatedOptions) => Promise<void> | void;
17
18
  onToggleAddressPreferenceDisclosure?: ShipmentFormTemplateProps["onToggleAddressPreferenceDisclosure"];
18
19
  salesOrder: SE.SalesOrder;
19
20
  shipment?: SE.SalesOrderShipment;
20
21
  shippingPresets?: UseShippingPresetsOptionsProps;
21
22
  };
22
- export declare const ShipmentForm: ({ addressPreference, onChangeAddress, onChangeShipmentFormMode, onShipmentDirty, onShipmentUpdated, onToggleAddressPreferenceDisclosure, salesOrder, shipment, shippingPresets, }: ShipmentFormProps) => JSX.Element;
23
+ export declare const ShipmentForm: ({ addressPreference, onApplyPreset, onChangeAddress, onChangeShipmentFormMode, onShipmentDirty, onShipmentUpdated, onToggleAddressPreferenceDisclosure, salesOrder, shipment, shippingPresets, }: ShipmentFormProps) => JSX.Element;
23
24
  export {};
package/index.cjs CHANGED
@@ -2731,6 +2731,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
2731
2731
 
2732
2732
  const ShipmentForm = ({
2733
2733
  addressPreference,
2734
+ onApplyPreset,
2734
2735
  onChangeAddress,
2735
2736
  onChangeShipmentFormMode,
2736
2737
  onShipmentDirty,
@@ -2773,7 +2774,7 @@ const ShipmentForm = ({
2773
2774
  }), [createShipment, updateShipment, logger, salesOrder, shipment, t]);
2774
2775
  const handleSubmit = react.useCallback(values => __awaiter(void 0, void 0, void 0, function* () {
2775
2776
  const updatedShipment = yield createOrUpdateShipment(values);
2776
- if (updatedShipment) onShipmentUpdated(updatedShipment, {
2777
+ if (updatedShipment) yield onShipmentUpdated(updatedShipment, {
2777
2778
  shouldCalculateRates: true
2778
2779
  });
2779
2780
  }), [createOrUpdateShipment, onShipmentUpdated]); // Handles any changes to the ship to address as well as handling user
@@ -2787,7 +2788,7 @@ const ShipmentForm = ({
2787
2788
  }));
2788
2789
 
2789
2790
  if (updatedShipment) {
2790
- onShipmentUpdated(updatedShipment, {
2791
+ yield onShipmentUpdated(updatedShipment, {
2791
2792
  shouldCalculateRates: false,
2792
2793
  shouldResetAddressPreference: options.shouldValidate
2793
2794
  });
@@ -2808,10 +2809,14 @@ const ShipmentForm = ({
2808
2809
  packageCode: preset.packageCode
2809
2810
  }] : undefined
2810
2811
  }));
2811
- if (updatedShipment) onShipmentUpdated(updatedShipment, {
2812
- shouldCalculateRates: !!(preset.dimensions && preset.weight),
2813
- shouldResetAddressPreference: false
2814
- });
2812
+
2813
+ if (updatedShipment) {
2814
+ yield onApplyPreset === null || onApplyPreset === void 0 ? void 0 : onApplyPreset(preset, updatedShipment);
2815
+ yield onShipmentUpdated(updatedShipment, {
2816
+ shouldCalculateRates: !!(preset.dimensions && preset.weight),
2817
+ shouldResetAddressPreference: false
2818
+ });
2819
+ }
2815
2820
  });
2816
2821
 
2817
2822
  const handleSubmitParseShipTo = ({
@@ -2830,7 +2835,7 @@ const ShipmentForm = ({
2830
2835
  }));
2831
2836
 
2832
2837
  if (updatedShipment) {
2833
- onShipmentUpdated(updatedShipment);
2838
+ yield onShipmentUpdated(updatedShipment);
2834
2839
  }
2835
2840
  });
2836
2841
 
@@ -20176,14 +20181,16 @@ const SalesOrder = ({
20176
20181
  externalOrderId,
20177
20182
  externalOrderNumber,
20178
20183
  onAddressValidation,
20179
- onChangeAddress,
20184
+ onApplyPreset,
20180
20185
  onBeforeLabelCreate,
20186
+ onChangeAddress,
20187
+ onChangeShipmentFormMode,
20181
20188
  onLabelCreateFailure,
20182
20189
  onLabelCreateSuccess,
20183
20190
  onLoad,
20184
20191
  onRateSaved,
20185
20192
  onRatesReturned,
20186
- onChangeShipmentFormMode,
20193
+ onShipmentUpdated,
20187
20194
  onToggleAddressPreferenceDisclosure,
20188
20195
  orderSourceCode,
20189
20196
  salesOrderId,
@@ -20286,7 +20293,7 @@ const SalesOrder = ({
20286
20293
  validation: result.addressValidation,
20287
20294
  fallbackAddress: currentSalesOrder.shipTo
20288
20295
  });
20289
- onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20296
+ yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20290
20297
  }
20291
20298
  } else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
20292
20299
  // We have a preexisting shipment; validate the address
@@ -20300,7 +20307,7 @@ const SalesOrder = ({
20300
20307
  validation: addressValidation,
20301
20308
  fallbackAddress: currentSalesOrder.shipTo
20302
20309
  });
20303
- onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20310
+ yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20304
20311
  }
20305
20312
  }
20306
20313
  }
@@ -20320,8 +20327,8 @@ const SalesOrder = ({
20320
20327
  const updatedAddressPreference = resetAddressPreference({
20321
20328
  validation: shipment.addressValidation
20322
20329
  });
20323
- onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20324
- onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
20330
+ yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20331
+ yield onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
20325
20332
  }
20326
20333
 
20327
20334
  if (options.shouldCalculateRates) {
@@ -20334,7 +20341,7 @@ const SalesOrder = ({
20334
20341
  : shipment.packages.map(pkg => pkg.packageCode)
20335
20342
  }
20336
20343
  });
20337
- result && (onRatesReturned === null || onRatesReturned === void 0 ? void 0 : onRatesReturned(result.rates, shipment)); // We are hiding, from the user, any errors in the rate response if the response
20344
+ if (result) yield onRatesReturned === null || onRatesReturned === void 0 ? void 0 : onRatesReturned(result.rates, shipment); // We are hiding, from the user, any errors in the rate response if the response
20338
20345
  // contains rates. Log to the console any rate errors if the response has rates.
20339
20346
 
20340
20347
  if ((result === null || result === void 0 ? void 0 : result.errors.length) && result.rates.length) {
@@ -20343,7 +20350,9 @@ const SalesOrder = ({
20343
20350
  }, `Rate response had errors`);
20344
20351
  }
20345
20352
  }
20346
- }), [calculateRates, carriers.data, hasCustomPackage, logger, onChangeAddress, onAddressValidation, onRatesReturned, resetAddressPreference, shipments]);
20353
+
20354
+ yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(shipment);
20355
+ }), [calculateRates, carriers.data, hasCustomPackage, logger, onAddressValidation, onChangeAddress, onRatesReturned, onShipmentUpdated, resetAddressPreference, shipments]);
20347
20356
  const handleShipmentDirty = react.useCallback(() => {
20348
20357
  calculateRates.reset();
20349
20358
  }, [calculateRates]);
@@ -20374,6 +20383,7 @@ const SalesOrder = ({
20374
20383
  }, {
20375
20384
  children: [jsxRuntime.jsx(ShipmentForm, {
20376
20385
  addressPreference: addressPreference,
20386
+ onApplyPreset: onApplyPreset,
20377
20387
  onChangeAddress: onChangeAddress,
20378
20388
  onChangeShipmentFormMode: onChangeShipmentFormMode,
20379
20389
  onShipmentDirty: handleShipmentDirty,
package/index.js CHANGED
@@ -2727,6 +2727,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
2727
2727
 
2728
2728
  const ShipmentForm = ({
2729
2729
  addressPreference,
2730
+ onApplyPreset,
2730
2731
  onChangeAddress,
2731
2732
  onChangeShipmentFormMode,
2732
2733
  onShipmentDirty,
@@ -2769,7 +2770,7 @@ const ShipmentForm = ({
2769
2770
  }), [createShipment, updateShipment, logger, salesOrder, shipment, t]);
2770
2771
  const handleSubmit = useCallback(values => __awaiter(void 0, void 0, void 0, function* () {
2771
2772
  const updatedShipment = yield createOrUpdateShipment(values);
2772
- if (updatedShipment) onShipmentUpdated(updatedShipment, {
2773
+ if (updatedShipment) yield onShipmentUpdated(updatedShipment, {
2773
2774
  shouldCalculateRates: true
2774
2775
  });
2775
2776
  }), [createOrUpdateShipment, onShipmentUpdated]); // Handles any changes to the ship to address as well as handling user
@@ -2783,7 +2784,7 @@ const ShipmentForm = ({
2783
2784
  }));
2784
2785
 
2785
2786
  if (updatedShipment) {
2786
- onShipmentUpdated(updatedShipment, {
2787
+ yield onShipmentUpdated(updatedShipment, {
2787
2788
  shouldCalculateRates: false,
2788
2789
  shouldResetAddressPreference: options.shouldValidate
2789
2790
  });
@@ -2804,10 +2805,14 @@ const ShipmentForm = ({
2804
2805
  packageCode: preset.packageCode
2805
2806
  }] : undefined
2806
2807
  }));
2807
- if (updatedShipment) onShipmentUpdated(updatedShipment, {
2808
- shouldCalculateRates: !!(preset.dimensions && preset.weight),
2809
- shouldResetAddressPreference: false
2810
- });
2808
+
2809
+ if (updatedShipment) {
2810
+ yield onApplyPreset === null || onApplyPreset === void 0 ? void 0 : onApplyPreset(preset, updatedShipment);
2811
+ yield onShipmentUpdated(updatedShipment, {
2812
+ shouldCalculateRates: !!(preset.dimensions && preset.weight),
2813
+ shouldResetAddressPreference: false
2814
+ });
2815
+ }
2811
2816
  });
2812
2817
 
2813
2818
  const handleSubmitParseShipTo = ({
@@ -2826,7 +2831,7 @@ const ShipmentForm = ({
2826
2831
  }));
2827
2832
 
2828
2833
  if (updatedShipment) {
2829
- onShipmentUpdated(updatedShipment);
2834
+ yield onShipmentUpdated(updatedShipment);
2830
2835
  }
2831
2836
  });
2832
2837
 
@@ -20172,14 +20177,16 @@ const SalesOrder = ({
20172
20177
  externalOrderId,
20173
20178
  externalOrderNumber,
20174
20179
  onAddressValidation,
20175
- onChangeAddress,
20180
+ onApplyPreset,
20176
20181
  onBeforeLabelCreate,
20182
+ onChangeAddress,
20183
+ onChangeShipmentFormMode,
20177
20184
  onLabelCreateFailure,
20178
20185
  onLabelCreateSuccess,
20179
20186
  onLoad,
20180
20187
  onRateSaved,
20181
20188
  onRatesReturned,
20182
- onChangeShipmentFormMode,
20189
+ onShipmentUpdated,
20183
20190
  onToggleAddressPreferenceDisclosure,
20184
20191
  orderSourceCode,
20185
20192
  salesOrderId,
@@ -20282,7 +20289,7 @@ const SalesOrder = ({
20282
20289
  validation: result.addressValidation,
20283
20290
  fallbackAddress: currentSalesOrder.shipTo
20284
20291
  });
20285
- onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20292
+ yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20286
20293
  }
20287
20294
  } else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
20288
20295
  // We have a preexisting shipment; validate the address
@@ -20296,7 +20303,7 @@ const SalesOrder = ({
20296
20303
  validation: addressValidation,
20297
20304
  fallbackAddress: currentSalesOrder.shipTo
20298
20305
  });
20299
- onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20306
+ yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20300
20307
  }
20301
20308
  }
20302
20309
  }
@@ -20316,8 +20323,8 @@ const SalesOrder = ({
20316
20323
  const updatedAddressPreference = resetAddressPreference({
20317
20324
  validation: shipment.addressValidation
20318
20325
  });
20319
- onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20320
- onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
20326
+ yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
20327
+ yield onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
20321
20328
  }
20322
20329
 
20323
20330
  if (options.shouldCalculateRates) {
@@ -20330,7 +20337,7 @@ const SalesOrder = ({
20330
20337
  : shipment.packages.map(pkg => pkg.packageCode)
20331
20338
  }
20332
20339
  });
20333
- result && (onRatesReturned === null || onRatesReturned === void 0 ? void 0 : onRatesReturned(result.rates, shipment)); // We are hiding, from the user, any errors in the rate response if the response
20340
+ if (result) yield onRatesReturned === null || onRatesReturned === void 0 ? void 0 : onRatesReturned(result.rates, shipment); // We are hiding, from the user, any errors in the rate response if the response
20334
20341
  // contains rates. Log to the console any rate errors if the response has rates.
20335
20342
 
20336
20343
  if ((result === null || result === void 0 ? void 0 : result.errors.length) && result.rates.length) {
@@ -20339,7 +20346,9 @@ const SalesOrder = ({
20339
20346
  }, `Rate response had errors`);
20340
20347
  }
20341
20348
  }
20342
- }), [calculateRates, carriers.data, hasCustomPackage, logger, onChangeAddress, onAddressValidation, onRatesReturned, resetAddressPreference, shipments]);
20349
+
20350
+ yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(shipment);
20351
+ }), [calculateRates, carriers.data, hasCustomPackage, logger, onAddressValidation, onChangeAddress, onRatesReturned, onShipmentUpdated, resetAddressPreference, shipments]);
20343
20352
  const handleShipmentDirty = useCallback(() => {
20344
20353
  calculateRates.reset();
20345
20354
  }, [calculateRates]);
@@ -20370,6 +20379,7 @@ const SalesOrder = ({
20370
20379
  }, {
20371
20380
  children: [jsx(ShipmentForm, {
20372
20381
  addressPreference: addressPreference,
20382
+ onApplyPreset: onApplyPreset,
20373
20383
  onChangeAddress: onChangeAddress,
20374
20384
  onChangeShipmentFormMode: onChangeShipmentFormMode,
20375
20385
  onShipmentDirty: handleShipmentDirty,
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@shipengine/elements",
3
- "version": "0.5.6",
3
+ "version": "0.6.0",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
9
  "react": "^18.2.0",
10
- "@shipengine/elements-core": "0.5.6",
10
+ "@shipengine/elements-core": "0.6.0",
11
11
  "react-i18next": "^11.18.4",
12
12
  "i18next": "^21.9.1",
13
13
  "i18next-http-backend": "^1.4.1",
14
14
  "i18next-browser-languagedetector": "^6.1.4",
15
- "@shipengine/elements-ui": "0.5.6"
15
+ "@shipengine/elements-ui": "0.6.0"
16
16
  },
17
17
  "peerDependencies": {}
18
18
  }