@shipengine/elements 2.26.4 → 2.26.5

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.
Files changed (68) hide show
  1. package/dist/cjs/components/shipment-not-found-error/shipment-not-found-error.cjs +2 -17
  2. package/dist/cjs/components/suspend-purchase/suspend-purchase.cjs +3 -3
  3. package/dist/cjs/elements/purchase-label/purchase-label.cjs +1 -7
  4. package/dist/cjs/hooks/use-configure-shipment.cjs +17 -127
  5. package/dist/cjs/hooks/use-import-sales-order.cjs +20 -45
  6. package/dist/cjs/locales/en/common.json.cjs +1 -1
  7. package/dist/cjs/locales/en/purchase-label.json.cjs +0 -7
  8. package/dist/cjs/package.json.cjs +1 -1
  9. package/dist/cjs/workflows/label-workflow/label-workflow.cjs +2 -26
  10. package/dist/esm/components/shipment-not-found-error/shipment-not-found-error.js +2 -17
  11. package/dist/esm/components/suspend-purchase/suspend-purchase.js +3 -3
  12. package/dist/esm/elements/purchase-label/purchase-label.js +1 -7
  13. package/dist/esm/hooks/use-configure-shipment.js +17 -127
  14. package/dist/esm/hooks/use-import-sales-order.js +22 -47
  15. package/dist/esm/locales/en/common.json.js +1 -1
  16. package/dist/esm/locales/en/purchase-label.json.js +0 -7
  17. package/dist/esm/package.json.js +1 -1
  18. package/dist/esm/workflows/label-workflow/label-workflow.js +2 -26
  19. package/dist/types/components/shipment-not-found-error/shipment-not-found-error.d.ts +2 -3
  20. package/dist/types/components/shipment-not-found-error/shipment-not-found-error.d.ts.map +1 -1
  21. package/dist/types/components/suspend-purchase/suspend-purchase.d.ts +2 -3
  22. package/dist/types/components/suspend-purchase/suspend-purchase.d.ts.map +1 -1
  23. package/dist/types/elements/labels-grid/labels-grid.d.ts +0 -7
  24. package/dist/types/elements/labels-grid/labels-grid.d.ts.map +1 -1
  25. package/dist/types/elements/manage-carriers/manage-carriers.d.ts +0 -7
  26. package/dist/types/elements/manage-carriers/manage-carriers.d.ts.map +1 -1
  27. package/dist/types/elements/manage-external-carriers/manage-external-carriers.d.ts +0 -7
  28. package/dist/types/elements/manage-external-carriers/manage-external-carriers.d.ts.map +1 -1
  29. package/dist/types/elements/manage-funding/manage-funding-element.d.ts +0 -7
  30. package/dist/types/elements/manage-funding/manage-funding-element.d.ts.map +1 -1
  31. package/dist/types/elements/manage-warehouses/manage-warehouses.d.ts +0 -7
  32. package/dist/types/elements/manage-warehouses/manage-warehouses.d.ts.map +1 -1
  33. package/dist/types/elements/payment-method-settings/payment-method-settings-element.d.ts +0 -7
  34. package/dist/types/elements/payment-method-settings/payment-method-settings-element.d.ts.map +1 -1
  35. package/dist/types/elements/purchase-label/purchase-label.d.ts +0 -7
  36. package/dist/types/elements/purchase-label/purchase-label.d.ts.map +1 -1
  37. package/dist/types/elements/select-label-layout/select-label-layout-element.d.ts +0 -7
  38. package/dist/types/elements/select-label-layout/select-label-layout-element.d.ts.map +1 -1
  39. package/dist/types/elements/shipment-summary/shipment-summary.d.ts +0 -7
  40. package/dist/types/elements/shipment-summary/shipment-summary.d.ts.map +1 -1
  41. package/dist/types/elements/shipments-grid/shipments-grid.d.ts +0 -7
  42. package/dist/types/elements/shipments-grid/shipments-grid.d.ts.map +1 -1
  43. package/dist/types/elements/theme-creator/theme-creator.d.ts +0 -7
  44. package/dist/types/elements/theme-creator/theme-creator.d.ts.map +1 -1
  45. package/dist/types/elements/transaction-history/transaction-history-element.d.ts +0 -7
  46. package/dist/types/elements/transaction-history/transaction-history-element.d.ts.map +1 -1
  47. package/dist/types/elements/unit-settings/unit-settings-element.d.ts +0 -7
  48. package/dist/types/elements/unit-settings/unit-settings-element.d.ts.map +1 -1
  49. package/dist/types/elements/vat-settings/vat-settings-element.d.ts +0 -7
  50. package/dist/types/elements/vat-settings/vat-settings-element.d.ts.map +1 -1
  51. package/dist/types/elements/void-label/void-label.d.ts +0 -7
  52. package/dist/types/elements/void-label/void-label.d.ts.map +1 -1
  53. package/dist/types/hooks/use-configure-shipment.d.ts.map +1 -1
  54. package/dist/types/hooks/use-import-sales-order.d.ts +1 -20
  55. package/dist/types/hooks/use-import-sales-order.d.ts.map +1 -1
  56. package/dist/types/locales/en/index.d.ts +0 -7
  57. package/dist/types/locales/en/index.d.ts.map +1 -1
  58. package/dist/types/workflows/account-settings/account-settings.d.ts +0 -7
  59. package/dist/types/workflows/account-settings/account-settings.d.ts.map +1 -1
  60. package/dist/types/workflows/carrier-services/carrier-services.d.ts +0 -7
  61. package/dist/types/workflows/carrier-services/carrier-services.d.ts.map +1 -1
  62. package/dist/types/workflows/connect-external-carrier/connect-external-carrier.d.ts +0 -7
  63. package/dist/types/workflows/connect-external-carrier/connect-external-carrier.d.ts.map +1 -1
  64. package/dist/types/workflows/label-workflow/label-workflow.d.ts +0 -7
  65. package/dist/types/workflows/label-workflow/label-workflow.d.ts.map +1 -1
  66. package/dist/types/workflows/onboarding/onboarding.d.ts +0 -7
  67. package/dist/types/workflows/onboarding/onboarding.d.ts.map +1 -1
  68. package/package.json +1 -1
@@ -7,26 +7,12 @@ var reactI18next = require('react-i18next');
7
7
  var shipmentNotFoundError_styles = require('./shipment-not-found-error.styles.cjs');
8
8
 
9
9
  const ShipmentNotFoundError = ({
10
- identifier,
10
+ shipmentId,
11
11
  onCreateNewShipment
12
12
  }) => {
13
13
  const {
14
14
  t
15
15
  } = reactI18next.useTranslation(["common", "purchase-label"]);
16
- const getIdentifierInfo = identifier => {
17
- // Order should match the actual search priority in useConfigureShipment:
18
- const identifierKeys = ["shipmentId", "externalShipmentId", "salesOrderId", "externalOrderId", "externalOrderNumber"];
19
- const foundKey = identifierKeys.find(key => identifier === null || identifier === void 0 ? void 0 : identifier[key]);
20
- const identifierKey = foundKey || "shipmentId";
21
- return {
22
- type: t(`purchase-label:identifierTypes.${identifierKey}`),
23
- value: identifier === null || identifier === void 0 ? void 0 : identifier[identifierKey]
24
- };
25
- };
26
- const {
27
- type: identifierType,
28
- value: identifierNumber
29
- } = getIdentifierInfo(identifier);
30
16
  return jsxRuntime.jsxs("div", {
31
17
  css: shipmentNotFoundError_styles.styles.container,
32
18
  children: [jsxRuntime.jsx("div", {
@@ -38,8 +24,7 @@ const ShipmentNotFoundError = ({
38
24
  }), jsxRuntime.jsx("div", {
39
25
  css: shipmentNotFoundError_styles.styles.message,
40
26
  children: t("common:errorMessages.shipmentNotFound", {
41
- identifierType,
42
- identifierNumber
27
+ id: shipmentId
43
28
  })
44
29
  }), jsxRuntime.jsx(giger.Button, {
45
30
  "data-testid": "create-new-shipment",
@@ -11,7 +11,7 @@ const SuspendPurchase = ({
11
11
  isLoading,
12
12
  data,
13
13
  onCreateNewShipment,
14
- identifier
14
+ shipmentId
15
15
  }) => {
16
16
  const {
17
17
  t
@@ -38,8 +38,8 @@ const SuspendPurchase = ({
38
38
  throw new Error(t("common:errorMessages.labelHasBeenPurchased"));
39
39
  case "shipment_not_found":
40
40
  return jsxRuntime.jsx(shipmentNotFoundError.ShipmentNotFoundError, {
41
- identifier: identifier,
42
- onCreateNewShipment: onCreateNewShipment
41
+ onCreateNewShipment: onCreateNewShipment,
42
+ shipmentId: shipmentId
43
43
  });
44
44
  }
45
45
  }
@@ -92,15 +92,9 @@ const Component = _a => {
92
92
  return jsxRuntime.jsx(suspendPurchase.SuspendPurchase, {
93
93
  data: shipment || salesOrder,
94
94
  errors: errors,
95
- identifier: {
96
- externalOrderId,
97
- externalOrderNumber,
98
- externalShipmentId,
99
- salesOrderId,
100
- shipmentId
101
- },
102
95
  isLoading: isLoading || insuranceIsLoading,
103
96
  onCreateNewShipment: createNewShipmentForNotFound,
97
+ shipmentId: shipmentId,
104
98
  children: jsxRuntime.jsx(configureShipment.ConfigureShipment, Object.assign({
105
99
  currency: currency,
106
100
  features: features,
@@ -22,8 +22,8 @@ const useConfigureShipment = ({
22
22
  warehouseId,
23
23
  useWarehouses = true
24
24
  }) => {
25
- // Track when user manually created a shipment for a "not found" case
26
- const [manuallyCreatedShipmentId, setManuallyCreatedShipmentId] = React.useState();
25
+ // Track when we've created a replacement shipment for a "not found" case
26
+ const [replacementShipmentId, setReplacementShipmentId] = React.useState();
27
27
  // Queue of incomplete requirement keys (i.e., Ship From addresses, Warehouses, Carriers)
28
28
  const incompleteRequirementsKeys = React.useMemo(() => [], []);
29
29
  const {
@@ -47,7 +47,6 @@ const useConfigureShipment = ({
47
47
  // Dont run Sales Order Import unless the Sales order info is present
48
48
  enabled: !!externalOrderNumber || !!orderSourceCode || !!salesOrderId || !!externalOrderId,
49
49
  externalOrderId,
50
- externalOrderNumber,
51
50
  orderSourceCode,
52
51
  salesOrderId
53
52
  });
@@ -64,49 +63,24 @@ const useConfigureShipment = ({
64
63
  isInitialLoading: isExternalShipmentInitialLoading,
65
64
  isFetching: isExternalShipmentFetching
66
65
  } = reactApi.useGetShipmentByExternalId({
67
- enabled: !!externalShipmentId && !shipmentId && !manuallyCreatedShipmentId,
66
+ enabled: !!externalShipmentId && !shipmentId,
68
67
  queryFnParams: {
69
68
  externalId: externalShipmentId !== null && externalShipmentId !== void 0 ? externalShipmentId : ""
70
69
  }
71
- // TODO: weird refetch on focus behavior
72
70
  });
73
- // #region List Sales Order Shipments
74
- const externalOrderIds = React.useMemo(() => {
75
- return externalOrderId ? [externalOrderId] : undefined;
76
- }, [externalOrderId]);
77
- const salesOrderIds = React.useMemo(() => {
78
- return salesOrderId ? [salesOrderId] : salesOrder$1 ? [salesOrder$1.salesOrderId] :
79
- // TODO: current workaround - revert to being undefined rather than empty list
80
- [];
81
- }, [salesOrderId, salesOrder$1]);
82
- const shipmentIds = React.useMemo(() => {
83
- return manuallyCreatedShipmentId ? [manuallyCreatedShipmentId] : shipmentId ? [shipmentId] : externalShipment ? [externalShipment.shipmentId] : newV1Shipment ? [newV1Shipment.shipments[0].shipmentId] : undefined;
84
- }, [manuallyCreatedShipmentId, shipmentId, externalShipment, newV1Shipment]);
85
- const listSalesOrderShipmentsParams = React.useMemo(() => {
86
- // TODO: useListSalesOrderShipments needs to be able to use the enabled prop, this is a workaround
87
- // Prevent query with stale params during shipment creation or when V1 shipment exists but manuallyCreatedShipmentId not set
88
- if (creatingV1Shipment && !manuallyCreatedShipmentId || newV1Shipment && !manuallyCreatedShipmentId) {
89
- return {};
90
- }
91
- if (manuallyCreatedShipmentId) {
92
- return {
93
- shipmentIds
94
- };
95
- }
96
- return {
97
- externalOrderIds,
98
- salesOrderIds,
99
- shipmentIds
100
- };
101
- }, [manuallyCreatedShipmentId, externalOrderIds, salesOrderIds, shipmentIds, creatingV1Shipment, newV1Shipment]);
102
71
  const {
103
72
  data: salesOrderShipments,
104
73
  error: listSalesOrderShipmentsErrors,
105
74
  refetch: refetchSalesOrderShipments,
106
75
  isInitialLoading: listSalesOrderShipmentsInitiallyLoading,
107
76
  isFetching: listSalesOrderShipmentsIsFetching
108
- } = reactApi.useListSalesOrderShipments(listSalesOrderShipmentsParams);
109
- // #endregion
77
+ } = reactApi.useListSalesOrderShipments({
78
+ externalOrderIds: externalOrderId ? [externalOrderId] : undefined,
79
+ salesOrderIds: salesOrderId ? [salesOrderId] : salesOrder$1 ? [salesOrder$1.salesOrderId] :
80
+ // TODO: current workaround - revert to being undefined rather than empty list
81
+ [],
82
+ shipmentIds: replacementShipmentId ? [replacementShipmentId] : shipmentId ? [shipmentId] : externalShipment ? [externalShipment.shipmentId] : newV1Shipment ? [newV1Shipment.shipments[0].shipmentId] : undefined
83
+ });
110
84
  const {
111
85
  error: createSalesOrderShipmentErrors,
112
86
  mutateAsync: createSalesOrderShipment,
@@ -131,7 +105,6 @@ const useConfigureShipment = ({
131
105
  }
132
106
  return null;
133
107
  }), [createV1Shipment, defaultShipFromAddress, defaultWarehouse, warehouseId, refetchSalesOrderShipments]);
134
- // #region Create Sales Order Shipment
135
108
  // Handles the creation of new shipments for the sales order flow and one-off flow
136
109
  const handleShipmentCreation = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
137
110
  var _a, _b, _c;
@@ -181,23 +154,17 @@ const useConfigureShipment = ({
181
154
  }
182
155
  // Create a Shipment for one-off flow
183
156
  if (!salesOrderId && !externalOrderId && !externalOrderNumber && !orderSourceCode && !shipmentId && !externalShipmentId) {
184
- const v1Shipment = yield createV1ShipmentWithDefaults();
185
- // Set manuallyCreatedShipmentId to ensure proper query parameter handling
186
- if (v1Shipment) {
187
- setManuallyCreatedShipmentId(v1Shipment.shipments[0].shipmentId);
188
- }
157
+ yield createV1ShipmentWithDefaults();
189
158
  }
190
159
  }), [createSalesOrderShipment, createV1ShipmentWithDefaults, creatingSalesOrderShipment, creatingV1Shipment, defaultShipFromAddress, defaultWarehouse, externalOrderId, externalOrderNumber, externalShipmentId, incompleteRequirementsKeys, isExternalShipmentFetching, isExternalShipmentInitialLoading, isFetchingWarehouses, isInitialLoadingWarehouses, labelPurchasedSalesOrderShipment, listSalesOrderShipmentsInitiallyLoading, listSalesOrderShipmentsIsFetching, orderSourceCode, pendingSalesOrderShipment, salesOrder$1, salesOrderId, salesOrderShipmentCreated, shipFromAddresses === null || shipFromAddresses === void 0 ? void 0 : shipFromAddresses.length, shipmentId, useWarehouses, v1shipmentCreated, warehouseId, warehouses$1]);
191
- // #endregion
192
160
  const createNewShipmentForNotFound = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
193
161
  // Force create a new shipment even if shipmentId exists (for shipment_not_found case)
194
162
  const v1Shipment = yield createV1ShipmentWithDefaults();
195
163
  if (v1Shipment) {
196
- setManuallyCreatedShipmentId(v1Shipment.shipments[0].shipmentId);
197
- // Refetch to ensure we have the latest shipment data
198
- yield refetchSalesOrderShipments();
164
+ // Store the new shipment ID to override the stale one
165
+ setReplacementShipmentId(v1Shipment.shipments[0].shipmentId);
199
166
  }
200
- }), [createV1ShipmentWithDefaults, refetchSalesOrderShipments]);
167
+ }), [createV1ShipmentWithDefaults]);
201
168
  const refetchPendingSalesOrderShipments = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
202
169
  const {
203
170
  data: shipments
@@ -221,83 +188,7 @@ const useConfigureShipment = ({
221
188
  if (isInitialLoadingCarriers || isFetchingCarriers) return;
222
189
  if ((carriers === null || carriers === void 0 ? void 0 : carriers.length) === 0) incompleteRequirementsKeys.push("no_carriers");
223
190
  }, [carriers, incompleteRequirementsKeys, isFetchingCarriers, isInitialLoadingCarriers]);
224
- const isConfigureShipmentLoading = React.useMemo(() => {
225
- if (isSalesOrderLoading) return true;
226
- if (listSalesOrderShipmentsInitiallyLoading) return true;
227
- if (listSalesOrderShipmentsIsFetching) return true;
228
- if (creatingSalesOrderShipment) return true;
229
- if (creatingV1Shipment) return true;
230
- // Include external shipment loading states to prevent premature error display
231
- // Only keep loading if we're actually fetching and don't have an error yet
232
- // Skip this check if we already have an error to avoid infinite loading
233
- if (externalShipmentId && isExternalShipmentFetching && !getExternalShipmentErrors && !isExternalShipmentInitialLoading) {
234
- return true;
235
- }
236
- // Check if this is a one-off flow (no identifiers provided)
237
- const isOneOffFlow = !salesOrderId && !externalOrderId && !externalOrderNumber && !orderSourceCode && !shipmentId && !externalShipmentId;
238
- // For one-off flow, keep loading until we have shipment data or V1 creation is complete
239
- if (isOneOffFlow && !pendingSalesOrderShipment && !labelPurchasedSalesOrderShipment) {
240
- return true;
241
- }
242
- // Only consider empty salesOrderShipments array as loading if we're not initially loading and have valid identifiers
243
- const shouldReturnTrueForEmptyShipments = (salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length) === 0 && !listSalesOrderShipmentsInitiallyLoading && !listSalesOrderShipmentsIsFetching;
244
- if (shouldReturnTrueForEmptyShipments) {
245
- return true;
246
- }
247
- return false;
248
- }, [isSalesOrderLoading, listSalesOrderShipmentsInitiallyLoading, listSalesOrderShipmentsIsFetching, creatingSalesOrderShipment, creatingV1Shipment, isExternalShipmentInitialLoading, isExternalShipmentFetching, getExternalShipmentErrors,
249
- // This was missing!
250
- salesOrderId, externalOrderId, externalOrderNumber, orderSourceCode, shipmentId, externalShipmentId, pendingSalesOrderShipment, labelPurchasedSalesOrderShipment, salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length]);
251
- // #region Custom Error Mapping
252
- const hasGetShipmentErrors = React.useMemo(() => {
253
- // Check for explicit API errors
254
- if (listSalesOrderShipmentsErrors) return true;
255
- if (getExternalShipmentErrors) return true;
256
- if (importSalesOrderErrors) return true;
257
- // Only treat empty results as error if we're not loading and have finished initial fetch
258
- if ((salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length) === 0 && shipmentId && !listSalesOrderShipmentsInitiallyLoading && !listSalesOrderShipmentsIsFetching) {
259
- return true;
260
- }
261
- return false;
262
- }, [listSalesOrderShipmentsErrors, getExternalShipmentErrors, importSalesOrderErrors, salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length, shipmentId, listSalesOrderShipmentsInitiallyLoading, listSalesOrderShipmentsIsFetching]);
263
- const hasValidShipmentData = React.useMemo(() => {
264
- if (manuallyCreatedShipmentId) return true;
265
- if (pendingSalesOrderShipment) return true;
266
- if (labelPurchasedSalesOrderShipment) return true;
267
- return false;
268
- }, [labelPurchasedSalesOrderShipment, manuallyCreatedShipmentId, pendingSalesOrderShipment]);
269
- const showShipmentNotFoundError = React.useMemo(() => {
270
- // Don't show error if we have a manually created shipment
271
- if (manuallyCreatedShipmentId) {
272
- return false;
273
- }
274
- // Don't show error if we're creating a V1 shipment
275
- if (creatingV1Shipment || newV1Shipment) {
276
- return false;
277
- }
278
- // For external shipment ID, show error if we're not in loading state
279
- // and we don't have valid shipment data
280
- if (externalShipmentId && !isConfigureShipmentLoading && !hasValidShipmentData) {
281
- return true;
282
- }
283
- // Don't show error if external shipment is still loading, unless we have explicit errors
284
- if (externalShipmentId && (isExternalShipmentInitialLoading || isExternalShipmentFetching) && !getExternalShipmentErrors) {
285
- return false;
286
- }
287
- // Show error immediately if we have shipment errors, even if still loading
288
- if (hasGetShipmentErrors) {
289
- return true;
290
- }
291
- // Check if this is a one-off flow (no identifiers provided)
292
- const isOneOffFlow = !salesOrderId && !externalOrderId && !externalOrderNumber && !orderSourceCode && !shipmentId && !externalShipmentId;
293
- // Don't show error for one-off flow until we've attempted shipment creation
294
- if (isOneOffFlow && !v1shipmentCreated) {
295
- return false;
296
- }
297
- // Otherwise, only show if not loading and no valid shipment data
298
- return !isConfigureShipmentLoading && !hasValidShipmentData;
299
- }, [manuallyCreatedShipmentId, creatingV1Shipment, newV1Shipment, hasGetShipmentErrors, isExternalShipmentInitialLoading, isExternalShipmentFetching, getExternalShipmentErrors, listSalesOrderShipmentsErrors, importSalesOrderErrors, salesOrderId, externalOrderId, externalOrderNumber, orderSourceCode, shipmentId, externalShipmentId, v1shipmentCreated, isConfigureShipmentLoading, hasValidShipmentData, pendingSalesOrderShipment, externalShipment]);
300
- const errors = [...(listWarehouseErrors !== null && listWarehouseErrors !== void 0 ? listWarehouseErrors : []), ...(createSalesOrderShipmentErrors !== null && createSalesOrderShipmentErrors !== void 0 ? createSalesOrderShipmentErrors : []), ...(createV1ShipmentErrors !== null && createV1ShipmentErrors !== void 0 ? createV1ShipmentErrors : []), ...(errorWhenShipmentCancelled && cancelledShipment ? [new reactApi.CodedError("shipment_cancelled", {
191
+ const errors = [...(listWarehouseErrors !== null && listWarehouseErrors !== void 0 ? listWarehouseErrors : []), ...(createSalesOrderShipmentErrors !== null && createSalesOrderShipmentErrors !== void 0 ? createSalesOrderShipmentErrors : []), ...(createV1ShipmentErrors !== null && createV1ShipmentErrors !== void 0 ? createV1ShipmentErrors : []), ...(listSalesOrderShipmentsErrors !== null && listSalesOrderShipmentsErrors !== void 0 ? listSalesOrderShipmentsErrors : []), ...(getExternalShipmentErrors !== null && getExternalShipmentErrors !== void 0 ? getExternalShipmentErrors : []), ...(importSalesOrderErrors !== null && importSalesOrderErrors !== void 0 ? importSalesOrderErrors : []), ...(errorWhenShipmentCancelled && cancelledShipment ? [new reactApi.CodedError("shipment_cancelled", {
301
192
  errorCode: "invalid_status",
302
193
  errorSource: "elements",
303
194
  errorType: "business_rules"
@@ -309,17 +200,16 @@ const useConfigureShipment = ({
309
200
  errorCode: "unknown",
310
201
  errorSource: "elements",
311
202
  errorType: "business_rules"
312
- })] : []), ...(showShipmentNotFoundError ? [new reactApi.CodedError("shipment_not_found", {
203
+ })] : []), ...((salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length) === 0 && shipmentId ? [new reactApi.CodedError("shipment_not_found", {
313
204
  errorCode: "invalid_status",
314
205
  errorSource: "elements",
315
206
  errorType: "business_rules"
316
207
  })] : [])];
317
- // #endregion
318
208
  return {
319
209
  carriers,
320
210
  createNewShipmentForNotFound,
321
211
  errors: errors.length > 0 ? errors : undefined,
322
- isLoading: isConfigureShipmentLoading && errors.length === 0,
212
+ isLoading: (isSalesOrderLoading || !(salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length) || creatingSalesOrderShipment) && errors.length === 0,
323
213
  refetchPendingSalesOrderShipments,
324
214
  salesOrder: salesOrder$1,
325
215
  shipment: pendingSalesOrderShipment !== null && pendingSalesOrderShipment !== void 0 ? pendingSalesOrderShipment : labelPurchasedSalesOrderShipment,
@@ -5,49 +5,26 @@ var reactApi = require('@shipengine/react-api');
5
5
  var reactQuery = require('@tanstack/react-query');
6
6
  var React = require('react');
7
7
 
8
- /**
9
- * Imports and retrieves sales orders by either:
10
- * - Sales order ID lookup
11
- * - External order ID/number search
12
- *
13
- * 1. First attempts to find the sales order using provided identifiers
14
- * 2. If no order is found and initial fetches have run, automatically refreshes order sources
15
- * 3. Invalidates relevant queries after successful refresh to refetch updated data
16
- *
17
- * @returns Object:
18
- * - `salesOrder`: The found sales order, or undefined
19
- * - `isLoading`: Boolean indicating if the hook is currently loading data
20
- * - `errors`: Array of errors from failed queries, or undefined
21
- */
22
8
  const useImportSalesOrder = ({
23
9
  enabled,
24
10
  externalOrderId,
25
- externalOrderNumber,
26
11
  orderSourceCode,
27
12
  salesOrderId
28
13
  }) => {
29
14
  var _a, _b, _c;
30
15
  const queryClient = reactQuery.useQueryClient();
31
16
  const [refreshAttempted, setRefreshAttempted] = React.useState(false);
32
- // Fetch sales order by External Order ID or External Order Number
33
- const salesOrderByExternalIdQuery = reactApi.useListSalesOrders({
34
- externalOrderId,
35
- externalOrderNumber
17
+ // attempt to get sales order through external id means
18
+ const orderByExternalIdQuery = reactApi.useGetSalesOrderByExternalOrderId(externalOrderId, {
19
+ enabled: enabled && !!externalOrderId && !salesOrderId
36
20
  });
37
21
  // if an order was found through external search disable this query
38
- const salesOrderByIdQuery = reactApi.useGetSalesOrder(salesOrderId, {
22
+ const orderByIdQuery = reactApi.useGetSalesOrder(salesOrderId, {
39
23
  enabled: enabled && !!salesOrderId
40
24
  });
41
- const salesOrder = React.useMemo(() => {
42
- if (salesOrderId) {
43
- return salesOrderByIdQuery.data;
44
- } else if (salesOrderByExternalIdQuery.data && salesOrderByExternalIdQuery.data.length > 0) {
45
- return salesOrderByExternalIdQuery.data[0];
46
- }
47
- return undefined;
48
- }, [salesOrderId, salesOrderByIdQuery.data, salesOrderByExternalIdQuery.data]);
25
+ const salesOrder = React.useMemo(() => salesOrderId ? orderByIdQuery.data : orderByExternalIdQuery.data, [salesOrderId, orderByIdQuery.data, orderByExternalIdQuery.data]);
49
26
  // Determine if the initial fetch attempts (if applicable) have settled without finding data
50
- const initialFetchSettled = (salesOrderId ? !salesOrderByIdQuery.isInitialLoading && !salesOrderByIdQuery.isFetching : true) && ((externalOrderNumber || externalOrderId) && !salesOrderId ? !salesOrderByExternalIdQuery.isLoading && !salesOrderByExternalIdQuery.isFetching : true);
27
+ const initialFetchSettled = (salesOrderId ? !orderByIdQuery.isInitialLoading && !orderByIdQuery.isFetching : true) && (externalOrderId && !salesOrderId ? !orderByExternalIdQuery.isLoading && !orderByExternalIdQuery.isFetching : true);
51
28
  const shouldAttemptRefresh = enabled && initialFetchSettled && !salesOrder && !refreshAttempted;
52
29
  const listOrderSourcesQuery = reactApi.useListOrderSources({
53
30
  enabled: shouldAttemptRefresh
@@ -57,17 +34,6 @@ const useImportSalesOrder = ({
57
34
  isLoading: isRefreshingOrderSource,
58
35
  mutateAsync: refreshOrderSource
59
36
  } = reactApi.useRefreshOrderSource();
60
- const invalidateSalesOrderQueries = React.useCallback(() => {
61
- if (salesOrderId) {
62
- void queryClient.invalidateQueries({
63
- queryKey: ["useGetSalesOrder", salesOrderId]
64
- });
65
- } else if (externalOrderId || externalOrderNumber) {
66
- void queryClient.invalidateQueries({
67
- queryKey: ["useListSalesOrders", externalOrderId, externalOrderNumber]
68
- });
69
- }
70
- }, [queryClient, salesOrderId, externalOrderId, externalOrderNumber]);
71
37
  React.useEffect(() => {
72
38
  if (listOrderSourcesQuery.isSuccess && listOrderSourcesQuery.data && shouldAttemptRefresh && !isRefreshingOrderSource) {
73
39
  const orderSourcesToRefresh = orderSourceCode ? listOrderSourcesQuery.data.filter(o => o.orderSourceCode.includes(orderSourceCode) && o.active) : listOrderSourcesQuery.data.filter(o => o.active);
@@ -75,20 +41,29 @@ const useImportSalesOrder = ({
75
41
  setRefreshAttempted(true);
76
42
  void (() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
77
43
  yield Promise.all(orderSourcesToRefresh.map(o => refreshOrderSource(o.orderSourceId, {
78
- // Invalidate relevant queries
44
+ // Invalidate relevant queries on successful refresh
79
45
  onSuccess: () => {
80
- invalidateSalesOrderQueries();
46
+ if (salesOrderId) {
47
+ void queryClient.invalidateQueries({
48
+ queryKey: ["useGetSalesOrder", salesOrderId]
49
+ });
50
+ }
51
+ if (externalOrderId && !salesOrderId) {
52
+ void queryClient.invalidateQueries({
53
+ queryKey: ["useGetSalesOrderByExternalOrderId", externalOrderId]
54
+ });
55
+ }
81
56
  }
82
57
  })));
83
58
  }))();
84
59
  }
85
60
  }
86
61
  }, [externalOrderId, isRefreshingOrderSource, listOrderSourcesQuery.data, listOrderSourcesQuery.isSuccess, orderSourceCode, queryClient, refreshOrderSource, salesOrderId, shouldAttemptRefresh]);
87
- const isLoading = salesOrderByIdQuery.isInitialLoading || salesOrderByExternalIdQuery.isInitialLoading || listOrderSourcesQuery.isInitialLoading || isRefreshingOrderSource;
88
- const errors = [...((_a = salesOrderByIdQuery.error) !== null && _a !== void 0 ? _a : []), ...((_b = salesOrderByExternalIdQuery.error) !== null && _b !== void 0 ? _b : []), ...((_c = listOrderSourcesQuery.error) !== null && _c !== void 0 ? _c : []), ...(refreshOrderSourceErrors !== null && refreshOrderSourceErrors !== void 0 ? refreshOrderSourceErrors : [])];
62
+ const isLoading = orderByIdQuery.isInitialLoading || orderByExternalIdQuery.isInitialLoading || listOrderSourcesQuery.isInitialLoading || isRefreshingOrderSource;
63
+ const errors = [...((_a = orderByIdQuery.error) !== null && _a !== void 0 ? _a : []), ...((_b = orderByExternalIdQuery.error) !== null && _b !== void 0 ? _b : []), ...((_c = listOrderSourcesQuery.error) !== null && _c !== void 0 ? _c : []), ...(refreshOrderSourceErrors !== null && refreshOrderSourceErrors !== void 0 ? refreshOrderSourceErrors : [])];
89
64
  return {
90
65
  errors: errors.length > 0 ? errors : undefined,
91
- isLoading: isLoading && errors.length === 0,
66
+ isLoading,
92
67
  salesOrder
93
68
  };
94
69
  };
@@ -170,7 +170,7 @@ var common = {
170
170
  invalidNameOrCompany: "Recipient name and company name (if provided) must have two characters in first and last name.",
171
171
  parsingFailure: "Parsing failed. Please check address and try again.",
172
172
  incompleteLabelPurchaseRequirements: "Please add your {{requirements}} to continue purchasing a label.",
173
- shipmentNotFound: "Cannot find {{identifierType}}: {{identifierNumber}}",
173
+ shipmentNotFound: "Cannot find shipment with ID: {{id}}.",
174
174
  shipmentCancelled: "This shipment is Cancelled in ShipStation. Log into ShipStation to restore the order to Awaiting Shipment status.",
175
175
  unableToLoad: {
176
176
  accountSettings: "Unable to load account settings",
@@ -32,13 +32,6 @@ var purchaseLabel = {
32
32
  saveRateFailedMessage: "Saving DHL Express Worldwide rates is temporarily unavailable. Please try again later.",
33
33
  saveRateFailedTitle: "Unable To Save Rate"
34
34
  },
35
- identifierTypes: {
36
- externalOrderId: "External Order ID",
37
- externalOrderNumber: "External Order Number",
38
- externalShipmentId: "External Shipment ID",
39
- salesOrderId: "Sales Order ID",
40
- shipmentId: "Shipment ID"
41
- },
42
35
  errorTypes: {
43
36
  results: "No results returned"
44
37
  },
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var version = "2.26.4";
3
+ var version = "2.26.5";
4
4
 
5
5
  exports.version = version;
@@ -62,31 +62,7 @@ const Component = _a => {
62
62
  }));
63
63
  // Track if we have a shipment_not_found error to avoid reusing the bad shipment ID
64
64
  const hasShipmentNotFoundError = configureShipmentErrors === null || configureShipmentErrors === void 0 ? void 0 : configureShipmentErrors.some(error => error.message === "shipment_not_found");
65
- const getMultiplexedIdentifier = React.useCallback(() => {
66
- if (_multiplexedId && "shipmentId" in _multiplexedId) {
67
- return {
68
- shipmentId: _multiplexedId.shipmentId
69
- };
70
- } else if (_multiplexedId && "externalShipmentId" in _multiplexedId) {
71
- return {
72
- externalShipmentId: _multiplexedId.externalShipmentId
73
- };
74
- } else if (_multiplexedId && "salesOrderId" in _multiplexedId) {
75
- return {
76
- salesOrderId: _multiplexedId.salesOrderId
77
- };
78
- } else if (_multiplexedId && "externalOrderNumber" in _multiplexedId) {
79
- return {
80
- externalOrderNumber: _multiplexedId.externalOrderNumber
81
- };
82
- } else if (_multiplexedId && "externalOrderId" in _multiplexedId) {
83
- return {
84
- externalOrderId: _multiplexedId.externalOrderId
85
- };
86
- }
87
- return {};
88
- }, [_multiplexedId]);
89
- const shipmentId = getMultiplexedIdentifier().shipmentId;
65
+ const shipmentId = _multiplexedId && "shipmentId" in _multiplexedId ? _multiplexedId.shipmentId : undefined;
90
66
  const {
91
67
  data: insuranceAccount,
92
68
  isInitialLoading: insuranceIsLoading
@@ -204,9 +180,9 @@ const Component = _a => {
204
180
  return jsxRuntime.jsx(suspendPurchase.SuspendPurchase, {
205
181
  data: shipment$1 || salesOrder,
206
182
  errors: errors.length ? errors : undefined,
207
- identifier: getMultiplexedIdentifier(),
208
183
  isLoading: isLabelsLoading || isConfiguringShipment || insuranceIsLoading,
209
184
  onCreateNewShipment: createNewShipmentForNotFound,
185
+ shipmentId: shipmentId,
210
186
  children: element && getElement(element)
211
187
  });
212
188
  };
@@ -5,26 +5,12 @@ import { useTranslation } from 'react-i18next';
5
5
  import { styles } from './shipment-not-found-error.styles.js';
6
6
 
7
7
  const ShipmentNotFoundError = ({
8
- identifier,
8
+ shipmentId,
9
9
  onCreateNewShipment
10
10
  }) => {
11
11
  const {
12
12
  t
13
13
  } = useTranslation(["common", "purchase-label"]);
14
- const getIdentifierInfo = identifier => {
15
- // Order should match the actual search priority in useConfigureShipment:
16
- const identifierKeys = ["shipmentId", "externalShipmentId", "salesOrderId", "externalOrderId", "externalOrderNumber"];
17
- const foundKey = identifierKeys.find(key => identifier === null || identifier === void 0 ? void 0 : identifier[key]);
18
- const identifierKey = foundKey || "shipmentId";
19
- return {
20
- type: t(`purchase-label:identifierTypes.${identifierKey}`),
21
- value: identifier === null || identifier === void 0 ? void 0 : identifier[identifierKey]
22
- };
23
- };
24
- const {
25
- type: identifierType,
26
- value: identifierNumber
27
- } = getIdentifierInfo(identifier);
28
14
  return jsxs("div", {
29
15
  css: styles.container,
30
16
  children: [jsx("div", {
@@ -36,8 +22,7 @@ const ShipmentNotFoundError = ({
36
22
  }), jsx("div", {
37
23
  css: styles.message,
38
24
  children: t("common:errorMessages.shipmentNotFound", {
39
- identifierType,
40
- identifierNumber
25
+ id: shipmentId
41
26
  })
42
27
  }), jsx(Button, {
43
28
  "data-testid": "create-new-shipment",
@@ -9,7 +9,7 @@ const SuspendPurchase = ({
9
9
  isLoading,
10
10
  data,
11
11
  onCreateNewShipment,
12
- identifier
12
+ shipmentId
13
13
  }) => {
14
14
  const {
15
15
  t
@@ -36,8 +36,8 @@ const SuspendPurchase = ({
36
36
  throw new Error(t("common:errorMessages.labelHasBeenPurchased"));
37
37
  case "shipment_not_found":
38
38
  return jsx(ShipmentNotFoundError, {
39
- identifier: identifier,
40
- onCreateNewShipment: onCreateNewShipment
39
+ onCreateNewShipment: onCreateNewShipment,
40
+ shipmentId: shipmentId
41
41
  });
42
42
  }
43
43
  }
@@ -90,15 +90,9 @@ const Component = _a => {
90
90
  return jsx(SuspendPurchase, {
91
91
  data: shipment || salesOrder,
92
92
  errors: errors,
93
- identifier: {
94
- externalOrderId,
95
- externalOrderNumber,
96
- externalShipmentId,
97
- salesOrderId,
98
- shipmentId
99
- },
100
93
  isLoading: isLoading || insuranceIsLoading,
101
94
  onCreateNewShipment: createNewShipmentForNotFound,
95
+ shipmentId: shipmentId,
102
96
  children: jsx(ConfigureShipment, Object.assign({
103
97
  currency: currency,
104
98
  features: features,