@shipengine/elements 0.6.42 → 0.6.43
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/components/shipment-form/shipment-form.d.ts +2 -1
- package/index.cjs +61 -32
- package/index.js +62 -33
- package/package.json +4 -4
|
@@ -16,11 +16,12 @@ export declare type ShipmentFormProps = {
|
|
|
16
16
|
onChangeShipmentFormMode?: ShipmentFormTemplateProps["onChangeMode"];
|
|
17
17
|
onShipmentDirty: () => void;
|
|
18
18
|
onShipmentUpdated: (shipment: SE.SalesOrderShipment, options?: ShipmentUpdatedOptions) => Promise<void> | void;
|
|
19
|
+
onShipmentUpdateFailure?: () => void;
|
|
19
20
|
onToggleAddressPreferenceDisclosure?: ShipmentFormTemplateProps["onToggleAddressPreferenceDisclosure"];
|
|
20
21
|
salesOrder: SE.SalesOrder;
|
|
21
22
|
shipment?: SE.SalesOrderShipment;
|
|
22
23
|
shippingPresets?: UseShippingPresetsOptionsProps;
|
|
23
24
|
warehouseId?: string;
|
|
24
25
|
};
|
|
25
|
-
export declare const ShipmentForm: ({ addressPreference, onApplyPreset, onChangeAddress, onChangeShipmentFormMode, onShipmentDirty, onShipmentUpdated, onToggleAddressPreferenceDisclosure, salesOrder, shipment, shippingPresets, warehouseId, }: ShipmentFormProps) => JSX.Element;
|
|
26
|
+
export declare const ShipmentForm: ({ addressPreference, onApplyPreset, onChangeAddress, onChangeShipmentFormMode, onShipmentDirty, onShipmentUpdated, onShipmentUpdateFailure, onToggleAddressPreferenceDisclosure, salesOrder, shipment, shippingPresets, warehouseId, }: ShipmentFormProps) => JSX.Element;
|
|
26
27
|
export {};
|
package/index.cjs
CHANGED
|
@@ -2848,6 +2848,7 @@ const ShipmentForm = ({
|
|
|
2848
2848
|
onShipmentDirty,
|
|
2849
2849
|
// Must be referentially stable
|
|
2850
2850
|
onShipmentUpdated,
|
|
2851
|
+
onShipmentUpdateFailure,
|
|
2851
2852
|
onToggleAddressPreferenceDisclosure,
|
|
2852
2853
|
salesOrder,
|
|
2853
2854
|
shipment,
|
|
@@ -2901,6 +2902,8 @@ const ShipmentForm = ({
|
|
|
2901
2902
|
shouldCalculateRates: false,
|
|
2902
2903
|
shouldResetAddressPreference: options.shouldValidate
|
|
2903
2904
|
});
|
|
2905
|
+
} else if (onShipmentUpdateFailure) {
|
|
2906
|
+
onShipmentUpdateFailure();
|
|
2904
2907
|
}
|
|
2905
2908
|
});
|
|
2906
2909
|
|
|
@@ -20380,7 +20383,7 @@ const SalesOrder = ({
|
|
|
20380
20383
|
|
|
20381
20384
|
if (((_a = salesOrders.data) === null || _a === void 0 ? void 0 : _a.length) && shipments.data && ((_b = warehouses.data) === null || _b === void 0 ? void 0 : _b.length) && !createShipment.data && !createShipment.errors && !createShipment.isMutating) {
|
|
20382
20385
|
const currentSalesOrder = salesOrders.data[0];
|
|
20383
|
-
const pendingShipment = shipments.data
|
|
20386
|
+
const pendingShipment = elementsCore.getPendingShipment(shipments.data);
|
|
20384
20387
|
|
|
20385
20388
|
if (currentSalesOrder && !pendingShipment) {
|
|
20386
20389
|
const defaultWarehouse = (_c = warehouses.data.find(w => w.warehouseId === warehouseId)) !== null && _c !== void 0 ? _c : warehouses.data[0];
|
|
@@ -20415,40 +20418,44 @@ const SalesOrder = ({
|
|
|
20415
20418
|
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20416
20419
|
}
|
|
20417
20420
|
} catch (error) {
|
|
20418
|
-
// Shipment creation failed most likely due to validate_and_clean
|
|
20419
|
-
//
|
|
20421
|
+
// Shipment creation failed, most likely due to validate_and_clean 500ing
|
|
20422
|
+
// and preventing a shipment from being created. Create a shipment with
|
|
20423
|
+
// the sales order ship to address without validating and setting the
|
|
20424
|
+
// address preference to an error state. This will display the not validated
|
|
20425
|
+
// error message to the user.
|
|
20420
20426
|
logger.warn("createShipment failed to create a shipment, trying plan b", error.message);
|
|
20421
|
-
|
|
20422
|
-
|
|
20423
|
-
|
|
20424
|
-
|
|
20425
|
-
|
|
20426
|
-
|
|
20427
|
-
|
|
20428
|
-
|
|
20429
|
-
|
|
20430
|
-
|
|
20431
|
-
|
|
20432
|
-
|
|
20433
|
-
|
|
20434
|
-
|
|
20435
|
-
|
|
20436
|
-
|
|
20437
|
-
|
|
20438
|
-
|
|
20439
|
-
|
|
20440
|
-
|
|
20441
|
-
}));
|
|
20442
|
-
yield shipments.mutate();
|
|
20427
|
+
|
|
20428
|
+
try {
|
|
20429
|
+
yield createShipment.trigger(Object.assign({
|
|
20430
|
+
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20431
|
+
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20432
|
+
packages: [{
|
|
20433
|
+
weight: {
|
|
20434
|
+
value: 0,
|
|
20435
|
+
unit: "pound"
|
|
20436
|
+
}
|
|
20437
|
+
}],
|
|
20438
|
+
shipTo: currentSalesOrder.shipTo,
|
|
20439
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20440
|
+
}, elementsCore.getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20441
|
+
customs: elementsCore.getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20442
|
+
}));
|
|
20443
|
+
const shipmentsMutationResult = yield shipments.mutate();
|
|
20444
|
+
const currentPendingShipment = elementsCore.getPendingShipment(shipmentsMutationResult);
|
|
20445
|
+
|
|
20446
|
+
if (currentPendingShipment) {
|
|
20443
20447
|
const updatedAddressPreference = resetAddressPreference({
|
|
20444
|
-
validation:
|
|
20445
|
-
|
|
20448
|
+
validation: {
|
|
20449
|
+
messages: [],
|
|
20450
|
+
originalAddress: currentPendingShipment.shipTo,
|
|
20451
|
+
status: "error"
|
|
20452
|
+
}
|
|
20446
20453
|
});
|
|
20447
20454
|
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20448
|
-
} catch (error) {
|
|
20449
|
-
logger.error("createShipment failed to create a shipment", error.message);
|
|
20450
|
-
throw new Error("errorMessages.unableToLoad.shipment");
|
|
20451
20455
|
}
|
|
20456
|
+
} catch (error) {
|
|
20457
|
+
logger.error("createShipment failed to create a shipment", error.message);
|
|
20458
|
+
throw new Error("errorMessages.unableToLoad.shipment");
|
|
20452
20459
|
}
|
|
20453
20460
|
}
|
|
20454
20461
|
} else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
@@ -20473,7 +20480,28 @@ const SalesOrder = ({
|
|
|
20473
20480
|
var _a;
|
|
20474
20481
|
|
|
20475
20482
|
return !!((_a = customPackageTypes.data) === null || _a === void 0 ? void 0 : _a.find(p => p.packageId === shipment.packages[0].packageId));
|
|
20476
|
-
}, [customPackageTypes]);
|
|
20483
|
+
}, [customPackageTypes]); // validate_and_clean failure is preventing the address preference object
|
|
20484
|
+
// from being refreshed. Manualy set the address preference to an error state.
|
|
20485
|
+
// with the original address set to the newly updated shipment ship to
|
|
20486
|
+
// This will display the not validated error message with the edited address to the user.
|
|
20487
|
+
|
|
20488
|
+
const handleShipmentUpdateFailure = react.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
20489
|
+
const result = yield shipments.mutate();
|
|
20490
|
+
const currentShipment = elementsCore.getPendingShipment(result);
|
|
20491
|
+
|
|
20492
|
+
if (currentShipment) {
|
|
20493
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20494
|
+
validation: {
|
|
20495
|
+
messages: [],
|
|
20496
|
+
originalAddress: currentShipment.shipTo,
|
|
20497
|
+
status: "error"
|
|
20498
|
+
}
|
|
20499
|
+
});
|
|
20500
|
+
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20501
|
+
yield onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
|
|
20502
|
+
yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(currentShipment);
|
|
20503
|
+
}
|
|
20504
|
+
}), [onAddressValidation, onChangeAddress, resetAddressPreference, onShipmentUpdated, shipments]);
|
|
20477
20505
|
const handleShipmentUpdated = react.useCallback((shipment, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20478
20506
|
var _h, _j;
|
|
20479
20507
|
|
|
@@ -20537,7 +20565,7 @@ const SalesOrder = ({
|
|
|
20537
20565
|
message: t("loading.carriers")
|
|
20538
20566
|
});
|
|
20539
20567
|
const salesOrder = salesOrders.data[0];
|
|
20540
|
-
const shipment = shipments.data
|
|
20568
|
+
const shipment = elementsCore.getPendingShipment(shipments.data);
|
|
20541
20569
|
let rateErrors = [...((_b = calculateRates.errors) !== null && _b !== void 0 ? _b : []), ...((_d = (_c = calculateRates.data) === null || _c === void 0 ? void 0 : _c.errors) !== null && _d !== void 0 ? _d : [])]; // Sometimes no rates are returned and no top-level errors are returned
|
|
20542
20570
|
// but there are invalid rates with errors. This will expose those to the user
|
|
20543
20571
|
// so the rate list isn't empty after calculating rates.
|
|
@@ -20561,6 +20589,7 @@ const SalesOrder = ({
|
|
|
20561
20589
|
onChangeShipmentFormMode: onChangeShipmentFormMode,
|
|
20562
20590
|
onShipmentDirty: handleShipmentDirty,
|
|
20563
20591
|
onShipmentUpdated: handleShipmentUpdated,
|
|
20592
|
+
onShipmentUpdateFailure: handleShipmentUpdateFailure,
|
|
20564
20593
|
onToggleAddressPreferenceDisclosure: onToggleAddressPreferenceDisclosure,
|
|
20565
20594
|
salesOrder: salesOrder,
|
|
20566
20595
|
shipment: shipment,
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useLogger, useListWarehouses, useListCarriers, useCreateShipment, useUpdateShipment, useParseAddress, useListCustomPackageTypes, useCreateLabel, isDomesticAddress, useListSalesOrders, useListOrderSources, useRefreshOrderSource, useCalculateRates, useValidateAddresses, useListShipments, getIsCustomsRequiredForSalesOrder, getCustomsFromSalesOrder, registerElement, useGetShipment, useListLabels, useGetLabel, useVoidLabel } from '@shipengine/elements-core';
|
|
1
|
+
import { useLogger, useListWarehouses, useListCarriers, useCreateShipment, useUpdateShipment, useParseAddress, useListCustomPackageTypes, useCreateLabel, isDomesticAddress, useListSalesOrders, useListOrderSources, useRefreshOrderSource, useCalculateRates, useValidateAddresses, useListShipments, getPendingShipment, getIsCustomsRequiredForSalesOrder, getCustomsFromSalesOrder, registerElement, useGetShipment, useListLabels, useGetLabel, useVoidLabel } from '@shipengine/elements-core';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { useCallback, useState, useEffect } from 'react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
@@ -2844,6 +2844,7 @@ const ShipmentForm = ({
|
|
|
2844
2844
|
onShipmentDirty,
|
|
2845
2845
|
// Must be referentially stable
|
|
2846
2846
|
onShipmentUpdated,
|
|
2847
|
+
onShipmentUpdateFailure,
|
|
2847
2848
|
onToggleAddressPreferenceDisclosure,
|
|
2848
2849
|
salesOrder,
|
|
2849
2850
|
shipment,
|
|
@@ -2897,6 +2898,8 @@ const ShipmentForm = ({
|
|
|
2897
2898
|
shouldCalculateRates: false,
|
|
2898
2899
|
shouldResetAddressPreference: options.shouldValidate
|
|
2899
2900
|
});
|
|
2901
|
+
} else if (onShipmentUpdateFailure) {
|
|
2902
|
+
onShipmentUpdateFailure();
|
|
2900
2903
|
}
|
|
2901
2904
|
});
|
|
2902
2905
|
|
|
@@ -20376,7 +20379,7 @@ const SalesOrder = ({
|
|
|
20376
20379
|
|
|
20377
20380
|
if (((_a = salesOrders.data) === null || _a === void 0 ? void 0 : _a.length) && shipments.data && ((_b = warehouses.data) === null || _b === void 0 ? void 0 : _b.length) && !createShipment.data && !createShipment.errors && !createShipment.isMutating) {
|
|
20378
20381
|
const currentSalesOrder = salesOrders.data[0];
|
|
20379
|
-
const pendingShipment = shipments.data
|
|
20382
|
+
const pendingShipment = getPendingShipment(shipments.data);
|
|
20380
20383
|
|
|
20381
20384
|
if (currentSalesOrder && !pendingShipment) {
|
|
20382
20385
|
const defaultWarehouse = (_c = warehouses.data.find(w => w.warehouseId === warehouseId)) !== null && _c !== void 0 ? _c : warehouses.data[0];
|
|
@@ -20411,40 +20414,44 @@ const SalesOrder = ({
|
|
|
20411
20414
|
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20412
20415
|
}
|
|
20413
20416
|
} catch (error) {
|
|
20414
|
-
// Shipment creation failed most likely due to validate_and_clean
|
|
20415
|
-
//
|
|
20417
|
+
// Shipment creation failed, most likely due to validate_and_clean 500ing
|
|
20418
|
+
// and preventing a shipment from being created. Create a shipment with
|
|
20419
|
+
// the sales order ship to address without validating and setting the
|
|
20420
|
+
// address preference to an error state. This will display the not validated
|
|
20421
|
+
// error message to the user.
|
|
20416
20422
|
logger.warn("createShipment failed to create a shipment, trying plan b", error.message);
|
|
20417
|
-
|
|
20418
|
-
|
|
20419
|
-
|
|
20420
|
-
|
|
20421
|
-
|
|
20422
|
-
|
|
20423
|
-
|
|
20424
|
-
|
|
20425
|
-
|
|
20426
|
-
|
|
20427
|
-
|
|
20428
|
-
|
|
20429
|
-
|
|
20430
|
-
|
|
20431
|
-
|
|
20432
|
-
|
|
20433
|
-
|
|
20434
|
-
|
|
20435
|
-
|
|
20436
|
-
|
|
20437
|
-
}));
|
|
20438
|
-
yield shipments.mutate();
|
|
20423
|
+
|
|
20424
|
+
try {
|
|
20425
|
+
yield createShipment.trigger(Object.assign({
|
|
20426
|
+
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20427
|
+
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20428
|
+
packages: [{
|
|
20429
|
+
weight: {
|
|
20430
|
+
value: 0,
|
|
20431
|
+
unit: "pound"
|
|
20432
|
+
}
|
|
20433
|
+
}],
|
|
20434
|
+
shipTo: currentSalesOrder.shipTo,
|
|
20435
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20436
|
+
}, getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20437
|
+
customs: getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20438
|
+
}));
|
|
20439
|
+
const shipmentsMutationResult = yield shipments.mutate();
|
|
20440
|
+
const currentPendingShipment = getPendingShipment(shipmentsMutationResult);
|
|
20441
|
+
|
|
20442
|
+
if (currentPendingShipment) {
|
|
20439
20443
|
const updatedAddressPreference = resetAddressPreference({
|
|
20440
|
-
validation:
|
|
20441
|
-
|
|
20444
|
+
validation: {
|
|
20445
|
+
messages: [],
|
|
20446
|
+
originalAddress: currentPendingShipment.shipTo,
|
|
20447
|
+
status: "error"
|
|
20448
|
+
}
|
|
20442
20449
|
});
|
|
20443
20450
|
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20444
|
-
} catch (error) {
|
|
20445
|
-
logger.error("createShipment failed to create a shipment", error.message);
|
|
20446
|
-
throw new Error("errorMessages.unableToLoad.shipment");
|
|
20447
20451
|
}
|
|
20452
|
+
} catch (error) {
|
|
20453
|
+
logger.error("createShipment failed to create a shipment", error.message);
|
|
20454
|
+
throw new Error("errorMessages.unableToLoad.shipment");
|
|
20448
20455
|
}
|
|
20449
20456
|
}
|
|
20450
20457
|
} else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
@@ -20469,7 +20476,28 @@ const SalesOrder = ({
|
|
|
20469
20476
|
var _a;
|
|
20470
20477
|
|
|
20471
20478
|
return !!((_a = customPackageTypes.data) === null || _a === void 0 ? void 0 : _a.find(p => p.packageId === shipment.packages[0].packageId));
|
|
20472
|
-
}, [customPackageTypes]);
|
|
20479
|
+
}, [customPackageTypes]); // validate_and_clean failure is preventing the address preference object
|
|
20480
|
+
// from being refreshed. Manualy set the address preference to an error state.
|
|
20481
|
+
// with the original address set to the newly updated shipment ship to
|
|
20482
|
+
// This will display the not validated error message with the edited address to the user.
|
|
20483
|
+
|
|
20484
|
+
const handleShipmentUpdateFailure = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
20485
|
+
const result = yield shipments.mutate();
|
|
20486
|
+
const currentShipment = getPendingShipment(result);
|
|
20487
|
+
|
|
20488
|
+
if (currentShipment) {
|
|
20489
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20490
|
+
validation: {
|
|
20491
|
+
messages: [],
|
|
20492
|
+
originalAddress: currentShipment.shipTo,
|
|
20493
|
+
status: "error"
|
|
20494
|
+
}
|
|
20495
|
+
});
|
|
20496
|
+
yield onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20497
|
+
yield onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
|
|
20498
|
+
yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(currentShipment);
|
|
20499
|
+
}
|
|
20500
|
+
}), [onAddressValidation, onChangeAddress, resetAddressPreference, onShipmentUpdated, shipments]);
|
|
20473
20501
|
const handleShipmentUpdated = useCallback((shipment, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20474
20502
|
var _h, _j;
|
|
20475
20503
|
|
|
@@ -20533,7 +20561,7 @@ const SalesOrder = ({
|
|
|
20533
20561
|
message: t("loading.carriers")
|
|
20534
20562
|
});
|
|
20535
20563
|
const salesOrder = salesOrders.data[0];
|
|
20536
|
-
const shipment = shipments.data
|
|
20564
|
+
const shipment = getPendingShipment(shipments.data);
|
|
20537
20565
|
let rateErrors = [...((_b = calculateRates.errors) !== null && _b !== void 0 ? _b : []), ...((_d = (_c = calculateRates.data) === null || _c === void 0 ? void 0 : _c.errors) !== null && _d !== void 0 ? _d : [])]; // Sometimes no rates are returned and no top-level errors are returned
|
|
20538
20566
|
// but there are invalid rates with errors. This will expose those to the user
|
|
20539
20567
|
// so the rate list isn't empty after calculating rates.
|
|
@@ -20557,6 +20585,7 @@ const SalesOrder = ({
|
|
|
20557
20585
|
onChangeShipmentFormMode: onChangeShipmentFormMode,
|
|
20558
20586
|
onShipmentDirty: handleShipmentDirty,
|
|
20559
20587
|
onShipmentUpdated: handleShipmentUpdated,
|
|
20588
|
+
onShipmentUpdateFailure: handleShipmentUpdateFailure,
|
|
20560
20589
|
onToggleAddressPreferenceDisclosure: onToggleAddressPreferenceDisclosure,
|
|
20561
20590
|
salesOrder: salesOrder,
|
|
20562
20591
|
shipment: shipment,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipengine/elements",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.43",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@packlink/giger": "*",
|
|
6
6
|
"react-i18next": "*",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"types": "./index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"react": "^18.2.0",
|
|
15
|
-
"@shipengine/elements-core": "0.6.
|
|
15
|
+
"@shipengine/elements-core": "0.6.43",
|
|
16
16
|
"i18next-http-backend": "^1.4.1",
|
|
17
17
|
"i18next-browser-languagedetector": "^6.1.4",
|
|
18
|
-
"@shipengine/types": "0.6.
|
|
19
|
-
"@shipengine/elements-ui": "0.6.
|
|
18
|
+
"@shipengine/types": "0.6.43",
|
|
19
|
+
"@shipengine/elements-ui": "0.6.43"
|
|
20
20
|
}
|
|
21
21
|
}
|