@shipengine/elements 2.21.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.
- package/cjs/components/grid-controller/grid-controller.cjs +49 -17
- package/cjs/components/grid-controller/grid-controller.styles.cjs +7 -2
- package/cjs/components/grid-controller/grid-footer.cjs +30 -15
- package/cjs/components/grid-controller/grid-footer.styles.cjs +24 -0
- package/cjs/components/grid-controller/index.cjs +1 -1
- package/cjs/components/grid-controller/sortable-header/index.cjs +9 -0
- package/cjs/components/grid-controller/{sortable-header.cjs → sortable-header/sortable-header.cjs} +3 -5
- package/cjs/components/grid-controller/sortable-header/sortable-header.styles.cjs +18 -0
- package/cjs/components/grid-filters/components/created-date-filter/created-date-filter.cjs +3 -0
- package/cjs/components/grid-filters/components/index.cjs +2 -0
- package/cjs/components/grid-filters/components/label-id-filter/label-id-filter.cjs +2 -0
- package/cjs/components/grid-filters/components/label-status-filter/index.cjs +9 -0
- package/cjs/components/grid-filters/components/label-status-filter/label-status-filter-schema.cjs +12 -0
- package/cjs/components/grid-filters/components/label-status-filter/label-status-filter.cjs +174 -0
- package/cjs/components/grid-filters/components/label-status-filter/label-status-filter.styles.cjs +21 -0
- package/cjs/components/grid-filters/components/shipment-id-filter/shipment-id-filter.cjs +2 -0
- package/cjs/components/grid-filters/components/tracking-status-filter/tracking-status-filter.cjs +23 -12
- package/cjs/components/grid-filters/grid-filters.cjs +12 -1
- package/cjs/elements/labels-grid/hooks/use-labels-grid.cjs +78 -31
- package/cjs/elements/labels-grid/hooks/use-tracking-status-filter.cjs +109 -0
- package/cjs/elements/labels-grid/labels-grid.cjs +56 -30
- package/cjs/elements/purchase-label/components/customs-forms/customs-forms.cjs +10 -3
- package/cjs/elements/purchase-label/components/fund-and-purchase/fund-and-purchase.cjs +22 -14
- package/cjs/elements/purchase-label/components/rate-form/rate-form.cjs +1 -1
- package/cjs/elements/purchase-label/components/rate-form/rate-view.cjs +4 -9
- package/cjs/elements/purchase-label/components/shipment-form/shipment-form.cjs +11 -5
- package/cjs/elements/purchase-label/configure-shipment.cjs +3 -1
- package/cjs/elements/purchase-label/hooks/use-rates-form.cjs +38 -16
- package/cjs/elements/purchase-label/purchase-label.cjs +0 -1
- package/cjs/elements/shipments-grid/hooks/use-shipments-grid.cjs +11 -6
- package/cjs/elements/shipments-grid/shipments-grid.cjs +67 -28
- package/cjs/hooks/index.cjs +3 -0
- package/cjs/hooks/use-configure-shipment.cjs +1 -34
- package/cjs/hooks/use-sortable-query.cjs +36 -0
- package/cjs/index.cjs +5 -0
- package/cjs/locales/en/common.cjs +3 -1
- package/cjs/locales/en/purchase-label.cjs +2 -1
- package/cjs/package.cjs +1 -1
- package/cjs/utilities/feature-flags/feature-flags.cjs +1 -1
- package/cjs/workflows/label-workflow/label-workflow.cjs +0 -1
- package/esm/components/grid-controller/grid-controller.js +51 -19
- package/esm/components/grid-controller/grid-controller.styles.js +7 -2
- package/esm/components/grid-controller/grid-footer.js +32 -17
- package/esm/components/grid-controller/grid-footer.styles.js +20 -0
- package/esm/components/grid-controller/index.js +1 -1
- package/esm/components/grid-controller/sortable-header/index.js +1 -0
- package/esm/components/grid-controller/{sortable-header.js → sortable-header/sortable-header.js} +3 -5
- package/esm/components/grid-controller/sortable-header/sortable-header.styles.js +14 -0
- package/esm/components/grid-filters/components/created-date-filter/created-date-filter.js +3 -0
- package/esm/components/grid-filters/components/index.js +1 -0
- package/esm/components/grid-filters/components/label-id-filter/label-id-filter.js +2 -0
- package/esm/components/grid-filters/components/label-status-filter/index.js +1 -0
- package/esm/components/grid-filters/components/label-status-filter/label-status-filter-schema.js +8 -0
- package/esm/components/grid-filters/components/label-status-filter/label-status-filter.js +170 -0
- package/esm/components/grid-filters/components/label-status-filter/label-status-filter.styles.js +17 -0
- package/esm/components/grid-filters/components/shipment-id-filter/shipment-id-filter.js +2 -0
- package/esm/components/grid-filters/components/tracking-status-filter/tracking-status-filter.js +23 -12
- package/esm/components/grid-filters/grid-filters.js +12 -1
- package/esm/elements/labels-grid/hooks/use-labels-grid.js +79 -32
- package/esm/elements/labels-grid/hooks/use-tracking-status-filter.js +105 -0
- package/esm/elements/labels-grid/labels-grid.js +57 -31
- package/esm/elements/purchase-label/components/customs-forms/customs-forms.js +10 -3
- package/esm/elements/purchase-label/components/fund-and-purchase/fund-and-purchase.js +22 -14
- package/esm/elements/purchase-label/components/rate-form/rate-form.js +1 -1
- package/esm/elements/purchase-label/components/rate-form/rate-view.js +4 -9
- package/esm/elements/purchase-label/components/shipment-form/shipment-form.js +11 -5
- package/esm/elements/purchase-label/configure-shipment.js +3 -1
- package/esm/elements/purchase-label/hooks/use-rates-form.js +38 -16
- package/esm/elements/purchase-label/purchase-label.js +0 -1
- package/esm/elements/shipments-grid/hooks/use-shipments-grid.js +11 -6
- package/esm/elements/shipments-grid/shipments-grid.js +68 -29
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/use-configure-shipment.js +3 -36
- package/esm/hooks/use-sortable-query.js +32 -0
- package/esm/index.js +2 -0
- package/esm/locales/en/common.js +3 -1
- package/esm/locales/en/purchase-label.js +2 -1
- package/esm/package.js +1 -1
- package/esm/utilities/feature-flags/feature-flags.js +1 -1
- package/esm/workflows/label-workflow/label-workflow.js +0 -1
- package/package.json +15 -4
- package/types/src/components/grid-controller/grid-controller.d.ts +4 -1
- package/types/src/components/grid-controller/grid-controller.styles.d.ts +6 -1
- package/types/src/components/grid-controller/grid-footer.d.ts +9 -1
- package/types/src/components/grid-controller/grid-footer.styles.d.ts +16 -0
- package/types/src/components/grid-controller/sortable-header/index.d.ts +1 -0
- package/types/src/components/grid-controller/{sortable-header.d.ts → sortable-header/sortable-header.d.ts} +2 -2
- package/types/src/components/grid-controller/sortable-header/sortable-header.styles.d.ts +10 -0
- package/types/src/components/grid-filters/components/created-date-filter/created-date-filter.d.ts +2 -1
- package/types/src/components/grid-filters/components/index.d.ts +1 -0
- package/types/src/components/grid-filters/components/label-id-filter/label-id-filter.d.ts +2 -1
- package/types/src/components/grid-filters/components/label-status-filter/index.d.ts +1 -0
- package/types/src/components/grid-filters/components/label-status-filter/label-status-filter-schema.d.ts +12 -0
- package/types/src/components/grid-filters/components/label-status-filter/label-status-filter.d.ts +24 -0
- package/types/src/components/grid-filters/components/label-status-filter/label-status-filter.styles.d.ts +13 -0
- package/types/src/components/grid-filters/components/shipment-id-filter/shipment-id-filter.d.ts +2 -1
- package/types/src/components/grid-filters/components/tracking-status-filter/tracking-status-filter.d.ts +2 -1
- package/types/src/components/grid-filters/grid-filters.d.ts +4 -1
- package/types/src/elements/labels-grid/hooks/use-labels-grid.d.ts +5 -3
- package/types/src/elements/labels-grid/hooks/use-tracking-status-filter.d.ts +25 -0
- package/types/src/elements/labels-grid/labels-grid.d.ts +34 -20
- package/types/src/elements/manage-carriers/manage-carriers.d.ts +3 -0
- package/types/src/elements/manage-external-carriers/manage-external-carriers.d.ts +3 -0
- package/types/src/elements/manage-funding/manage-funding-element.d.ts +3 -0
- package/types/src/elements/manage-warehouses/manage-warehouses.d.ts +3 -0
- package/types/src/elements/payment-method-settings/payment-method-settings-element.d.ts +3 -0
- package/types/src/elements/purchase-label/components/fund-and-purchase/fund-and-purchase.d.ts +2 -2
- package/types/src/elements/purchase-label/hooks/use-rates-form.d.ts +1 -0
- package/types/src/elements/purchase-label/purchase-label.d.ts +12 -9
- package/types/src/elements/select-label-layout/select-label-layout-element.d.ts +3 -0
- package/types/src/elements/shipment-summary/shipment-summary.d.ts +3 -0
- package/types/src/elements/shipments-grid/hooks/use-shipments-grid.d.ts +13 -2
- package/types/src/elements/shipments-grid/shipments-grid.d.ts +41 -6
- package/types/src/elements/theme-creator/theme-creator.d.ts +3 -0
- package/types/src/elements/transaction-history/transaction-history-element.d.ts +3 -0
- package/types/src/elements/unit-settings/unit-settings-element.d.ts +3 -0
- package/types/src/elements/vat-settings/vat-settings-element.d.ts +3 -0
- package/types/src/elements/void-label/void-label.d.ts +34 -0
- package/types/src/hooks/index.d.ts +1 -0
- package/types/src/hooks/use-configure-shipment.d.ts +1 -2
- package/types/src/hooks/use-sortable-query.d.ts +13 -0
- package/types/src/index.d.ts +5 -0
- package/types/src/locales/en/index.d.ts +3 -0
- package/types/src/utilities/feature-flags/types.d.ts +5 -1
- package/types/src/workflows/account-settings/account-settings.d.ts +3 -0
- package/types/src/workflows/carrier-services/carrier-services.d.ts +3 -0
- package/types/src/workflows/connect-external-carrier/connect-external-carrier.d.ts +3 -0
- package/types/src/workflows/label-workflow/label-workflow.d.ts +11 -1
- package/types/src/workflows/onboarding/onboarding.d.ts +3 -0
|
@@ -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:
|
|
141
|
+
shipment: formattedShipment
|
|
135
142
|
}), jsx(TaxIds, {
|
|
136
143
|
onDirty: onDirty,
|
|
137
144
|
onUpdateTaxableIds: onUpdateTaxableIds,
|
|
138
|
-
shipment:
|
|
145
|
+
shipment: formattedShipment
|
|
139
146
|
})]
|
|
140
147
|
}));
|
|
141
148
|
};
|
|
@@ -34,12 +34,12 @@ const FundAndPurchase = ({
|
|
|
34
34
|
currency,
|
|
35
35
|
disabled,
|
|
36
36
|
isFundingEnabled,
|
|
37
|
-
|
|
38
|
-
onSave,
|
|
37
|
+
isInvalidatedByError,
|
|
39
38
|
onPurchase,
|
|
39
|
+
onSave,
|
|
40
40
|
onVatRegistrationComplete,
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
rateData,
|
|
42
|
+
showVatSettings
|
|
43
43
|
}) => {
|
|
44
44
|
var _a, _b, _c;
|
|
45
45
|
const {
|
|
@@ -71,10 +71,18 @@ const FundAndPurchase = ({
|
|
|
71
71
|
const purchaseAmount = getTotalRateAmount(rate);
|
|
72
72
|
const [isSavingRate, setIsSavingRate] = useState(false);
|
|
73
73
|
const [isSavingError, setIsSavingError] = useState(false);
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
const purchaseRequiresAddingFunds = isFundingEnabled && isFundingRequired && (fundingOrigin === null || fundingOrigin === void 0 ? void 0 : fundingOrigin.balance) !== undefined && fundingOrigin.balance < purchaseAmount && !isInvalidatedByError;
|
|
75
|
+
const [isFormManuallyToggled, setIsFormManuallyToggled] = useState(false);
|
|
76
|
+
const isAddFundsFormOpen = purchaseRequiresAddingFunds || isFormManuallyToggled;
|
|
77
|
+
const toggleAddFundsForm = () => {
|
|
78
|
+
if (!purchaseRequiresAddingFunds) {
|
|
79
|
+
// If the label can be purchased without adding funds, allow manual toggling of the form
|
|
80
|
+
setIsFormManuallyToggled(!isFormManuallyToggled);
|
|
81
|
+
} else if (isFormManuallyToggled) {
|
|
82
|
+
// If the form is already open, close it
|
|
83
|
+
setIsFormManuallyToggled(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
78
86
|
useEffect(() => {
|
|
79
87
|
resetAddFundsMutationState();
|
|
80
88
|
}, [isAddFundsFormOpen, resetAddFundsMutationState]);
|
|
@@ -82,7 +90,7 @@ const FundAndPurchase = ({
|
|
|
82
90
|
setIsSavingRate(true);
|
|
83
91
|
setIsSavingError(false);
|
|
84
92
|
try {
|
|
85
|
-
yield onSave();
|
|
93
|
+
yield onSave === null || onSave === void 0 ? void 0 : onSave();
|
|
86
94
|
} catch (e) {
|
|
87
95
|
setIsSavingError(true);
|
|
88
96
|
} finally {
|
|
@@ -108,7 +116,7 @@ const FundAndPurchase = ({
|
|
|
108
116
|
breakpoint: "mobileLarge",
|
|
109
117
|
justify: "end"
|
|
110
118
|
}, {
|
|
111
|
-
children: [jsx(Button, Object.assign({
|
|
119
|
+
children: [onSave && jsx(Button, Object.assign({
|
|
112
120
|
bold: false,
|
|
113
121
|
css: styles.saveRateButton,
|
|
114
122
|
disabled: disableSaveButton,
|
|
@@ -139,7 +147,7 @@ const FundAndPurchase = ({
|
|
|
139
147
|
}), isFundingEnabled ? jsx(LinkAction, {
|
|
140
148
|
icon: "add",
|
|
141
149
|
isDisabled: !isFundingRequired || isAddFundsFormOpen || isRateFormSubmitting,
|
|
142
|
-
onClick:
|
|
150
|
+
onClick: toggleAddFundsForm,
|
|
143
151
|
title: t("manage-funding:actions.addFunds")
|
|
144
152
|
}) : null]
|
|
145
153
|
}), jsx(Spacer, {
|
|
@@ -185,7 +193,7 @@ const FundAndPurchase = ({
|
|
|
185
193
|
}), isFundingEnabled && jsx(LinkAction, {
|
|
186
194
|
icon: "add",
|
|
187
195
|
isDisabled: isAddFundsFormOpen || isRateFormSubmitting,
|
|
188
|
-
onClick:
|
|
196
|
+
onClick: toggleAddFundsForm,
|
|
189
197
|
title: t("manage-funding:actions.addFunds")
|
|
190
198
|
})]
|
|
191
199
|
}), jsx(Spacer, {
|
|
@@ -206,7 +214,7 @@ const FundAndPurchase = ({
|
|
|
206
214
|
currency: currency,
|
|
207
215
|
minimumAmount: purchaseAmount - balance,
|
|
208
216
|
onSuccess: () => {
|
|
209
|
-
|
|
217
|
+
setIsFormManuallyToggled(false);
|
|
210
218
|
onPurchase();
|
|
211
219
|
}
|
|
212
220
|
}, {
|
|
@@ -243,7 +251,7 @@ const FundAndPurchase = ({
|
|
|
243
251
|
}, {
|
|
244
252
|
children: jsx(Button, Object.assign({
|
|
245
253
|
disabled: addFundsForm.isSubmitting || isRateFormSubmitting,
|
|
246
|
-
onClick: () =>
|
|
254
|
+
onClick: () => setIsFormManuallyToggled(false),
|
|
247
255
|
variant: ButtonVariant.TEXT
|
|
248
256
|
}, {
|
|
249
257
|
children: t("actions.cancel")
|
|
@@ -215,7 +215,7 @@ const RateForm = ({
|
|
|
215
215
|
isFundingEnabled: !!(features === null || features === void 0 ? void 0 : features.enableFunding),
|
|
216
216
|
isInvalidatedByError: !!(labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length),
|
|
217
217
|
onPurchase: handleSubmit,
|
|
218
|
-
onSave: handleSaveRate,
|
|
218
|
+
onSave: (features === null || features === void 0 ? void 0 : features.saveRate) ? handleSaveRate : undefined,
|
|
219
219
|
onVatRegistrationComplete: onVatRegistrationComplete,
|
|
220
220
|
rateData: {
|
|
221
221
|
isPreferredRate,
|
|
@@ -219,16 +219,11 @@ const RateView = ({
|
|
|
219
219
|
}))]
|
|
220
220
|
})]
|
|
221
221
|
});
|
|
222
|
-
if (errors) return jsx(
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
if (errors) return jsx(InlineNotification, Object.assign({
|
|
223
|
+
title: t(errors.title),
|
|
224
|
+
type: NotificationType.ERROR
|
|
225
225
|
}, {
|
|
226
|
-
children:
|
|
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
|
-
|
|
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:
|
|
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(() =>
|
|
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:
|
|
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
|
-
|
|
192
|
-
|
|
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
|
-
}
|
|
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: (
|
|
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: (
|
|
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
|
-
|
|
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
|
|
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, "");
|
|
@@ -18,7 +18,9 @@ const getInitialFilters = (showShipmentIdFilter, showCreatedDateFilter) => ({
|
|
|
18
18
|
const useShipmentsGrid = ({
|
|
19
19
|
shipmentStatus,
|
|
20
20
|
showShipmentIdFilter: _showShipmentIdFilter = true,
|
|
21
|
-
showCreatedDateFilter: _showCreatedDateFilter = true
|
|
21
|
+
showCreatedDateFilter: _showCreatedDateFilter = true,
|
|
22
|
+
sortBy,
|
|
23
|
+
sortDir
|
|
22
24
|
}) => {
|
|
23
25
|
var _a, _b, _c, _d;
|
|
24
26
|
const initialFilters = getInitialFilters(_showShipmentIdFilter, _showCreatedDateFilter);
|
|
@@ -30,6 +32,7 @@ const useShipmentsGrid = ({
|
|
|
30
32
|
pageSize,
|
|
31
33
|
pagerProps
|
|
32
34
|
} = usePager(PAGE_SIZE);
|
|
35
|
+
const [activeShipmentId, setActiveShipmentId] = useState();
|
|
33
36
|
const [filters, setFilters] = useState(initialFilters);
|
|
34
37
|
const clearAllFilters = () => {
|
|
35
38
|
setFilters(initialFilters);
|
|
@@ -58,14 +61,14 @@ const useShipmentsGrid = ({
|
|
|
58
61
|
page,
|
|
59
62
|
pageSize,
|
|
60
63
|
shipmentStatus,
|
|
61
|
-
sortBy:
|
|
62
|
-
sortDir:
|
|
64
|
+
sortBy: sortBy,
|
|
65
|
+
sortDir: sortDir
|
|
63
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)));
|
|
64
67
|
const shipments = useMemo(() => data === null || data === void 0 ? void 0 : data.shipments.map(shipment => Object.assign(Object.assign({}, shipment), {
|
|
65
68
|
disableOnRowClick: shipment.shipmentStatus === "cancelled",
|
|
69
|
+
isLoading: activeShipmentId === shipment.shipmentId,
|
|
66
70
|
serviceName: getServiceName(shipment)
|
|
67
|
-
})), [data === null || data === void 0 ? void 0 : data.shipments, getServiceName]);
|
|
68
|
-
const shouldShowFilters = isAnyFilterEnabled && (isAnyFilterActive || Boolean(shipments === null || shipments === void 0 ? void 0 : shipments.length));
|
|
71
|
+
})), [activeShipmentId, data === null || data === void 0 ? void 0 : data.shipments, getServiceName]);
|
|
69
72
|
const {
|
|
70
73
|
data: shipmentById,
|
|
71
74
|
error: shipmentErrors,
|
|
@@ -106,6 +109,7 @@ const useShipmentsGrid = ({
|
|
|
106
109
|
if (shipmentFilteredById) {
|
|
107
110
|
return [Object.assign(Object.assign({}, shipmentFilteredById), {
|
|
108
111
|
disableOnRowClick: shipmentFilteredById.shipmentStatus === "cancelled",
|
|
112
|
+
isLoading: activeShipmentId === shipmentFilteredById.shipmentId,
|
|
109
113
|
serviceName: getServiceName(shipmentFilteredById)
|
|
110
114
|
})];
|
|
111
115
|
} else if (shipmentFilteredByIdHasErrors) {
|
|
@@ -130,9 +134,10 @@ const useShipmentsGrid = ({
|
|
|
130
134
|
showPagination: shipmentFilteredById ? false : ((data === null || data === void 0 ? void 0 : data.total) || 0) > pageSize,
|
|
131
135
|
totalElements: shipmentFilteredById ? 1 : (data === null || data === void 0 ? void 0 : data.total) || 0
|
|
132
136
|
},
|
|
137
|
+
setActiveShipmentId,
|
|
133
138
|
setFilters: onSetFilters,
|
|
134
139
|
shipments,
|
|
135
|
-
shouldShowFilters
|
|
140
|
+
shouldShowFilters: isAnyFilterEnabled
|
|
136
141
|
};
|
|
137
142
|
};
|
|
138
143
|
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
1
2
|
import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
|
|
3
|
+
import { useSortableQuery } from '../../hooks/use-sortable-query.js';
|
|
4
|
+
import { useMemo } from 'react';
|
|
2
5
|
import { useTranslation } from 'react-i18next';
|
|
3
|
-
import { TagColor, Typography, Tag, TagVariant
|
|
6
|
+
import { EmptyState, Button, TagColor, Typography, Tag, TagVariant } from '@shipengine/giger';
|
|
4
7
|
import { useShipmentsGrid } from './hooks/use-shipments-grid.js';
|
|
5
8
|
import { styles } from './shipments-grid.styles.js';
|
|
6
9
|
import { ActionsMenu, Actions } from '../../components/actions-menu/actions-menu.js';
|
|
7
10
|
import { GridFilters } from '../../components/grid-filters/grid-filters.js';
|
|
8
11
|
import en from '../../locales/en/index.js';
|
|
9
12
|
import { useElements } from '../../elements-provider/elements-context-provider.js';
|
|
10
|
-
import { Loader } from '../../components/loader/loader.js';
|
|
11
13
|
import { ErrorState } from '../../components/error-state/error-state.js';
|
|
14
|
+
import { SortableHeader } from '../../components/grid-controller/sortable-header/sortable-header.js';
|
|
12
15
|
import { CellFormattedDate } from '../../components/grid-controller/cell-formatted-date.js';
|
|
13
16
|
import { GridController } from '../../components/grid-controller/grid-controller.js';
|
|
14
17
|
import { GridFooter } from '../../components/grid-controller/grid-footer.js';
|
|
@@ -39,18 +42,25 @@ import { ErrorFallback } from '../../components/error-fallback/error-fallback.js
|
|
|
39
42
|
* @see {@link ShipmentsGrid.Element | The **Element** created to render `<ShipmentsGrid />`}
|
|
40
43
|
*/
|
|
41
44
|
const Component = ({
|
|
42
|
-
onRowClick,
|
|
45
|
+
onRowClick: onRowClickProp,
|
|
43
46
|
onClickCancelShipment,
|
|
44
47
|
shipmentStatus,
|
|
45
48
|
showShipmentIdFilter: _showShipmentIdFilter = true,
|
|
46
49
|
showCreatedDateFilter: _showCreatedDateFilter = true
|
|
47
50
|
}) => {
|
|
51
|
+
const {
|
|
52
|
+
globalFeatures
|
|
53
|
+
} = useElements();
|
|
48
54
|
const {
|
|
49
55
|
t
|
|
50
56
|
} = useTranslation(["common", "list-shipments"]);
|
|
51
57
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
toggleSort,
|
|
59
|
+
sortState
|
|
60
|
+
} = useSortableQuery({
|
|
61
|
+
defaultSortBy: "modified_at",
|
|
62
|
+
defaultSortDir: "desc"
|
|
63
|
+
});
|
|
54
64
|
const {
|
|
55
65
|
isLoading,
|
|
56
66
|
isError,
|
|
@@ -60,17 +70,50 @@ const Component = ({
|
|
|
60
70
|
getGridData,
|
|
61
71
|
isAnyFilterActive,
|
|
62
72
|
shouldShowFilters,
|
|
63
|
-
clearAllFilters
|
|
73
|
+
clearAllFilters,
|
|
74
|
+
setActiveShipmentId
|
|
64
75
|
} = useShipmentsGrid({
|
|
65
76
|
shipmentStatus,
|
|
66
77
|
showCreatedDateFilter: _showCreatedDateFilter,
|
|
67
|
-
showShipmentIdFilter: _showShipmentIdFilter
|
|
78
|
+
showShipmentIdFilter: _showShipmentIdFilter,
|
|
79
|
+
sortBy: sortState.by,
|
|
80
|
+
sortDir: sortState.dir
|
|
68
81
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
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
|
+
});
|
|
87
|
+
const handleCreatedDateSort = () => {
|
|
88
|
+
toggleSort("created_at");
|
|
89
|
+
};
|
|
90
|
+
const handleUpdatedDateSort = () => {
|
|
91
|
+
toggleSort("modified_at");
|
|
92
|
+
};
|
|
93
|
+
const emptyContentComponent = useMemo(() => {
|
|
94
|
+
if (isLoading) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (isAnyFilterActive) {
|
|
98
|
+
return jsx(EmptyState, Object.assign({
|
|
99
|
+
isElevated: false,
|
|
100
|
+
subtitle: t("list-shipments:emptyState.filtersSubtitle"),
|
|
101
|
+
title: t("list-shipments:emptyState.filtersTitle")
|
|
102
|
+
}, {
|
|
103
|
+
children: jsx(Button, Object.assign({
|
|
104
|
+
onClick: clearAllFilters
|
|
105
|
+
}, {
|
|
106
|
+
children: t("list-shipments:emptyState.viewAll")
|
|
107
|
+
}))
|
|
108
|
+
}));
|
|
109
|
+
} else {
|
|
110
|
+
return jsx(EmptyState, {
|
|
111
|
+
isElevated: false,
|
|
112
|
+
subtitle: t("list-shipments:emptyState.subtitle"),
|
|
113
|
+
title: t("list-shipments:emptyState.title")
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}, [clearAllFilters, isAnyFilterActive, isLoading, t]);
|
|
74
117
|
if (isError) {
|
|
75
118
|
return jsx(ErrorState, {
|
|
76
119
|
css: styles.errorState,
|
|
@@ -156,7 +199,11 @@ const Component = ({
|
|
|
156
199
|
}));
|
|
157
200
|
}
|
|
158
201
|
}, {
|
|
159
|
-
headerContent:
|
|
202
|
+
headerContent: jsx(SortableHeader, {
|
|
203
|
+
headerText: t("list-shipments:headers.created"),
|
|
204
|
+
onToggleSort: handleCreatedDateSort,
|
|
205
|
+
sortDirection: sortState.createdAtDir
|
|
206
|
+
}),
|
|
160
207
|
renderCellContent: shipment => {
|
|
161
208
|
return jsx(CellFormattedDate, {
|
|
162
209
|
date: shipment.createdAt,
|
|
@@ -164,7 +211,11 @@ const Component = ({
|
|
|
164
211
|
});
|
|
165
212
|
}
|
|
166
213
|
}, {
|
|
167
|
-
headerContent:
|
|
214
|
+
headerContent: jsx(SortableHeader, {
|
|
215
|
+
headerText: t("list-shipments:headers.modified"),
|
|
216
|
+
onToggleSort: handleUpdatedDateSort,
|
|
217
|
+
sortDirection: sortState.modifiedAtDir
|
|
218
|
+
}),
|
|
168
219
|
renderCellContent: shipment => {
|
|
169
220
|
return jsx(CellFormattedDate, {
|
|
170
221
|
date: shipment.modifiedAt,
|
|
@@ -196,23 +247,10 @@ const Component = ({
|
|
|
196
247
|
children: [jsx(GridController, {
|
|
197
248
|
columns: columns,
|
|
198
249
|
data: getGridData(),
|
|
199
|
-
emptyContent:
|
|
200
|
-
isElevated: false,
|
|
201
|
-
subtitle: t("list-shipments:emptyState.filtersSubtitle"),
|
|
202
|
-
title: t("list-shipments:emptyState.filtersTitle")
|
|
203
|
-
}, {
|
|
204
|
-
children: jsx(Button, Object.assign({
|
|
205
|
-
onClick: clearAllFilters
|
|
206
|
-
}, {
|
|
207
|
-
children: t("list-shipments:emptyState.viewAll")
|
|
208
|
-
}))
|
|
209
|
-
})) : jsx(EmptyState, {
|
|
210
|
-
isElevated: false,
|
|
211
|
-
subtitle: t("list-shipments:emptyState.subtitle"),
|
|
212
|
-
title: t("list-shipments:emptyState.title")
|
|
213
|
-
}),
|
|
250
|
+
emptyContent: emptyContentComponent,
|
|
214
251
|
filters: shouldShowFilters && jsx(GridFilters, {
|
|
215
252
|
filters: filters,
|
|
253
|
+
filtersDisabled: isLoading,
|
|
216
254
|
onClearAllFilters: clearAllFilters,
|
|
217
255
|
onFiltersUpdated: setFilters
|
|
218
256
|
}),
|
|
@@ -224,6 +262,7 @@ const Component = ({
|
|
|
224
262
|
showPagination: pageConfig.showPagination,
|
|
225
263
|
total: pageConfig.totalElements
|
|
226
264
|
}),
|
|
265
|
+
isLoading: isLoading,
|
|
227
266
|
onRowClick: onRowClick
|
|
228
267
|
}), globalFeatures.poweredByShipEngine && jsxs(Fragment, {
|
|
229
268
|
children: [jsx(Spacer, {}), jsx(PoweredByShipEngine, {})]
|
package/esm/hooks/index.js
CHANGED
|
@@ -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';
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
3
2
|
import { getDefaultShipFromAddress } from '../utilities/shipengine/address.js';
|
|
4
3
|
import { getIsCustomsRequiredForSalesOrder, getCustomsFromSalesOrder } from '../utilities/shipengine/sales-order.js';
|
|
5
|
-
import { getShipmentByStatus
|
|
4
|
+
import { getShipmentByStatus } from '../utilities/shipengine/shipment.js';
|
|
6
5
|
import { getDefaultWarehouse, getWarehouseById } from '../utilities/shipengine/warehouses.js';
|
|
7
6
|
import { useMemo, useCallback, useEffect } from 'react';
|
|
8
|
-
import { useListCarriers, useListWarehouses,
|
|
7
|
+
import { useListCarriers, useListWarehouses, useCreateShipment, useGetShipmentByExternalId, useListSalesOrderShipments, useCreateSalesOrderShipment, CodedError } from '@shipengine/react-api';
|
|
9
8
|
import { useImportSalesOrder } from './use-import-sales-order.js';
|
|
10
9
|
|
|
11
10
|
const useConfigureShipment = ({
|
|
12
|
-
onShipmentUpdated,
|
|
13
11
|
onLoad,
|
|
14
12
|
errorWhenShipmentCancelled: _errorWhenShipmentCancelled = false,
|
|
15
13
|
externalOrderId,
|
|
@@ -22,7 +20,6 @@ const useConfigureShipment = ({
|
|
|
22
20
|
warehouseId,
|
|
23
21
|
useWarehouses: _useWarehouses = true
|
|
24
22
|
}) => {
|
|
25
|
-
const queryClient = useQueryClient();
|
|
26
23
|
// Queue of incomplete requirement keys (i.e., Ship From addresses, Warehouses, Carriers)
|
|
27
24
|
const incompleteRequirementsKeys = useMemo(() => [], []);
|
|
28
25
|
const {
|
|
@@ -50,10 +47,6 @@ const useConfigureShipment = ({
|
|
|
50
47
|
orderSourceCode,
|
|
51
48
|
salesOrderId
|
|
52
49
|
});
|
|
53
|
-
const {
|
|
54
|
-
error: updateShipmentErrors,
|
|
55
|
-
mutate: updateShipment
|
|
56
|
-
} = useUpdateSalesOrderShipment();
|
|
57
50
|
const {
|
|
58
51
|
data: newV1Shipment,
|
|
59
52
|
mutateAsync: createV1Shipment,
|
|
@@ -157,25 +150,6 @@ const useConfigureShipment = ({
|
|
|
157
150
|
}
|
|
158
151
|
}
|
|
159
152
|
}), [createSalesOrderShipment, createV1Shipment, creatingSalesOrderShipment, creatingV1Shipment, defaultShipFromAddress, defaultWarehouse, externalOrderId, externalOrderNumber, externalShipmentId, incompleteRequirementsKeys, isExternalShipmentFetching, isExternalShipmentInitialLoading, isFetchingWarehouses, isInitialLoadingWarehouses, labelPurchasedSalesOrderShipment, listSalesOrderShipmentsInitiallyLoading, listSalesOrderShipmentsIsFetching, orderSourceCode, pendingSalesOrderShipment, refetchSalesOrderShipments, salesOrder, salesOrderId, salesOrderShipmentCreated, shipFromAddresses === null || shipFromAddresses === void 0 ? void 0 : shipFromAddresses.length, shipmentId, _useWarehouses, v1shipmentCreated, warehouseId, warehouses]);
|
|
160
|
-
/**
|
|
161
|
-
* Update a shipment with deprecated customs items. Move items to the products array on the Shipment's packages array
|
|
162
|
-
*
|
|
163
|
-
* Invalidate useGetShipment's cache
|
|
164
|
-
*/
|
|
165
|
-
const formatCustoms = useCallback(shipment => {
|
|
166
|
-
const formattedShipment = moveCustomsItemsToProducts(shipment);
|
|
167
|
-
updateShipment(formattedShipment, {
|
|
168
|
-
onSuccess(data) {
|
|
169
|
-
void (onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(data));
|
|
170
|
-
void queryClient.invalidateQueries(["useListSalesOrderShipments", {
|
|
171
|
-
shipmentId: data.shipmentId
|
|
172
|
-
}], {
|
|
173
|
-
exact: false
|
|
174
|
-
} // Invalidate queries with similar keys
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}, [onShipmentUpdated, queryClient, updateShipment]);
|
|
179
153
|
const refetchPendingSalesOrderShipments = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
180
154
|
const {
|
|
181
155
|
data: shipments
|
|
@@ -188,13 +162,6 @@ const useConfigureShipment = ({
|
|
|
188
162
|
yield handleShipmentCreation();
|
|
189
163
|
}))();
|
|
190
164
|
}, [shipmentId, externalShipmentId, salesOrderId, salesOrder, warehouses, warehouseId, handleShipmentCreation]);
|
|
191
|
-
// useEffect to handle formating customs
|
|
192
|
-
useEffect(() => {
|
|
193
|
-
var _a, _b;
|
|
194
|
-
if ((_b = (_a = pendingSalesOrderShipment === null || pendingSalesOrderShipment === void 0 ? void 0 : pendingSalesOrderShipment.customs) === null || _a === void 0 ? void 0 : _a.customsItems) === null || _b === void 0 ? void 0 : _b.length) {
|
|
195
|
-
formatCustoms(pendingSalesOrderShipment);
|
|
196
|
-
}
|
|
197
|
-
}, [formatCustoms, pendingSalesOrderShipment]);
|
|
198
165
|
// useEffect to check and run the onLoad prop
|
|
199
166
|
useEffect(() => {
|
|
200
167
|
if ((salesOrderShipments === null || salesOrderShipments === void 0 ? void 0 : salesOrderShipments.length) && salesOrderShipments.every(s => s.shipmentStatus === "label_purchased")) {
|
|
@@ -206,7 +173,7 @@ const useConfigureShipment = ({
|
|
|
206
173
|
if (isInitialLoadingCarriers || isFetchingCarriers) return;
|
|
207
174
|
if ((carriers === null || carriers === void 0 ? void 0 : carriers.length) === 0) incompleteRequirementsKeys.push("no_carriers");
|
|
208
175
|
}, [carriers, incompleteRequirementsKeys, isFetchingCarriers, isInitialLoadingCarriers]);
|
|
209
|
-
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 : []), ...(
|
|
176
|
+
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 CodedError("shipment_cancelled", {
|
|
210
177
|
errorCode: "invalid_status",
|
|
211
178
|
errorSource: "elements",
|
|
212
179
|
errorType: "business_rules"
|