@shipengine/elements 2.22.0 → 2.23.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.
Files changed (86) hide show
  1. package/cjs/components/grid-controller/grid-controller.cjs +29 -15
  2. package/cjs/components/grid-filters/components/index.cjs +2 -0
  3. package/cjs/components/grid-filters/components/label-status-filter/index.cjs +9 -0
  4. package/cjs/components/grid-filters/components/label-status-filter/label-status-filter-schema.cjs +12 -0
  5. package/cjs/components/grid-filters/components/label-status-filter/label-status-filter.cjs +174 -0
  6. package/cjs/components/grid-filters/components/label-status-filter/label-status-filter.styles.cjs +21 -0
  7. package/cjs/components/grid-filters/components/tracking-status-filter/tracking-status-filter.cjs +21 -12
  8. package/cjs/components/grid-filters/grid-filters.cjs +6 -1
  9. package/cjs/elements/labels-grid/hooks/use-labels-grid.cjs +25 -12
  10. package/cjs/elements/labels-grid/labels-grid.cjs +11 -2
  11. package/cjs/elements/purchase-label/components/customs-forms/customs-forms.cjs +10 -3
  12. package/cjs/elements/purchase-label/components/rate-form/rate-view.cjs +4 -9
  13. package/cjs/elements/purchase-label/components/shipment-form/shipment-form.cjs +11 -5
  14. package/cjs/elements/purchase-label/configure-shipment.cjs +3 -1
  15. package/cjs/elements/purchase-label/hooks/use-rates-form.cjs +38 -16
  16. package/cjs/elements/purchase-label/purchase-label.cjs +0 -1
  17. package/cjs/elements/shipments-grid/hooks/use-shipments-grid.cjs +5 -1
  18. package/cjs/elements/shipments-grid/shipments-grid.cjs +12 -5
  19. package/cjs/hooks/index.cjs +3 -0
  20. package/cjs/hooks/use-configure-shipment.cjs +1 -34
  21. package/cjs/index.cjs +5 -0
  22. package/cjs/locales/en/common.cjs +2 -1
  23. package/cjs/locales/en/purchase-label.cjs +2 -1
  24. package/cjs/package.cjs +1 -1
  25. package/cjs/workflows/label-workflow/label-workflow.cjs +0 -1
  26. package/esm/components/grid-controller/grid-controller.js +29 -15
  27. package/esm/components/grid-filters/components/index.js +1 -0
  28. package/esm/components/grid-filters/components/label-status-filter/index.js +1 -0
  29. package/esm/components/grid-filters/components/label-status-filter/label-status-filter-schema.js +8 -0
  30. package/esm/components/grid-filters/components/label-status-filter/label-status-filter.js +170 -0
  31. package/esm/components/grid-filters/components/label-status-filter/label-status-filter.styles.js +17 -0
  32. package/esm/components/grid-filters/components/tracking-status-filter/tracking-status-filter.js +21 -12
  33. package/esm/components/grid-filters/grid-filters.js +6 -1
  34. package/esm/elements/labels-grid/hooks/use-labels-grid.js +25 -12
  35. package/esm/elements/labels-grid/labels-grid.js +11 -2
  36. package/esm/elements/purchase-label/components/customs-forms/customs-forms.js +10 -3
  37. package/esm/elements/purchase-label/components/rate-form/rate-view.js +4 -9
  38. package/esm/elements/purchase-label/components/shipment-form/shipment-form.js +11 -5
  39. package/esm/elements/purchase-label/configure-shipment.js +3 -1
  40. package/esm/elements/purchase-label/hooks/use-rates-form.js +38 -16
  41. package/esm/elements/purchase-label/purchase-label.js +0 -1
  42. package/esm/elements/shipments-grid/hooks/use-shipments-grid.js +5 -1
  43. package/esm/elements/shipments-grid/shipments-grid.js +12 -5
  44. package/esm/hooks/index.js +1 -0
  45. package/esm/hooks/use-configure-shipment.js +3 -36
  46. package/esm/index.js +2 -0
  47. package/esm/locales/en/common.js +2 -1
  48. package/esm/locales/en/purchase-label.js +2 -1
  49. package/esm/package.js +1 -1
  50. package/esm/workflows/label-workflow/label-workflow.js +0 -1
  51. package/package.json +13 -2
  52. package/types/src/components/grid-controller/grid-controller.d.ts +2 -0
  53. package/types/src/components/grid-filters/components/index.d.ts +1 -0
  54. package/types/src/components/grid-filters/components/label-status-filter/index.d.ts +1 -0
  55. package/types/src/components/grid-filters/components/label-status-filter/label-status-filter-schema.d.ts +12 -0
  56. package/types/src/components/grid-filters/components/label-status-filter/label-status-filter.d.ts +24 -0
  57. package/types/src/components/grid-filters/components/label-status-filter/label-status-filter.styles.d.ts +13 -0
  58. package/types/src/components/grid-filters/grid-filters.d.ts +2 -0
  59. package/types/src/elements/labels-grid/hooks/use-labels-grid.d.ts +2 -1
  60. package/types/src/elements/labels-grid/labels-grid.d.ts +3 -4
  61. package/types/src/elements/manage-carriers/manage-carriers.d.ts +2 -0
  62. package/types/src/elements/manage-external-carriers/manage-external-carriers.d.ts +2 -0
  63. package/types/src/elements/manage-funding/manage-funding-element.d.ts +2 -0
  64. package/types/src/elements/manage-warehouses/manage-warehouses.d.ts +2 -0
  65. package/types/src/elements/payment-method-settings/payment-method-settings-element.d.ts +2 -0
  66. package/types/src/elements/purchase-label/hooks/use-rates-form.d.ts +1 -0
  67. package/types/src/elements/purchase-label/purchase-label.d.ts +11 -9
  68. package/types/src/elements/select-label-layout/select-label-layout-element.d.ts +2 -0
  69. package/types/src/elements/shipment-summary/shipment-summary.d.ts +2 -0
  70. package/types/src/elements/shipments-grid/hooks/use-shipments-grid.d.ts +11 -6
  71. package/types/src/elements/shipments-grid/shipments-grid.d.ts +31 -5
  72. package/types/src/elements/theme-creator/theme-creator.d.ts +2 -0
  73. package/types/src/elements/transaction-history/transaction-history-element.d.ts +2 -0
  74. package/types/src/elements/unit-settings/unit-settings-element.d.ts +2 -0
  75. package/types/src/elements/vat-settings/vat-settings-element.d.ts +2 -0
  76. package/types/src/elements/void-label/void-label.d.ts +33 -0
  77. package/types/src/hooks/index.d.ts +1 -0
  78. package/types/src/hooks/use-configure-shipment.d.ts +1 -2
  79. package/types/src/index.d.ts +5 -0
  80. package/types/src/locales/en/index.d.ts +2 -0
  81. package/types/src/utilities/feature-flags/types.d.ts +5 -1
  82. package/types/src/workflows/account-settings/account-settings.d.ts +2 -0
  83. package/types/src/workflows/carrier-services/carrier-services.d.ts +2 -0
  84. package/types/src/workflows/connect-external-carrier/connect-external-carrier.d.ts +2 -0
  85. package/types/src/workflows/label-workflow/label-workflow.d.ts +10 -1
  86. package/types/src/workflows/onboarding/onboarding.d.ts +2 -0
@@ -0,0 +1,17 @@
1
+ import { createStyles, scopeTheme } from '../../../../utilities/styles.js';
2
+
3
+ const styles = createStyles({
4
+ buttons: theme => ({
5
+ display: "flex",
6
+ gap: scopeTheme(theme).spacing(),
7
+ justifyContent: "end",
8
+ paddingTop: scopeTheme(theme).spacing(2)
9
+ }),
10
+ radioGroup: theme => ({
11
+ display: "flex",
12
+ flexDirection: "column",
13
+ gap: scopeTheme(theme).spacing(0.5)
14
+ })
15
+ });
16
+
17
+ export { styles };
@@ -25,7 +25,7 @@ const TrackingStatusFilter = ({
25
25
  filters,
26
26
  onFiltersUpdated
27
27
  }) => {
28
- var _a;
28
+ var _a, _b, _c, _d;
29
29
  const {
30
30
  t
31
31
  } = useTranslation();
@@ -42,21 +42,24 @@ const TrackingStatusFilter = ({
42
42
  },
43
43
  resolver: validationResolver(trackingStatusFormSchema)
44
44
  });
45
- const determineButtonText = useCallback(filters => {
46
- if (filters.length === 0) {
47
- return t("list-labels:headers.trackingStatus");
48
- } else if (filters.length === 1) {
45
+ const determineButtonText = useCallback(statuses => {
46
+ var _a, _b, _c;
47
+ if (statuses.length === 0) {
48
+ return ((_a = filters === null || filters === void 0 ? void 0 : filters.trackingStatus) === null || _a === void 0 ? void 0 : _a.nickname) || t("list-labels:headers.trackingStatus");
49
+ } else if (statuses.length === 1) {
49
50
  return t("common:grid.filteredTrackingStatus", {
50
- filter: t(`list-labels:trackingStatus.${filters[0]}`)
51
+ filter: t(`list-labels:trackingStatus.${statuses[0]}`),
52
+ name: ((_b = filters === null || filters === void 0 ? void 0 : filters.trackingStatus) === null || _b === void 0 ? void 0 : _b.nickname) || t("list-labels:headers.trackingStatus")
51
53
  });
52
54
  } else {
53
55
  return t("common:grid.filteredTrackingStatus", {
54
- filter: t(`list-labels:trackingStatus.${filters[0]}`)
56
+ filter: t(`list-labels:trackingStatus.${statuses[0]}`),
57
+ name: ((_c = filters === null || filters === void 0 ? void 0 : filters.trackingStatus) === null || _c === void 0 ? void 0 : _c.nickname) || t("list-labels:headers.trackingStatus")
55
58
  }) + t("common:grid.more", {
56
- count: filters.length - 1
59
+ count: statuses.length - 1
57
60
  });
58
61
  }
59
- }, [t]);
62
+ }, [t, (_a = filters === null || filters === void 0 ? void 0 : filters.trackingStatus) === null || _a === void 0 ? void 0 : _a.nickname]);
60
63
  const getUpdatedKeys = useCallback(updatedFields => {
61
64
  return Object.keys(updatedFields).filter(key => updatedFields[key]);
62
65
  }, []);
@@ -76,9 +79,13 @@ const TrackingStatusFilter = ({
76
79
  unknown: filters.trackingStatus.value.includes("unknown")
77
80
  };
78
81
  form.reset(updatedFields);
79
- setButtonText(determineButtonText(getUpdatedKeys(updatedFields)));
82
+ // Only set buttonText when filters are applied
83
+ const updatedKeys = getUpdatedKeys(updatedFields);
84
+ if (updatedKeys.length > 0) {
85
+ setButtonText(determineButtonText(updatedKeys));
86
+ }
80
87
  }
81
- }, [determineButtonText, (_a = filters.trackingStatus) === null || _a === void 0 ? void 0 : _a.value, form, getUpdatedKeys, t]);
88
+ }, [determineButtonText, (_b = filters.trackingStatus) === null || _b === void 0 ? void 0 : _b.value, form, getUpdatedKeys]);
82
89
  const onClearFilters = useCallback(() => {
83
90
  onFiltersUpdated(Object.assign(Object.assign({}, filters), {
84
91
  trackingStatus: Object.assign(Object.assign({}, filters.trackingStatus), {
@@ -111,8 +118,10 @@ const TrackingStatusFilter = ({
111
118
  ref: buttonRef,
112
119
  variant: ButtonVariant.TEXT
113
120
  }, {
114
- children: [jsx("span", {
121
+ children: [isAnyCheckboxChecked ? jsx("span", {
115
122
  children: buttonText
123
+ }) : jsx("span", {
124
+ children: (_d = (_c = filters === null || filters === void 0 ? void 0 : filters.trackingStatus) === null || _c === void 0 ? void 0 : _c.nickname) !== null && _d !== void 0 ? _d : t("list-labels:headers.trackingStatus")
116
125
  }), isAnyCheckboxChecked ?
117
126
  // Show Close Icon
118
127
  jsx(Icon, {
@@ -5,6 +5,7 @@ import { ShipmentIdFilter } from './components/shipment-id-filter/shipment-id-fi
5
5
  import { LabelIdFilter } from './components/label-id-filter/label-id-filter.js';
6
6
  import { CreatedDateFilter } from './components/created-date-filter/created-date-filter.js';
7
7
  import { TrackingStatusFilter } from './components/tracking-status-filter/tracking-status-filter.js';
8
+ import { LabelStatusFilter } from './components/label-status-filter/label-status-filter.js';
8
9
 
9
10
  /**
10
11
  * @internal
@@ -21,7 +22,7 @@ const GridFilters = ({
21
22
  filtersDisabled: _filtersDisabled = false,
22
23
  onClearAllFilters
23
24
  }) => {
24
- var _a, _b, _c;
25
+ var _a, _b, _c, _d;
25
26
  const {
26
27
  t
27
28
  } = useTranslation(["common"]);
@@ -53,6 +54,10 @@ const GridFilters = ({
53
54
  disabled: _filtersDisabled,
54
55
  filters: filters,
55
56
  onFiltersUpdated: onFiltersUpdated
57
+ }), ((_d = filters.status) === null || _d === void 0 ? void 0 : _d.enabled) && jsx(LabelStatusFilter, {
58
+ disabled: _filtersDisabled,
59
+ filters: filters,
60
+ onFiltersUpdated: onFiltersUpdated
56
61
  }), shouldShowClearAll && jsx(Button, Object.assign({
57
62
  disabled: _filtersDisabled,
58
63
  onClick: () => {
@@ -10,11 +10,12 @@ const useLabelsGrid = ({
10
10
  labelStatus,
11
11
  showShipmentIdFilter,
12
12
  showLabelIdFilter,
13
+ showStatusFilter,
13
14
  showTrackingStatusFilter,
14
15
  fetchShipments,
15
16
  sortDir
16
17
  }) => {
17
- var _a, _b, _c, _d, _e, _f;
18
+ var _a, _b, _c, _d, _e, _f, _g, _h;
18
19
  const initialFilters = {
19
20
  labelId: {
20
21
  enabled: !!showLabelIdFilter,
@@ -24,6 +25,10 @@ const useLabelsGrid = ({
24
25
  enabled: !!showShipmentIdFilter,
25
26
  value: ""
26
27
  },
28
+ status: {
29
+ enabled: !!showStatusFilter,
30
+ value: ""
31
+ },
27
32
  trackingStatus: {
28
33
  enabled: !!showTrackingStatusFilter,
29
34
  value: []
@@ -80,13 +85,17 @@ const useLabelsGrid = ({
80
85
  enabled: !!showShipmentIdFilter,
81
86
  value: ""
82
87
  },
88
+ status: {
89
+ enabled: !!showStatusFilter,
90
+ value: ""
91
+ },
83
92
  trackingStatus: {
84
93
  enabled: !!showTrackingStatusFilter,
85
94
  value: []
86
95
  }
87
96
  };
88
97
  setFilters(updatedFilters);
89
- }, [showLabelIdFilter, showShipmentIdFilter, showTrackingStatusFilter]);
98
+ }, [showLabelIdFilter, showShipmentIdFilter, showStatusFilter, showTrackingStatusFilter]);
90
99
  const isTrackingStatusFilterActive = useMemo(() => {
91
100
  var _a, _b;
92
101
  return !!(((_a = filters.trackingStatus) === null || _a === void 0 ? void 0 : _a.enabled) && hasActiveFilterValue((_b = filters.trackingStatus) === null || _b === void 0 ? void 0 : _b.value));
@@ -101,11 +110,11 @@ const useLabelsGrid = ({
101
110
  } = useTrackingStatusFilter({
102
111
  currentPage: page,
103
112
  isActive: isTrackingStatusFilterActive,
104
- labelStatus,
113
+ labelStatus: ((_c = filters.status) === null || _c === void 0 ? void 0 : _c.value) || labelStatus,
105
114
  pageSize,
106
- shipmentId: ((_c = filters.shipmentId) === null || _c === void 0 ? void 0 : _c.value) || undefined,
115
+ shipmentId: ((_d = filters.shipmentId) === null || _d === void 0 ? void 0 : _d.value) || undefined,
107
116
  sortDir: sortDir !== null && sortDir !== void 0 ? sortDir : "desc",
108
- trackingStatusFilters: ((_d = filters.trackingStatus) === null || _d === void 0 ? void 0 : _d.value) || []
117
+ trackingStatusFilters: ((_e = filters.trackingStatus) === null || _e === void 0 ? void 0 : _e.value) || []
109
118
  });
110
119
  // Use regular API pagination when tracking status filter is not active
111
120
  const {
@@ -115,7 +124,7 @@ const useLabelsGrid = ({
115
124
  } = useListLabels({
116
125
  enabled: !isTrackingStatusFilterActive,
117
126
  queryFnParams: {
118
- labelStatus,
127
+ labelStatus: ((_f = filters.status) === null || _f === void 0 ? void 0 : _f.value) || labelStatus,
119
128
  page,
120
129
  pageSize,
121
130
  shipmentId: filters.shipmentId.value || undefined,
@@ -157,13 +166,13 @@ const useLabelsGrid = ({
157
166
  data: labelFilterData,
158
167
  isError: isLabelFilterError,
159
168
  isInitialLoading: isLabelFilterLoading
160
- } = useGetLabel(((_e = filters.labelId) === null || _e === void 0 ? void 0 : _e.value) || undefined);
161
- const isLabelFilterActive = (_f = filters.labelId) === null || _f === void 0 ? void 0 : _f.value;
169
+ } = useGetLabel(((_g = filters.labelId) === null || _g === void 0 ? void 0 : _g.value) || undefined);
170
+ const isLabelFilterActive = (_h = filters.labelId) === null || _h === void 0 ? void 0 : _h.value;
162
171
  const isStatusFilteredOut = (status, filter) => {
163
172
  return (filter === null || filter === void 0 ? void 0 : filter.length) && !filter.includes(status);
164
173
  };
165
174
  const getLabelById = labelById => {
166
- var _a, _b, _c, _d;
175
+ var _a, _b, _c, _d, _e, _f, _g;
167
176
  // Check if filter by label id is active and there are no errors
168
177
  if (isLabelFilterActive && !isLabelFilterError) {
169
178
  let labelPassFilters = true;
@@ -171,15 +180,19 @@ const useLabelsGrid = ({
171
180
  if (labelStatus && labelStatus !== (labelById === null || labelById === void 0 ? void 0 : labelById.status)) {
172
181
  labelPassFilters = false;
173
182
  }
183
+ // Check if status filter is active and if the label has the same status
184
+ if (((_a = filters === null || filters === void 0 ? void 0 : filters.status) === null || _a === void 0 ? void 0 : _a.enabled) && ((_b = filters === null || filters === void 0 ? void 0 : filters.status) === null || _b === void 0 ? void 0 : _b.value) && ((_c = filters === null || filters === void 0 ? void 0 : filters.status) === null || _c === void 0 ? void 0 : _c.value) !== (labelById === null || labelById === void 0 ? void 0 : labelById.status)) {
185
+ labelPassFilters = false;
186
+ }
174
187
  // Check if shipment filter has the same value if defined
175
- if (((_a = filters === null || filters === void 0 ? void 0 : filters.shipmentId) === null || _a === void 0 ? void 0 : _a.value) !== "" && ((_b = filters === null || filters === void 0 ? void 0 : filters.shipmentId) === null || _b === void 0 ? void 0 : _b.value) !== (labelById === null || labelById === void 0 ? void 0 : labelById.shipmentId)) {
188
+ if (((_d = filters === null || filters === void 0 ? void 0 : filters.shipmentId) === null || _d === void 0 ? void 0 : _d.value) !== "" && ((_e = filters === null || filters === void 0 ? void 0 : filters.shipmentId) === null || _e === void 0 ? void 0 : _e.value) !== (labelById === null || labelById === void 0 ? void 0 : labelById.shipmentId)) {
176
189
  labelPassFilters = false;
177
190
  }
178
191
  if (
179
192
  // If Label status is voided and voided status is filtered out, don't show the label
180
- (labelById === null || labelById === void 0 ? void 0 : labelById.status) === "voided" && isStatusFilteredOut("voided", (_c = filters.trackingStatus) === null || _c === void 0 ? void 0 : _c.value) ||
193
+ (labelById === null || labelById === void 0 ? void 0 : labelById.status) === "voided" && isStatusFilteredOut("voided", (_f = filters.trackingStatus) === null || _f === void 0 ? void 0 : _f.value) ||
181
194
  // If Label status is not voided and tracking status is filtered out, don't show the label
182
- (labelById === null || labelById === void 0 ? void 0 : labelById.status) !== "voided" && (labelById === null || labelById === void 0 ? void 0 : labelById.trackingStatus) && isStatusFilteredOut(labelById.trackingStatus, (_d = filters.trackingStatus) === null || _d === void 0 ? void 0 : _d.value)) {
195
+ (labelById === null || labelById === void 0 ? void 0 : labelById.status) !== "voided" && (labelById === null || labelById === void 0 ? void 0 : labelById.trackingStatus) && isStatusFilteredOut(labelById.trackingStatus, (_g = filters.trackingStatus) === null || _g === void 0 ? void 0 : _g.value)) {
183
196
  labelPassFilters = false;
184
197
  }
185
198
  return labelPassFilters ? labelById : undefined;
@@ -31,7 +31,7 @@ const Component = ({
31
31
  onClickExternalShipmentId,
32
32
  onClickShipmentNumber
33
33
  }) => {
34
- var _a, _b;
34
+ var _a, _b, _c;
35
35
  const {
36
36
  t
37
37
  } = useTranslation(["common", "list-labels"]);
@@ -65,8 +65,13 @@ const Component = ({
65
65
  var _a;
66
66
  return (_a = features === null || features === void 0 ? void 0 : features.columns) === null || _a === void 0 ? void 0 : _a.find(c => c.name === "shipmentNumber");
67
67
  }, [features]);
68
+ const statusColumn = useMemo(() => {
69
+ var _a;
70
+ return (_a = features === null || features === void 0 ? void 0 : features.columns) === null || _a === void 0 ? void 0 : _a.find(c => c.name === "status");
71
+ }, [features]);
68
72
  const showLabelIdFilter = labelIdColumn && ((_a = labelIdColumn.allowFilter) !== null && _a !== void 0 ? _a : true);
69
73
  const showShipmentIdFilter = shipmentIdColumn && ((_b = shipmentIdColumn.allowFilter) !== null && _b !== void 0 ? _b : true);
74
+ const showStatusFilter = statusColumn && ((_c = statusColumn.allowFilter) !== null && _c !== void 0 ? _c : true);
70
75
  const showTrackingStatusFilter = trackingStatusColumn && !!trackingStatusColumn.allowFilter;
71
76
  const {
72
77
  labels,
@@ -86,6 +91,7 @@ const Component = ({
86
91
  labelStatus,
87
92
  showLabelIdFilter,
88
93
  showShipmentIdFilter,
94
+ showStatusFilter,
89
95
  showTrackingStatusFilter,
90
96
  sortDir: sortState.dir
91
97
  });
@@ -103,11 +109,14 @@ const Component = ({
103
109
  shipmentId: Object.assign(Object.assign({}, filters.shipmentId), {
104
110
  nickname: shipmentIdColumn === null || shipmentIdColumn === void 0 ? void 0 : shipmentIdColumn.nickname
105
111
  }),
112
+ status: Object.assign(Object.assign({}, filters.status), {
113
+ nickname: statusColumn === null || statusColumn === void 0 ? void 0 : statusColumn.nickname
114
+ }),
106
115
  trackingStatus: Object.assign(Object.assign({}, filters.trackingStatus), {
107
116
  nickname: trackingStatusColumn === null || trackingStatusColumn === void 0 ? void 0 : trackingStatusColumn.nickname
108
117
  })
109
118
  };
110
- }, [filters, labelIdColumn, shipmentIdColumn, trackingStatusColumn]);
119
+ }, [filters, labelIdColumn, shipmentIdColumn, statusColumn, trackingStatusColumn]);
111
120
  const toggleCreatedDateSort = useCallback(() => {
112
121
  toggleSort("created_at");
113
122
  }, [toggleSort]);
@@ -1,10 +1,11 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import { jsxs, jsx, Fragment } from '@emotion/react/jsx-runtime';
3
3
  import isEqual from 'lodash/isEqual.js';
4
- import { useCallback } from 'react';
4
+ import { useMemo, useCallback } from 'react';
5
5
  import { useTranslation } from 'react-i18next';
6
6
  import { InlineNotification, NotificationType } from '@shipengine/giger';
7
7
  import { WindsorFramework } from './windsor-framework/windsor-framework.js';
8
+ import { moveCustomsItemsToProducts } from '../../../../utilities/shipengine/shipment.js';
8
9
  import { useCustomsContentsOptions } from '../../hooks/use-customs-contents-options.js';
9
10
  import { useCustomsNonDeliveryOptions } from '../../hooks/use-customs-non-delivery-options.js';
10
11
  import { ProductsDisplay } from './products-display/products-display.js';
@@ -29,6 +30,12 @@ const CustomsForms = ({
29
30
  const {
30
31
  t
31
32
  } = useTranslation(["purchase-label", "common"]);
33
+ // Convert deprecated customs items to the products format
34
+ const formattedShipment = useMemo(() => {
35
+ var _a, _b, _c, _d;
36
+ const hasDeprecatedCustomsItems = !!((_b = (_a = shipment.customs) === null || _a === void 0 ? void 0 : _a.customsItems) === null || _b === void 0 ? void 0 : _b.length) && !((_d = (_c = shipment.packages) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.products);
37
+ return hasDeprecatedCustomsItems ? moveCustomsItemsToProducts(shipment) : shipment;
38
+ }, [shipment]);
32
39
  const {
33
40
  errors: {
34
41
  packages: packageErrors
@@ -131,11 +138,11 @@ const CustomsForms = ({
131
138
  currency: currency,
132
139
  harmonizedTariffCodes: harmonizedTariffCodes,
133
140
  onUpdate: handleUpdateProducts,
134
- shipment: shipment
141
+ shipment: formattedShipment
135
142
  }), jsx(TaxIds, {
136
143
  onDirty: onDirty,
137
144
  onUpdateTaxableIds: onUpdateTaxableIds,
138
- shipment: shipment
145
+ shipment: formattedShipment
139
146
  })]
140
147
  }));
141
148
  };
@@ -219,16 +219,11 @@ const RateView = ({
219
219
  }))]
220
220
  })]
221
221
  });
222
- if (errors) return jsx("article", Object.assign({
223
- css: styles.ratesInterstitial,
224
- role: "presentation"
222
+ if (errors) return jsx(InlineNotification, Object.assign({
223
+ title: t(errors.title),
224
+ type: NotificationType.ERROR
225
225
  }, {
226
- children: jsx(InlineNotification, Object.assign({
227
- title: t(errors.title),
228
- type: NotificationType.ERROR
229
- }, {
230
- children: errors === null || errors === void 0 ? void 0 : errors.messages
231
- }))
226
+ children: errors === null || errors === void 0 ? void 0 : errors.messages
232
227
  }));
233
228
  return jsxs("article", Object.assign({
234
229
  css: styles.ratesInterstitial,
@@ -866,7 +866,13 @@ const ShipmentForm = ({
866
866
  label: t("purchase-label:fields.packageCode"),
867
867
  name: "packages.0.type",
868
868
  onCategoryChange: value => {
869
- form.setValue("carrierId", value);
869
+ // Set carrierId to value if:
870
+ // 1. value exists (carrier-specific package) - set to that carrier
871
+ // 2. in browse_rates mode (even for custom packages) - could be set to undefined
872
+ // Otherwise (custom package in select_service mode) - keep existing carrierId
873
+ if (value || form.getValues("__mode") === "browse_rates") {
874
+ form.setValue("carrierId", value);
875
+ }
870
876
  // we have deviated from preset so we need to clear it in order to keep required dims and weight fields in sync
871
877
  setSelectedPreset(undefined);
872
878
  },
@@ -953,17 +959,17 @@ const ShipmentForm = ({
953
959
  })
954
960
  })), hasUpsOptions && jsx(Switch, {
955
961
  defaultChecked: ((_k = shipment === null || shipment === void 0 ? void 0 : shipment.advancedOptions) === null || _k === void 0 ? void 0 : _k.additionalHandling) || false,
956
- label: jsx(Trans, {
962
+ label: (features === null || features === void 0 ? void 0 : features.additionalHandlingHref) ? jsx(Trans, {
957
963
  components: {
958
964
  Link: jsx(Link, {
959
- href: "https://help.paypal.shipstation.com/hc/en-us/articles/13823149193755-UPS-Additional-Handling",
965
+ href: features === null || features === void 0 ? void 0 : features.additionalHandlingHref,
960
966
  rel: "noopener noreferrer",
961
967
  target: "_blank"
962
968
  })
963
969
  },
964
- i18nKey: "purchase-label:fields.requires-additional-handling",
970
+ i18nKey: "purchase-label:fields.requires-additional-handling-link",
965
971
  t: t
966
- }),
972
+ }) : t("purchase-label:fields.requires-additional-handling"),
967
973
  name: "advancedOptions.additionalHandling",
968
974
  onChange: e => form.setValue("advancedOptions.additionalHandling", e.target.checked, {
969
975
  shouldDirty: true
@@ -138,7 +138,9 @@ const ConfigureShipment = _a => {
138
138
  }
139
139
  });
140
140
  // Capture ship from address schema validation error to toggle form and display error message
141
- const hasShipFromAddressErrors = useMemo(() => !!(shipmentFormErrors === null || shipmentFormErrors === void 0 ? void 0 : shipmentFormErrors.filter(error => error.errorCode === "invalid_address")), [shipmentFormErrors]);
141
+ const hasShipFromAddressErrors = useMemo(() => {
142
+ return (shipmentFormErrors === null || shipmentFormErrors === void 0 ? void 0 : shipmentFormErrors.some(error => error.errorCode === "invalid_address")) || false;
143
+ }, [shipmentFormErrors]);
142
144
  return jsxs(Fragment, {
143
145
  children: [jsx(ShipmentForm, Object.assign({}, shipmentFormProps, props, ((_c = features === null || features === void 0 ? void 0 : features.shipmentForm) === null || _c === void 0 ? void 0 : _c.useWarehouses) && {
144
146
  warehouses
@@ -57,7 +57,7 @@ const useRatesForm = ({
57
57
  mutateAsync: updateShipment
58
58
  } = useUpdateSalesOrderShipment();
59
59
  const {
60
- error: labelErrors,
60
+ error: createLabelErrors,
61
61
  reset: resetLabel,
62
62
  mutateAsync: createLabel
63
63
  } = useCreateLabel();
@@ -180,7 +180,7 @@ const useRatesForm = ({
180
180
  }
181
181
  }), [onBeforeRateSaved, onUpdatedShipment, resetRates, shipment, updateShipment]);
182
182
  const handleSubmit = useCallback((rateId, servicePoint) => __awaiter(void 0, void 0, void 0, function* () {
183
- var _g, _h, _j;
183
+ var _g, _h, _j, _k;
184
184
  setBeforeCreateError(undefined);
185
185
  if (!shipment) return;
186
186
  const preferredRates = preferredRatesResponse === null || preferredRatesResponse === void 0 ? void 0 : preferredRatesResponse.map(r => r.rate);
@@ -188,17 +188,35 @@ const useRatesForm = ({
188
188
  if (rate) {
189
189
  try {
190
190
  const beforePurchaseResponse = yield onBeforeLabelCreate === null || onBeforeLabelCreate === void 0 ? void 0 : onBeforeLabelCreate(rate, shipment);
191
- if (!beforePurchaseResponse || Object.keys(beforePurchaseResponse).length === 0) {
192
- yield purchaseLabel(rateId, shipment, rate, servicePoint);
193
- return;
194
- }
195
- // The user has selected a house rate that requires some type of set up to happen before purchase.
196
- // For white label this would be a user has selected a house account UPS ground saver rate and needs to register and
197
- // re-rate their shipment to get a real rate. If its successful, we'll purchase a label with the new rate.
198
- if (beforePurchaseResponse.error) {
191
+ // If the callback has returned an error, abort label purchase
192
+ if (beforePurchaseResponse === null || beforePurchaseResponse === void 0 ? void 0 : beforePurchaseResponse.error) {
199
193
  resetRates();
200
194
  throw new Error(beforePurchaseResponse.error.message);
201
- } else if (beforePurchaseResponse.rate && !beforePurchaseResponse.error) {
195
+ }
196
+ let updatedShipment;
197
+ if (beforePurchaseResponse === null || beforePurchaseResponse === void 0 ? void 0 : beforePurchaseResponse.labelMessages) {
198
+ // The callback has returned custom label messages to be added to the shipment.
199
+ // Merge those messages in with the shipment
200
+ updatedShipment = Object.assign(Object.assign({}, shipment), {
201
+ packages: (_h = shipment.packages) === null || _h === void 0 ? void 0 : _h.map(pkg => Object.assign(Object.assign({}, pkg), {
202
+ labelMessages: beforePurchaseResponse.labelMessages
203
+ }))
204
+ });
205
+ }
206
+ if (updatedShipment) {
207
+ // The shipment needs to be updated before purchase
208
+ try {
209
+ yield updateShipment(Object.assign(Object.assign({}, updatedShipment), {
210
+ shipDate: isNowOrInTheFuture(updatedShipment.shipDate) ? updatedShipment.shipDate : undefined
211
+ }));
212
+ } catch (_l) {
213
+ throw new Error("Unable to update shipment before creating label.");
214
+ }
215
+ }
216
+ if (beforePurchaseResponse === null || beforePurchaseResponse === void 0 ? void 0 : beforePurchaseResponse.rate) {
217
+ // The user has selected a house rate that requires some type of set up to happen before purchase.
218
+ // For white label this would be a user has selected a house account UPS ground saver rate and needs to register and
219
+ // re-rate their shipment to get a real rate. If its successful, we'll purchase a label with the new rate.
202
220
  const _rate = beforePurchaseResponse.rate;
203
221
  const totalRateAmount = getTotalRateAmount(_rate);
204
222
  if (!fundingOrigin) throw new Error("Unable to find balance");
@@ -209,24 +227,27 @@ const useRatesForm = ({
209
227
  });
210
228
  throw new Error("Insufficient funds. Please add funds before purchasing and try again.");
211
229
  } else {
212
- yield purchaseLabel(_rate.rateId, shipment, _rate, servicePoint);
230
+ yield purchaseLabel(_rate.rateId, updatedShipment !== null && updatedShipment !== void 0 ? updatedShipment : shipment, _rate, servicePoint);
213
231
  return;
214
232
  }
215
233
  }
234
+ // The user has selected a standard rate and no further action is required before purchase
235
+ yield purchaseLabel(rateId, shipment, rate, servicePoint);
236
+ return;
216
237
  } catch (e) {
217
238
  if (Array.isArray(e)) {
218
239
  if (e[0] instanceof SE.CodedError) setBeforeCreateError(e[0]);else setBeforeCreateError({
219
240
  errorCode: "unknown",
220
241
  errorSource: "client",
221
242
  errorType: "unknown",
222
- message: (_h = e[0].message) !== null && _h !== void 0 ? _h : "An unknown error occurred"
243
+ message: (_j = e[0].message) !== null && _j !== void 0 ? _j : "An unknown error occurred"
223
244
  });
224
245
  } else {
225
246
  if (e instanceof SE.CodedError) setBeforeCreateError(e);else setBeforeCreateError({
226
247
  errorCode: "unknown",
227
248
  errorSource: "client",
228
249
  errorType: "unknown",
229
- message: (_j = e.message) !== null && _j !== void 0 ? _j : "An unknown error occurred"
250
+ message: (_k = e.message) !== null && _k !== void 0 ? _k : "An unknown error occurred"
230
251
  });
231
252
  }
232
253
  return;
@@ -234,7 +255,8 @@ const useRatesForm = ({
234
255
  }
235
256
  }), [fundingOrigin, handleSave, onBeforeLabelCreate, preferredRatesResponse, purchaseLabel, ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates, resetRates, shipment]);
236
257
  let errors = [...(ratesErrors !== null && ratesErrors !== void 0 ? ratesErrors : []), ...((_b = ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.errors) !== null && _b !== void 0 ? _b : [])];
237
- if (beforeCreateError) errors = [...errors, beforeCreateError];
258
+ let labelErrors = createLabelErrors !== null && createLabelErrors !== void 0 ? createLabelErrors : [];
259
+ if (beforeCreateError) labelErrors = [...labelErrors, beforeCreateError];
238
260
  if (beforeSaveError) errors = [...errors, beforeSaveError];
239
261
  // Sometimes no rates are returned and no top-level errors are returned
240
262
  // but there are invalid rates with errors. This will filter out duplicate error messages and expose those to the user
@@ -255,7 +277,7 @@ const useRatesForm = ({
255
277
  scrubber: useCallback(() => "common:errorMessages.noRatesAvailable", [])
256
278
  });
257
279
  const displayableLabelErrors = useScrubErrors({
258
- errors: labelErrors !== null && labelErrors !== void 0 ? labelErrors : undefined,
280
+ errors: labelErrors,
259
281
  scrubber: useCallback(e => {
260
282
  if (e.message.includes("The ship from email is required") || e.message.includes("The ship to email is required")) return "common:errorMessages.emailIsRequired";
261
283
  return e.message.replace(/Exception with code \w+; module \d+, category \d+, item \d+/g, "");
@@ -70,7 +70,6 @@ const Component = _a => {
70
70
  externalOrderNumber,
71
71
  externalShipmentId,
72
72
  onLoad,
73
- onShipmentUpdated,
74
73
  orderSourceCode,
75
74
  salesOrderId,
76
75
  shipFromAddresses,
@@ -32,6 +32,7 @@ const useShipmentsGrid = ({
32
32
  pageSize,
33
33
  pagerProps
34
34
  } = usePager(PAGE_SIZE);
35
+ const [activeShipmentId, setActiveShipmentId] = useState();
35
36
  const [filters, setFilters] = useState(initialFilters);
36
37
  const clearAllFilters = () => {
37
38
  setFilters(initialFilters);
@@ -65,8 +66,9 @@ const useShipmentsGrid = ({
65
66
  }, getCreatedDateFilterValue((_b = (_a = filters.createdDate) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.start, (_d = (_c = filters.createdDate) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.end)));
66
67
  const shipments = useMemo(() => data === null || data === void 0 ? void 0 : data.shipments.map(shipment => Object.assign(Object.assign({}, shipment), {
67
68
  disableOnRowClick: shipment.shipmentStatus === "cancelled",
69
+ isLoading: activeShipmentId === shipment.shipmentId,
68
70
  serviceName: getServiceName(shipment)
69
- })), [data === null || data === void 0 ? void 0 : data.shipments, getServiceName]);
71
+ })), [activeShipmentId, data === null || data === void 0 ? void 0 : data.shipments, getServiceName]);
70
72
  const {
71
73
  data: shipmentById,
72
74
  error: shipmentErrors,
@@ -107,6 +109,7 @@ const useShipmentsGrid = ({
107
109
  if (shipmentFilteredById) {
108
110
  return [Object.assign(Object.assign({}, shipmentFilteredById), {
109
111
  disableOnRowClick: shipmentFilteredById.shipmentStatus === "cancelled",
112
+ isLoading: activeShipmentId === shipmentFilteredById.shipmentId,
110
113
  serviceName: getServiceName(shipmentFilteredById)
111
114
  })];
112
115
  } else if (shipmentFilteredByIdHasErrors) {
@@ -131,6 +134,7 @@ const useShipmentsGrid = ({
131
134
  showPagination: shipmentFilteredById ? false : ((data === null || data === void 0 ? void 0 : data.total) || 0) > pageSize,
132
135
  totalElements: shipmentFilteredById ? 1 : (data === null || data === void 0 ? void 0 : data.total) || 0
133
136
  },
137
+ setActiveShipmentId,
134
138
  setFilters: onSetFilters,
135
139
  shipments,
136
140
  shouldShowFilters: isAnyFilterEnabled
@@ -1,3 +1,4 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
2
3
  import { useSortableQuery } from '../../hooks/use-sortable-query.js';
3
4
  import { useMemo } from 'react';
@@ -41,18 +42,18 @@ import { ErrorFallback } from '../../components/error-fallback/error-fallback.js
41
42
  * @see {@link ShipmentsGrid.Element | The **Element** created to render `<ShipmentsGrid />`}
42
43
  */
43
44
  const Component = ({
44
- onRowClick,
45
+ onRowClick: onRowClickProp,
45
46
  onClickCancelShipment,
46
47
  shipmentStatus,
47
48
  showShipmentIdFilter: _showShipmentIdFilter = true,
48
49
  showCreatedDateFilter: _showCreatedDateFilter = true
49
50
  }) => {
50
- const {
51
- t
52
- } = useTranslation(["common", "list-shipments"]);
53
51
  const {
54
52
  globalFeatures
55
53
  } = useElements();
54
+ const {
55
+ t
56
+ } = useTranslation(["common", "list-shipments"]);
56
57
  const {
57
58
  toggleSort,
58
59
  sortState
@@ -69,7 +70,8 @@ const Component = ({
69
70
  getGridData,
70
71
  isAnyFilterActive,
71
72
  shouldShowFilters,
72
- clearAllFilters
73
+ clearAllFilters,
74
+ setActiveShipmentId
73
75
  } = useShipmentsGrid({
74
76
  shipmentStatus,
75
77
  showCreatedDateFilter: _showCreatedDateFilter,
@@ -77,6 +79,11 @@ const Component = ({
77
79
  sortBy: sortState.by,
78
80
  sortDir: sortState.dir
79
81
  });
82
+ const onRowClick = shipment => __awaiter(void 0, void 0, void 0, function* () {
83
+ setActiveShipmentId(shipment.shipmentId);
84
+ yield onRowClickProp === null || onRowClickProp === void 0 ? void 0 : onRowClickProp(shipment);
85
+ setActiveShipmentId(undefined);
86
+ });
80
87
  const handleCreatedDateSort = () => {
81
88
  toggleSort("created_at");
82
89
  };
@@ -3,3 +3,4 @@ export { useHelpers } from './use-helpers.js';
3
3
  export { useConfigureShipment } from './use-configure-shipment.js';
4
4
  export { useImportSalesOrder } from './use-import-sales-order.js';
5
5
  export { useBalanceServices } from './use-balance-services.js';
6
+ export { RootPortalProvider, useRootPortal } from './use-root-portal.js';