@shipengine/elements 0.4.8 → 0.5.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/components/rate-form/rate-form.d.ts +3 -2
- package/components/sales-order/sales-order.d.ts +13 -2
- package/components/shipment/shipment.d.ts +3 -2
- package/components/shipment-form/shipment-form.d.ts +8 -1
- package/hooks/use-address-preference.d.ts +17 -1
- package/index.cjs +110 -39
- package/index.js +112 -41
- package/package.json +8 -4
|
@@ -3,9 +3,10 @@ import SE from "@shipengine/elements-core";
|
|
|
3
3
|
export declare type RateFormProps = {
|
|
4
4
|
errors?: SE.CodedError[];
|
|
5
5
|
loading?: boolean;
|
|
6
|
-
|
|
6
|
+
onLabelCreateFailure?: () => void;
|
|
7
|
+
onLabelCreateSuccess?: (label: SE.Label, shipment?: SE.SalesOrderShipment) => void;
|
|
7
8
|
onRateSaved?: (shipment: SE.SalesOrderShipment) => void;
|
|
8
9
|
rates?: SE.Rate[];
|
|
9
10
|
shipment?: SE.SalesOrderShipment;
|
|
10
11
|
};
|
|
11
|
-
export declare const RateForm: ({ errors, loading,
|
|
12
|
+
export declare const RateForm: ({ errors, loading, onLabelCreateFailure, onLabelCreateSuccess, onRateSaved, rates, shipment, }: RateFormProps) => JSX.Element;
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import SE from "@shipengine/elements-core";
|
|
3
|
+
import { Templates, UseShippingPresetsOptionsProps } from "@shipengine/elements-ui";
|
|
4
|
+
import { ShipmentFormProps } from "../shipment-form";
|
|
5
|
+
import { RateFormProps } from "../rate-form";
|
|
3
6
|
export declare type SalesOrderProps = {
|
|
4
7
|
externalOrderId?: string;
|
|
5
8
|
externalOrderNumber?: string;
|
|
9
|
+
onAddressValidation?: (addressPreference: Templates.AddressPreference) => void;
|
|
10
|
+
onChangeAddress?: ShipmentFormProps["onChangeAddress"];
|
|
11
|
+
onLabelCreateFailure?: RateFormProps["onLabelCreateFailure"];
|
|
12
|
+
onLabelCreateSuccess?: RateFormProps["onLabelCreateSuccess"];
|
|
6
13
|
onLoad?: (salesOrder: SE.SalesOrder, shipments: SE.SalesOrderShipment[]) => void;
|
|
7
|
-
|
|
14
|
+
onRateSaved?: RateFormProps["onRateSaved"];
|
|
15
|
+
onRatesReturned?: (rates: SE.Rate[], shipment: SE.SalesOrderShipment) => void;
|
|
16
|
+
onChangeShipmentFormMode?: ShipmentFormProps["onChangeShipmentFormMode"];
|
|
17
|
+
onToggleAddressPreferenceDisclosure?: ShipmentFormProps["onToggleAddressPreferenceDisclosure"];
|
|
8
18
|
orderSourceCode?: string;
|
|
9
19
|
salesOrderId?: string;
|
|
20
|
+
shippingPresets?: UseShippingPresetsOptionsProps;
|
|
10
21
|
};
|
|
11
|
-
export declare const SalesOrder: ({ externalOrderId, externalOrderNumber, onLoad,
|
|
22
|
+
export declare const SalesOrder: ({ externalOrderId, externalOrderNumber, onAddressValidation, onChangeAddress, onLabelCreateFailure, onLabelCreateSuccess, onLoad, onRateSaved, onRatesReturned, onChangeShipmentFormMode, onToggleAddressPreferenceDisclosure, orderSourceCode, salesOrderId, shippingPresets, }: SalesOrderProps) => JSX.Element;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import SE from "@shipengine/elements-core";
|
|
3
3
|
export declare type ShipmentProps = {
|
|
4
4
|
shipmentId?: string;
|
|
5
|
-
onClickVoidLabel?: (label: SE.Label) => void;
|
|
6
5
|
onClickPurchaseLabel?: (order: SE.SalesOrder) => void;
|
|
6
|
+
onClickPrintLabel?: () => void;
|
|
7
|
+
onClickVoidLabel?: (label: SE.Label) => void;
|
|
7
8
|
};
|
|
8
|
-
export declare const Shipment: ({
|
|
9
|
+
export declare const Shipment: ({ onClickPrintLabel, onClickPurchaseLabel, onClickVoidLabel, shipmentId, }: ShipmentProps) => JSX.Element;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Templates } from "@shipengine/elements-ui";
|
|
3
3
|
import SE from "@shipengine/elements-core";
|
|
4
|
+
import { UseShippingPresetsOptionsProps } from "@shipengine/elements-ui";
|
|
4
5
|
export declare type ShipmentFormMode = "browse_rates" | "select_service";
|
|
5
6
|
export declare type ShipmentUpdatedOptions = {
|
|
6
7
|
shouldCalculateRates?: boolean;
|
|
7
8
|
shouldResetAddressPreference?: boolean;
|
|
8
9
|
};
|
|
10
|
+
declare type ShipmentFormTemplateProps = React.ComponentProps<typeof Templates.ShipmentForm>;
|
|
9
11
|
export declare type ShipmentFormProps = {
|
|
10
12
|
addressPreference?: Templates.AddressPreference;
|
|
13
|
+
onChangeAddress?: (addressPreference: Templates.AddressPreference) => any | void;
|
|
14
|
+
onChangeShipmentFormMode?: ShipmentFormTemplateProps["onChangeMode"];
|
|
11
15
|
onShipmentDirty: () => void;
|
|
12
16
|
onShipmentUpdated: (shipment: SE.SalesOrderShipment, options?: ShipmentUpdatedOptions) => void;
|
|
17
|
+
onToggleAddressPreferenceDisclosure?: ShipmentFormTemplateProps["onToggleAddressPreferenceDisclosure"];
|
|
13
18
|
salesOrder: SE.SalesOrder;
|
|
14
19
|
shipment?: SE.SalesOrderShipment;
|
|
20
|
+
shippingPresets?: UseShippingPresetsOptionsProps;
|
|
15
21
|
};
|
|
16
|
-
export declare const ShipmentForm: ({ addressPreference, onShipmentDirty, onShipmentUpdated, salesOrder, shipment, }: ShipmentFormProps) => JSX.Element;
|
|
22
|
+
export declare const ShipmentForm: ({ addressPreference, onChangeAddress, onChangeShipmentFormMode, onShipmentDirty, onShipmentUpdated, onToggleAddressPreferenceDisclosure, salesOrder, shipment, shippingPresets, }: ShipmentFormProps) => JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -6,5 +6,21 @@ export declare type ResetAddressPreferenceParams = {
|
|
|
6
6
|
};
|
|
7
7
|
export declare const useAddressPreference: () => {
|
|
8
8
|
readonly addressPreference: Templates.AddressPreference | undefined;
|
|
9
|
-
readonly resetAddressPreference: ({ validation, fallbackAddress }: ResetAddressPreferenceParams) =>
|
|
9
|
+
readonly resetAddressPreference: ({ validation, fallbackAddress }: ResetAddressPreferenceParams) => {
|
|
10
|
+
alternative: SE.Address | undefined;
|
|
11
|
+
selection: SE.Address;
|
|
12
|
+
status: "unverified" | "verified" | "warning" | "error";
|
|
13
|
+
originalAddress: SE.Address;
|
|
14
|
+
matchedAddress?: SE.Address | undefined;
|
|
15
|
+
messages: {
|
|
16
|
+
code: "a1000" | "a1001" | "a1002" | "a1003" | "a1004" | "a1005" | "a1006" | "a1007" | "a1008" | "r1000" | "r1001" | "r1002" | "r1003";
|
|
17
|
+
message: string;
|
|
18
|
+
type: "warning" | "error" | "info";
|
|
19
|
+
detailCode: "address_not_found" | "city_locality_changed_or_added" | "city_locality_max_length_exceeded" | "coded_to_community_level" | "coded_to_neighborhood_level" | "coded_to_rooftop_interpolation_level" | "coded_to_rooftop_level" | "coded_to_state_level" | "coded_to_street_lavel" | "company_name_max_length_exceeded" | "country_invalid_length" | "double_dependent_locality_changed_or_added" | "house_number_changed" | "incompatible_paired_labels" | "invalid_box_number" | "invalid_charge_event" | "invalid_house_number" | "invalid_postal_code" | "line1_min_max_length" | "line2_max_length_exceeded" | "line3_max_length_exceeded" | "minimum_postal_code_verification_failed" | "missing_box_number" | "missing_cmra_or_private_mail_box_number" | "missing_house_number" | "multiple_directionals" | "multiple_matches" | "name_max_length_exceeded" | "non_supported_country" | "organization_changed_or_added" | "partially_verified_to_city_level" | "partially_verified_to_premise_level" | "partially_verified_to_state_level" | "partially_verified_to_street_level" | "phone_max_length_exceeded" | "po_box_changed_or_added" | "postal_code_changed_or_added" | "premise_type_changed_or_added" | "state_province_changed_or_added" | "state_province_max_length_exceeded" | "street_direction_changed_or_added" | "street_does_not_match_unique_street_name" | "street_name_spelling_changed_or_added" | "street_name_type_changed_or_added" | "subadministrative_area_changed_or_added" | "subnational_area_changed_or_added" | "suite_has_no_secondaries" | "suite_missing" | "suite_not_valid" | "suite_type_changed_or_added" | "suite_unit_number_changed_or_added" | "unsupported_country" | "urbanization_changed" | "verified_to_city_level" | "verified_to_premise_level" | "verified_to_state_level" | "verified_to_street_level" | "verified_to_suite_level";
|
|
20
|
+
}[];
|
|
21
|
+
alternativeSource: "originalAddress" | "matchedAddress";
|
|
22
|
+
isModified: boolean;
|
|
23
|
+
toggle: () => SE.Address;
|
|
24
|
+
selectionSource: "originalAddress" | "matchedAddress";
|
|
25
|
+
};
|
|
10
26
|
};
|
package/index.cjs
CHANGED
|
@@ -2731,11 +2731,15 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
2731
2731
|
|
|
2732
2732
|
const ShipmentForm = ({
|
|
2733
2733
|
addressPreference,
|
|
2734
|
+
onChangeAddress,
|
|
2735
|
+
onChangeShipmentFormMode,
|
|
2734
2736
|
onShipmentDirty,
|
|
2735
2737
|
// Must be referentially stable
|
|
2736
2738
|
onShipmentUpdated,
|
|
2739
|
+
onToggleAddressPreferenceDisclosure,
|
|
2737
2740
|
salesOrder,
|
|
2738
|
-
shipment
|
|
2741
|
+
shipment,
|
|
2742
|
+
shippingPresets
|
|
2739
2743
|
}) => {
|
|
2740
2744
|
const {
|
|
2741
2745
|
t
|
|
@@ -2775,7 +2779,7 @@ const ShipmentForm = ({
|
|
|
2775
2779
|
}), [createOrUpdateShipment, onShipmentUpdated]); // Handles any changes to the ship to address as well as handling user
|
|
2776
2780
|
// selecting fall-back address
|
|
2777
2781
|
|
|
2778
|
-
const handleChangeAddress =
|
|
2782
|
+
const handleChangeAddress = (payload, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2779
2783
|
const updatedShipment = yield createOrUpdateShipment(Object.assign(Object.assign(Object.assign({}, shipment), {
|
|
2780
2784
|
shipTo: payload
|
|
2781
2785
|
}), options.shouldValidate && {
|
|
@@ -2788,8 +2792,29 @@ const ShipmentForm = ({
|
|
|
2788
2792
|
shouldResetAddressPreference: options.shouldValidate
|
|
2789
2793
|
});
|
|
2790
2794
|
}
|
|
2791
|
-
})
|
|
2792
|
-
|
|
2795
|
+
});
|
|
2796
|
+
|
|
2797
|
+
const handleApplyPreset = preset => __awaiter(void 0, void 0, void 0, function* () {
|
|
2798
|
+
const updatedShipment = yield createOrUpdateShipment(Object.assign(Object.assign(Object.assign({}, shipment), preset.serviceCode && preset.carrierId && {
|
|
2799
|
+
carrierId: preset.carrierId,
|
|
2800
|
+
serviceCode: preset.serviceCode
|
|
2801
|
+
}), {
|
|
2802
|
+
confirmation: preset.confirmation,
|
|
2803
|
+
insuranceProvider: preset.insuranceProvider,
|
|
2804
|
+
packages: preset.weight && preset.packageCode ? [{
|
|
2805
|
+
dimensions: preset.dimensions,
|
|
2806
|
+
weight: preset.weight,
|
|
2807
|
+
insuredValue: preset.insuredValue,
|
|
2808
|
+
packageCode: preset.packageCode
|
|
2809
|
+
}] : undefined
|
|
2810
|
+
}));
|
|
2811
|
+
if (updatedShipment) onShipmentUpdated(updatedShipment, {
|
|
2812
|
+
shouldCalculateRates: !!(preset.dimensions && preset.weight),
|
|
2813
|
+
shouldResetAddressPreference: false
|
|
2814
|
+
});
|
|
2815
|
+
});
|
|
2816
|
+
|
|
2817
|
+
const handleSubmitParseShipTo = ({
|
|
2793
2818
|
fullAddress
|
|
2794
2819
|
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2795
2820
|
const parseResult = yield parseAddress.trigger({
|
|
@@ -2797,19 +2822,35 @@ const ShipmentForm = ({
|
|
|
2797
2822
|
});
|
|
2798
2823
|
if (!parseResult) logger.warn("Address parser returned no results");
|
|
2799
2824
|
return parseResult;
|
|
2800
|
-
})
|
|
2801
|
-
|
|
2825
|
+
});
|
|
2826
|
+
|
|
2827
|
+
const handleUpdateCustoms = customs => __awaiter(void 0, void 0, void 0, function* () {
|
|
2828
|
+
const updatedShipment = yield createOrUpdateShipment(Object.assign(Object.assign({}, shipment), {
|
|
2829
|
+
customs
|
|
2830
|
+
}));
|
|
2831
|
+
|
|
2832
|
+
if (updatedShipment) {
|
|
2833
|
+
onShipmentUpdated(updatedShipment);
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
|
|
2837
|
+
const errors = [...(updateShipment.errors || []), ...(createShipment.errors || [])];
|
|
2802
2838
|
return jsxRuntime.jsx(elementsUi.Templates.ShipmentForm, {
|
|
2803
2839
|
addressPreference: addressPreference,
|
|
2840
|
+
onToggleAddressPreferenceDisclosure: onToggleAddressPreferenceDisclosure,
|
|
2841
|
+
onChangeMode: onChangeShipmentFormMode,
|
|
2804
2842
|
carriers: carriers.data,
|
|
2805
2843
|
customPackageTypes: customPackageTypes.data,
|
|
2806
2844
|
errors: errors,
|
|
2845
|
+
onApplyPreset: handleApplyPreset,
|
|
2807
2846
|
onChangeAddress: handleChangeAddress,
|
|
2808
2847
|
onDirty: onShipmentDirty,
|
|
2809
2848
|
onSubmit: handleSubmit,
|
|
2849
|
+
onUpdateCustoms: handleUpdateCustoms,
|
|
2810
2850
|
onSubmitParseShipTo: handleSubmitParseShipTo,
|
|
2811
2851
|
salesOrder: salesOrder,
|
|
2812
2852
|
shipment: shipment,
|
|
2853
|
+
shippingPresets: shippingPresets,
|
|
2813
2854
|
warehouses: warehouses.data
|
|
2814
2855
|
});
|
|
2815
2856
|
};
|
|
@@ -2817,7 +2858,8 @@ const ShipmentForm = ({
|
|
|
2817
2858
|
const RateForm = ({
|
|
2818
2859
|
errors,
|
|
2819
2860
|
loading: _loading = false,
|
|
2820
|
-
|
|
2861
|
+
onLabelCreateFailure,
|
|
2862
|
+
onLabelCreateSuccess,
|
|
2821
2863
|
onRateSaved,
|
|
2822
2864
|
rates,
|
|
2823
2865
|
shipment
|
|
@@ -2830,8 +2872,13 @@ const RateForm = ({
|
|
|
2830
2872
|
});
|
|
2831
2873
|
|
|
2832
2874
|
const handleSubmit = values => __awaiter(void 0, void 0, void 0, function* () {
|
|
2833
|
-
const label = yield createLabel.trigger(values);
|
|
2834
|
-
|
|
2875
|
+
const label = yield createLabel.trigger(values.rate);
|
|
2876
|
+
|
|
2877
|
+
if (label) {
|
|
2878
|
+
onLabelCreateSuccess === null || onLabelCreateSuccess === void 0 ? void 0 : onLabelCreateSuccess(label, shipment);
|
|
2879
|
+
} else {
|
|
2880
|
+
onLabelCreateFailure === null || onLabelCreateFailure === void 0 ? void 0 : onLabelCreateFailure();
|
|
2881
|
+
}
|
|
2835
2882
|
});
|
|
2836
2883
|
|
|
2837
2884
|
const handleSave = rate => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -2845,10 +2892,9 @@ const RateForm = ({
|
|
|
2845
2892
|
});
|
|
2846
2893
|
|
|
2847
2894
|
const carriers = elementsCore.useListCarriers();
|
|
2848
|
-
const mergedErrors = [...(errors !== null && errors !== void 0 ? errors : []), ...((_a = createLabel.errors) !== null && _a !== void 0 ? _a : [])];
|
|
2849
2895
|
return jsxRuntime.jsx(elementsUi.Templates.RateForm, {
|
|
2850
2896
|
carriers: carriers.data,
|
|
2851
|
-
errors:
|
|
2897
|
+
errors: [...(errors !== null && errors !== void 0 ? errors : []), ...((_a = createLabel.errors) !== null && _a !== void 0 ? _a : [])],
|
|
2852
2898
|
loading: _loading,
|
|
2853
2899
|
onSave: handleSave,
|
|
2854
2900
|
onSubmit: handleSubmit,
|
|
@@ -20108,10 +20154,12 @@ const useAddressPreference = () => {
|
|
|
20108
20154
|
const alternative = newAddressPreference[alternativeSource];
|
|
20109
20155
|
const selection = newAddressPreference[selectionSource];
|
|
20110
20156
|
if (!selection) throw new Error("Cannot select an undefined address.");
|
|
20111
|
-
|
|
20157
|
+
const updatedAddressPreference = Object.assign(Object.assign({}, newAddressPreference), {
|
|
20112
20158
|
alternative,
|
|
20113
20159
|
selection
|
|
20114
|
-
})
|
|
20160
|
+
});
|
|
20161
|
+
setAddressPreference(updatedAddressPreference);
|
|
20162
|
+
return updatedAddressPreference;
|
|
20115
20163
|
}, [toggle]);
|
|
20116
20164
|
return {
|
|
20117
20165
|
addressPreference,
|
|
@@ -20122,10 +20170,18 @@ const useAddressPreference = () => {
|
|
|
20122
20170
|
const SalesOrder = ({
|
|
20123
20171
|
externalOrderId,
|
|
20124
20172
|
externalOrderNumber,
|
|
20173
|
+
onAddressValidation,
|
|
20174
|
+
onChangeAddress,
|
|
20175
|
+
onLabelCreateFailure,
|
|
20176
|
+
onLabelCreateSuccess,
|
|
20125
20177
|
onLoad,
|
|
20126
|
-
|
|
20178
|
+
onRateSaved,
|
|
20179
|
+
onRatesReturned,
|
|
20180
|
+
onChangeShipmentFormMode,
|
|
20181
|
+
onToggleAddressPreferenceDisclosure,
|
|
20127
20182
|
orderSourceCode,
|
|
20128
|
-
salesOrderId
|
|
20183
|
+
salesOrderId,
|
|
20184
|
+
shippingPresets
|
|
20129
20185
|
}) => {
|
|
20130
20186
|
var _a, _b, _c, _d, _e;
|
|
20131
20187
|
|
|
@@ -20192,10 +20248,14 @@ const SalesOrder = ({
|
|
|
20192
20248
|
void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
20193
20249
|
var _a, _b, _c;
|
|
20194
20250
|
|
|
20195
|
-
if (((_a = salesOrders.data) === null || _a === void 0 ? void 0 : _a.length) && shipments.data && !createShipment.data && !createShipment.errors && !createShipment.isMutating) {
|
|
20196
|
-
|
|
20197
|
-
|
|
20198
|
-
|
|
20251
|
+
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) {
|
|
20252
|
+
const currentSalesOrder = salesOrders.data[0];
|
|
20253
|
+
const pendingShipment = shipments.data.find(s => s.shipmentStatus === "pending");
|
|
20254
|
+
|
|
20255
|
+
if (currentSalesOrder && !pendingShipment) {
|
|
20256
|
+
const defaultWarehouse = (_c = warehouses.data) === null || _c === void 0 ? void 0 : _c[0]; // We don't have a shipment yet; create one.
|
|
20257
|
+
|
|
20258
|
+
const result = yield createShipment.trigger(Object.assign({
|
|
20199
20259
|
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20200
20260
|
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20201
20261
|
packages: [{
|
|
@@ -20205,8 +20265,10 @@ const SalesOrder = ({
|
|
|
20205
20265
|
}
|
|
20206
20266
|
}],
|
|
20207
20267
|
validateAddress: "validate_and_clean",
|
|
20208
|
-
warehouseId:
|
|
20209
|
-
})
|
|
20268
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20269
|
+
}, elementsCore.getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20270
|
+
customs: elementsCore.getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20271
|
+
}));
|
|
20210
20272
|
|
|
20211
20273
|
if (!result) {
|
|
20212
20274
|
logger.error("createShipment returned an undefined result");
|
|
@@ -20214,28 +20276,30 @@ const SalesOrder = ({
|
|
|
20214
20276
|
logger.error("createShipment returned an undefined addressValidation");
|
|
20215
20277
|
} else {
|
|
20216
20278
|
yield shipments.mutate();
|
|
20217
|
-
resetAddressPreference({
|
|
20279
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20218
20280
|
validation: result.addressValidation,
|
|
20219
|
-
fallbackAddress:
|
|
20281
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20220
20282
|
});
|
|
20283
|
+
onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20221
20284
|
}
|
|
20222
|
-
} else if (!validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
20285
|
+
} else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
20223
20286
|
// We have a preexisting shipment; validate the address
|
|
20224
20287
|
const result = yield validateAddresses.trigger({
|
|
20225
|
-
addresses: [
|
|
20288
|
+
addresses: [pendingShipment.shipTo]
|
|
20226
20289
|
});
|
|
20227
20290
|
const addressValidation = result === null || result === void 0 ? void 0 : result[0];
|
|
20228
20291
|
|
|
20229
20292
|
if (addressValidation) {
|
|
20230
|
-
resetAddressPreference({
|
|
20293
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20231
20294
|
validation: addressValidation,
|
|
20232
|
-
fallbackAddress:
|
|
20295
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20233
20296
|
});
|
|
20297
|
+
onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20234
20298
|
}
|
|
20235
20299
|
}
|
|
20236
20300
|
}
|
|
20237
20301
|
}))();
|
|
20238
|
-
}, [addressPreference, createShipment, logger, salesOrders.data, shipments, shipments.data,
|
|
20302
|
+
}, [addressPreference, createShipment, logger, onAddressValidation, resetAddressPreference, salesOrders.data, shipments, shipments.data, validateAddresses, warehouses.data]);
|
|
20239
20303
|
const hasCustomPackage = react.useCallback(shipment => {
|
|
20240
20304
|
var _a;
|
|
20241
20305
|
|
|
@@ -20247,9 +20311,11 @@ const SalesOrder = ({
|
|
|
20247
20311
|
yield shipments.mutate();
|
|
20248
20312
|
|
|
20249
20313
|
if (options.shouldResetAddressPreference && shipment.addressValidation) {
|
|
20250
|
-
resetAddressPreference({
|
|
20314
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20251
20315
|
validation: shipment.addressValidation
|
|
20252
20316
|
});
|
|
20317
|
+
onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20318
|
+
onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
|
|
20253
20319
|
}
|
|
20254
20320
|
|
|
20255
20321
|
if (options.shouldCalculateRates) {
|
|
@@ -20261,7 +20327,8 @@ const SalesOrder = ({
|
|
|
20261
20327
|
packageTypes: hasCustomPackage(shipment) ? ["package"] // Only specify package types for non-custom packages
|
|
20262
20328
|
: shipment.packages.map(pkg => pkg.packageCode)
|
|
20263
20329
|
}
|
|
20264
|
-
});
|
|
20330
|
+
});
|
|
20331
|
+
result && (onRatesReturned === null || onRatesReturned === void 0 ? void 0 : onRatesReturned(result.rates, shipment)); // We are hiding, from the user, any errors in the rate response if the response
|
|
20265
20332
|
// contains rates. Log to the console any rate errors if the response has rates.
|
|
20266
20333
|
|
|
20267
20334
|
if ((result === null || result === void 0 ? void 0 : result.errors.length) && result.rates.length) {
|
|
@@ -20270,13 +20337,10 @@ const SalesOrder = ({
|
|
|
20270
20337
|
}, `Rate response had errors`);
|
|
20271
20338
|
}
|
|
20272
20339
|
}
|
|
20273
|
-
}), [calculateRates, carriers.data, hasCustomPackage, logger, resetAddressPreference, shipments]);
|
|
20340
|
+
}), [calculateRates, carriers.data, hasCustomPackage, logger, onChangeAddress, onAddressValidation, onRatesReturned, resetAddressPreference, shipments]);
|
|
20274
20341
|
const handleShipmentDirty = react.useCallback(() => {
|
|
20275
20342
|
calculateRates.reset();
|
|
20276
20343
|
}, [calculateRates]);
|
|
20277
|
-
const handleLabelCreated = react.useCallback(label => __awaiter(void 0, void 0, void 0, function* () {
|
|
20278
|
-
if (label) onPurchase === null || onPurchase === void 0 ? void 0 : onPurchase(label);
|
|
20279
|
-
}), [onPurchase]);
|
|
20280
20344
|
if (salesOrders.isLoading) return jsxRuntime.jsx(elementsUi.Loader, {
|
|
20281
20345
|
message: t("loading.salesOrder")
|
|
20282
20346
|
});
|
|
@@ -20304,15 +20368,20 @@ const SalesOrder = ({
|
|
|
20304
20368
|
}, {
|
|
20305
20369
|
children: [jsxRuntime.jsx(ShipmentForm, {
|
|
20306
20370
|
addressPreference: addressPreference,
|
|
20371
|
+
onChangeAddress: onChangeAddress,
|
|
20372
|
+
onChangeShipmentFormMode: onChangeShipmentFormMode,
|
|
20307
20373
|
onShipmentDirty: handleShipmentDirty,
|
|
20308
20374
|
onShipmentUpdated: handleShipmentUpdated,
|
|
20375
|
+
onToggleAddressPreferenceDisclosure: onToggleAddressPreferenceDisclosure,
|
|
20309
20376
|
salesOrder: salesOrder,
|
|
20310
|
-
shipment: shipment
|
|
20377
|
+
shipment: shipment,
|
|
20378
|
+
shippingPresets: shippingPresets
|
|
20311
20379
|
}), jsxRuntime.jsx(RateForm, {
|
|
20312
20380
|
errors: [...((_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 : [])],
|
|
20313
20381
|
loading: calculateRates.isMutating,
|
|
20314
|
-
|
|
20315
|
-
|
|
20382
|
+
onLabelCreateFailure: onLabelCreateFailure,
|
|
20383
|
+
onLabelCreateSuccess: onLabelCreateSuccess,
|
|
20384
|
+
onRateSaved: onRateSaved,
|
|
20316
20385
|
rates: (_e = calculateRates.data) === null || _e === void 0 ? void 0 : _e.rates,
|
|
20317
20386
|
shipment: shipment
|
|
20318
20387
|
})]
|
|
@@ -20322,9 +20391,10 @@ const SalesOrder = ({
|
|
|
20322
20391
|
const Element$2 = elementsCore.registerElement("purchase-label", SalesOrder);
|
|
20323
20392
|
|
|
20324
20393
|
const Shipment = ({
|
|
20325
|
-
|
|
20394
|
+
onClickPrintLabel,
|
|
20395
|
+
onClickPurchaseLabel,
|
|
20326
20396
|
onClickVoidLabel,
|
|
20327
|
-
|
|
20397
|
+
shipmentId
|
|
20328
20398
|
}) => {
|
|
20329
20399
|
var _a, _b, _c;
|
|
20330
20400
|
|
|
@@ -20357,6 +20427,7 @@ const Shipment = ({
|
|
|
20357
20427
|
carriers: carriers.data,
|
|
20358
20428
|
labels: labels.data,
|
|
20359
20429
|
onClickPurchaseLabel: onClickPurchaseLabel,
|
|
20430
|
+
onClickPrintLabel: onClickPrintLabel,
|
|
20360
20431
|
onClickVoidLabel: onClickVoidLabel,
|
|
20361
20432
|
salesOrder: salesOrder,
|
|
20362
20433
|
shipment: shipment.data,
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useTranslation, useLogger, useListWarehouses, useListCarriers, useCreateShipment, useUpdateShipment, useParseAddress, useListCustomPackageTypes, useCreateLabel, isDomesticAddress, useListSalesOrders, useListOrderSources, useRefreshOrderSource, useCalculateRates, useValidateAddresses, useListShipments, registerElement, useGetShipment, useListLabels, useGetLabel, useVoidLabel } from '@shipengine/elements-core';
|
|
1
|
+
import { useTranslation, 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';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { useCallback,
|
|
3
|
+
import { useCallback, useState, useEffect } from 'react';
|
|
4
4
|
import { Templates, Loader } from '@shipengine/elements-ui';
|
|
5
5
|
|
|
6
6
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -2727,11 +2727,15 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
2727
2727
|
|
|
2728
2728
|
const ShipmentForm = ({
|
|
2729
2729
|
addressPreference,
|
|
2730
|
+
onChangeAddress,
|
|
2731
|
+
onChangeShipmentFormMode,
|
|
2730
2732
|
onShipmentDirty,
|
|
2731
2733
|
// Must be referentially stable
|
|
2732
2734
|
onShipmentUpdated,
|
|
2735
|
+
onToggleAddressPreferenceDisclosure,
|
|
2733
2736
|
salesOrder,
|
|
2734
|
-
shipment
|
|
2737
|
+
shipment,
|
|
2738
|
+
shippingPresets
|
|
2735
2739
|
}) => {
|
|
2736
2740
|
const {
|
|
2737
2741
|
t
|
|
@@ -2771,7 +2775,7 @@ const ShipmentForm = ({
|
|
|
2771
2775
|
}), [createOrUpdateShipment, onShipmentUpdated]); // Handles any changes to the ship to address as well as handling user
|
|
2772
2776
|
// selecting fall-back address
|
|
2773
2777
|
|
|
2774
|
-
const handleChangeAddress =
|
|
2778
|
+
const handleChangeAddress = (payload, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2775
2779
|
const updatedShipment = yield createOrUpdateShipment(Object.assign(Object.assign(Object.assign({}, shipment), {
|
|
2776
2780
|
shipTo: payload
|
|
2777
2781
|
}), options.shouldValidate && {
|
|
@@ -2784,8 +2788,29 @@ const ShipmentForm = ({
|
|
|
2784
2788
|
shouldResetAddressPreference: options.shouldValidate
|
|
2785
2789
|
});
|
|
2786
2790
|
}
|
|
2787
|
-
})
|
|
2788
|
-
|
|
2791
|
+
});
|
|
2792
|
+
|
|
2793
|
+
const handleApplyPreset = preset => __awaiter(void 0, void 0, void 0, function* () {
|
|
2794
|
+
const updatedShipment = yield createOrUpdateShipment(Object.assign(Object.assign(Object.assign({}, shipment), preset.serviceCode && preset.carrierId && {
|
|
2795
|
+
carrierId: preset.carrierId,
|
|
2796
|
+
serviceCode: preset.serviceCode
|
|
2797
|
+
}), {
|
|
2798
|
+
confirmation: preset.confirmation,
|
|
2799
|
+
insuranceProvider: preset.insuranceProvider,
|
|
2800
|
+
packages: preset.weight && preset.packageCode ? [{
|
|
2801
|
+
dimensions: preset.dimensions,
|
|
2802
|
+
weight: preset.weight,
|
|
2803
|
+
insuredValue: preset.insuredValue,
|
|
2804
|
+
packageCode: preset.packageCode
|
|
2805
|
+
}] : undefined
|
|
2806
|
+
}));
|
|
2807
|
+
if (updatedShipment) onShipmentUpdated(updatedShipment, {
|
|
2808
|
+
shouldCalculateRates: !!(preset.dimensions && preset.weight),
|
|
2809
|
+
shouldResetAddressPreference: false
|
|
2810
|
+
});
|
|
2811
|
+
});
|
|
2812
|
+
|
|
2813
|
+
const handleSubmitParseShipTo = ({
|
|
2789
2814
|
fullAddress
|
|
2790
2815
|
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2791
2816
|
const parseResult = yield parseAddress.trigger({
|
|
@@ -2793,19 +2818,35 @@ const ShipmentForm = ({
|
|
|
2793
2818
|
});
|
|
2794
2819
|
if (!parseResult) logger.warn("Address parser returned no results");
|
|
2795
2820
|
return parseResult;
|
|
2796
|
-
})
|
|
2797
|
-
|
|
2821
|
+
});
|
|
2822
|
+
|
|
2823
|
+
const handleUpdateCustoms = customs => __awaiter(void 0, void 0, void 0, function* () {
|
|
2824
|
+
const updatedShipment = yield createOrUpdateShipment(Object.assign(Object.assign({}, shipment), {
|
|
2825
|
+
customs
|
|
2826
|
+
}));
|
|
2827
|
+
|
|
2828
|
+
if (updatedShipment) {
|
|
2829
|
+
onShipmentUpdated(updatedShipment);
|
|
2830
|
+
}
|
|
2831
|
+
});
|
|
2832
|
+
|
|
2833
|
+
const errors = [...(updateShipment.errors || []), ...(createShipment.errors || [])];
|
|
2798
2834
|
return jsx(Templates.ShipmentForm, {
|
|
2799
2835
|
addressPreference: addressPreference,
|
|
2836
|
+
onToggleAddressPreferenceDisclosure: onToggleAddressPreferenceDisclosure,
|
|
2837
|
+
onChangeMode: onChangeShipmentFormMode,
|
|
2800
2838
|
carriers: carriers.data,
|
|
2801
2839
|
customPackageTypes: customPackageTypes.data,
|
|
2802
2840
|
errors: errors,
|
|
2841
|
+
onApplyPreset: handleApplyPreset,
|
|
2803
2842
|
onChangeAddress: handleChangeAddress,
|
|
2804
2843
|
onDirty: onShipmentDirty,
|
|
2805
2844
|
onSubmit: handleSubmit,
|
|
2845
|
+
onUpdateCustoms: handleUpdateCustoms,
|
|
2806
2846
|
onSubmitParseShipTo: handleSubmitParseShipTo,
|
|
2807
2847
|
salesOrder: salesOrder,
|
|
2808
2848
|
shipment: shipment,
|
|
2849
|
+
shippingPresets: shippingPresets,
|
|
2809
2850
|
warehouses: warehouses.data
|
|
2810
2851
|
});
|
|
2811
2852
|
};
|
|
@@ -2813,7 +2854,8 @@ const ShipmentForm = ({
|
|
|
2813
2854
|
const RateForm = ({
|
|
2814
2855
|
errors,
|
|
2815
2856
|
loading: _loading = false,
|
|
2816
|
-
|
|
2857
|
+
onLabelCreateFailure,
|
|
2858
|
+
onLabelCreateSuccess,
|
|
2817
2859
|
onRateSaved,
|
|
2818
2860
|
rates,
|
|
2819
2861
|
shipment
|
|
@@ -2826,8 +2868,13 @@ const RateForm = ({
|
|
|
2826
2868
|
});
|
|
2827
2869
|
|
|
2828
2870
|
const handleSubmit = values => __awaiter(void 0, void 0, void 0, function* () {
|
|
2829
|
-
const label = yield createLabel.trigger(values);
|
|
2830
|
-
|
|
2871
|
+
const label = yield createLabel.trigger(values.rate);
|
|
2872
|
+
|
|
2873
|
+
if (label) {
|
|
2874
|
+
onLabelCreateSuccess === null || onLabelCreateSuccess === void 0 ? void 0 : onLabelCreateSuccess(label, shipment);
|
|
2875
|
+
} else {
|
|
2876
|
+
onLabelCreateFailure === null || onLabelCreateFailure === void 0 ? void 0 : onLabelCreateFailure();
|
|
2877
|
+
}
|
|
2831
2878
|
});
|
|
2832
2879
|
|
|
2833
2880
|
const handleSave = rate => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -2841,10 +2888,9 @@ const RateForm = ({
|
|
|
2841
2888
|
});
|
|
2842
2889
|
|
|
2843
2890
|
const carriers = useListCarriers();
|
|
2844
|
-
const mergedErrors = [...(errors !== null && errors !== void 0 ? errors : []), ...((_a = createLabel.errors) !== null && _a !== void 0 ? _a : [])];
|
|
2845
2891
|
return jsx(Templates.RateForm, {
|
|
2846
2892
|
carriers: carriers.data,
|
|
2847
|
-
errors:
|
|
2893
|
+
errors: [...(errors !== null && errors !== void 0 ? errors : []), ...((_a = createLabel.errors) !== null && _a !== void 0 ? _a : [])],
|
|
2848
2894
|
loading: _loading,
|
|
2849
2895
|
onSave: handleSave,
|
|
2850
2896
|
onSubmit: handleSubmit,
|
|
@@ -20104,10 +20150,12 @@ const useAddressPreference = () => {
|
|
|
20104
20150
|
const alternative = newAddressPreference[alternativeSource];
|
|
20105
20151
|
const selection = newAddressPreference[selectionSource];
|
|
20106
20152
|
if (!selection) throw new Error("Cannot select an undefined address.");
|
|
20107
|
-
|
|
20153
|
+
const updatedAddressPreference = Object.assign(Object.assign({}, newAddressPreference), {
|
|
20108
20154
|
alternative,
|
|
20109
20155
|
selection
|
|
20110
|
-
})
|
|
20156
|
+
});
|
|
20157
|
+
setAddressPreference(updatedAddressPreference);
|
|
20158
|
+
return updatedAddressPreference;
|
|
20111
20159
|
}, [toggle]);
|
|
20112
20160
|
return {
|
|
20113
20161
|
addressPreference,
|
|
@@ -20118,10 +20166,18 @@ const useAddressPreference = () => {
|
|
|
20118
20166
|
const SalesOrder = ({
|
|
20119
20167
|
externalOrderId,
|
|
20120
20168
|
externalOrderNumber,
|
|
20169
|
+
onAddressValidation,
|
|
20170
|
+
onChangeAddress,
|
|
20171
|
+
onLabelCreateFailure,
|
|
20172
|
+
onLabelCreateSuccess,
|
|
20121
20173
|
onLoad,
|
|
20122
|
-
|
|
20174
|
+
onRateSaved,
|
|
20175
|
+
onRatesReturned,
|
|
20176
|
+
onChangeShipmentFormMode,
|
|
20177
|
+
onToggleAddressPreferenceDisclosure,
|
|
20123
20178
|
orderSourceCode,
|
|
20124
|
-
salesOrderId
|
|
20179
|
+
salesOrderId,
|
|
20180
|
+
shippingPresets
|
|
20125
20181
|
}) => {
|
|
20126
20182
|
var _a, _b, _c, _d, _e;
|
|
20127
20183
|
|
|
@@ -20188,10 +20244,14 @@ const SalesOrder = ({
|
|
|
20188
20244
|
void (() => __awaiter(void 0, void 0, void 0, function* () {
|
|
20189
20245
|
var _a, _b, _c;
|
|
20190
20246
|
|
|
20191
|
-
if (((_a = salesOrders.data) === null || _a === void 0 ? void 0 : _a.length) && shipments.data && !createShipment.data && !createShipment.errors && !createShipment.isMutating) {
|
|
20192
|
-
|
|
20193
|
-
|
|
20194
|
-
|
|
20247
|
+
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) {
|
|
20248
|
+
const currentSalesOrder = salesOrders.data[0];
|
|
20249
|
+
const pendingShipment = shipments.data.find(s => s.shipmentStatus === "pending");
|
|
20250
|
+
|
|
20251
|
+
if (currentSalesOrder && !pendingShipment) {
|
|
20252
|
+
const defaultWarehouse = (_c = warehouses.data) === null || _c === void 0 ? void 0 : _c[0]; // We don't have a shipment yet; create one.
|
|
20253
|
+
|
|
20254
|
+
const result = yield createShipment.trigger(Object.assign({
|
|
20195
20255
|
// /v-beta/shipments/sales_order/:salesOrderId requires at minimum
|
|
20196
20256
|
// a (warehouseId or shipFrom) and a package with weight defined.
|
|
20197
20257
|
packages: [{
|
|
@@ -20201,8 +20261,10 @@ const SalesOrder = ({
|
|
|
20201
20261
|
}
|
|
20202
20262
|
}],
|
|
20203
20263
|
validateAddress: "validate_and_clean",
|
|
20204
|
-
warehouseId:
|
|
20205
|
-
})
|
|
20264
|
+
warehouseId: defaultWarehouse.warehouseId
|
|
20265
|
+
}, getIsCustomsRequiredForSalesOrder(currentSalesOrder, defaultWarehouse) && {
|
|
20266
|
+
customs: getCustomsFromSalesOrder(currentSalesOrder, defaultWarehouse)
|
|
20267
|
+
}));
|
|
20206
20268
|
|
|
20207
20269
|
if (!result) {
|
|
20208
20270
|
logger.error("createShipment returned an undefined result");
|
|
@@ -20210,28 +20272,30 @@ const SalesOrder = ({
|
|
|
20210
20272
|
logger.error("createShipment returned an undefined addressValidation");
|
|
20211
20273
|
} else {
|
|
20212
20274
|
yield shipments.mutate();
|
|
20213
|
-
resetAddressPreference({
|
|
20275
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20214
20276
|
validation: result.addressValidation,
|
|
20215
|
-
fallbackAddress:
|
|
20277
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20216
20278
|
});
|
|
20279
|
+
onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20217
20280
|
}
|
|
20218
|
-
} else if (!validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
20281
|
+
} else if (currentSalesOrder && pendingShipment && !validateAddresses.data && !validateAddresses.errors && !validateAddresses.isMutating) {
|
|
20219
20282
|
// We have a preexisting shipment; validate the address
|
|
20220
20283
|
const result = yield validateAddresses.trigger({
|
|
20221
|
-
addresses: [
|
|
20284
|
+
addresses: [pendingShipment.shipTo]
|
|
20222
20285
|
});
|
|
20223
20286
|
const addressValidation = result === null || result === void 0 ? void 0 : result[0];
|
|
20224
20287
|
|
|
20225
20288
|
if (addressValidation) {
|
|
20226
|
-
resetAddressPreference({
|
|
20289
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20227
20290
|
validation: addressValidation,
|
|
20228
|
-
fallbackAddress:
|
|
20291
|
+
fallbackAddress: currentSalesOrder.shipTo
|
|
20229
20292
|
});
|
|
20293
|
+
onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20230
20294
|
}
|
|
20231
20295
|
}
|
|
20232
20296
|
}
|
|
20233
20297
|
}))();
|
|
20234
|
-
}, [addressPreference, createShipment, logger, salesOrders.data, shipments, shipments.data,
|
|
20298
|
+
}, [addressPreference, createShipment, logger, onAddressValidation, resetAddressPreference, salesOrders.data, shipments, shipments.data, validateAddresses, warehouses.data]);
|
|
20235
20299
|
const hasCustomPackage = useCallback(shipment => {
|
|
20236
20300
|
var _a;
|
|
20237
20301
|
|
|
@@ -20243,9 +20307,11 @@ const SalesOrder = ({
|
|
|
20243
20307
|
yield shipments.mutate();
|
|
20244
20308
|
|
|
20245
20309
|
if (options.shouldResetAddressPreference && shipment.addressValidation) {
|
|
20246
|
-
resetAddressPreference({
|
|
20310
|
+
const updatedAddressPreference = resetAddressPreference({
|
|
20247
20311
|
validation: shipment.addressValidation
|
|
20248
20312
|
});
|
|
20313
|
+
onAddressValidation === null || onAddressValidation === void 0 ? void 0 : onAddressValidation(updatedAddressPreference);
|
|
20314
|
+
onChangeAddress === null || onChangeAddress === void 0 ? void 0 : onChangeAddress(updatedAddressPreference);
|
|
20249
20315
|
}
|
|
20250
20316
|
|
|
20251
20317
|
if (options.shouldCalculateRates) {
|
|
@@ -20257,7 +20323,8 @@ const SalesOrder = ({
|
|
|
20257
20323
|
packageTypes: hasCustomPackage(shipment) ? ["package"] // Only specify package types for non-custom packages
|
|
20258
20324
|
: shipment.packages.map(pkg => pkg.packageCode)
|
|
20259
20325
|
}
|
|
20260
|
-
});
|
|
20326
|
+
});
|
|
20327
|
+
result && (onRatesReturned === null || onRatesReturned === void 0 ? void 0 : onRatesReturned(result.rates, shipment)); // We are hiding, from the user, any errors in the rate response if the response
|
|
20261
20328
|
// contains rates. Log to the console any rate errors if the response has rates.
|
|
20262
20329
|
|
|
20263
20330
|
if ((result === null || result === void 0 ? void 0 : result.errors.length) && result.rates.length) {
|
|
@@ -20266,13 +20333,10 @@ const SalesOrder = ({
|
|
|
20266
20333
|
}, `Rate response had errors`);
|
|
20267
20334
|
}
|
|
20268
20335
|
}
|
|
20269
|
-
}), [calculateRates, carriers.data, hasCustomPackage, logger, resetAddressPreference, shipments]);
|
|
20336
|
+
}), [calculateRates, carriers.data, hasCustomPackage, logger, onChangeAddress, onAddressValidation, onRatesReturned, resetAddressPreference, shipments]);
|
|
20270
20337
|
const handleShipmentDirty = useCallback(() => {
|
|
20271
20338
|
calculateRates.reset();
|
|
20272
20339
|
}, [calculateRates]);
|
|
20273
|
-
const handleLabelCreated = useCallback(label => __awaiter(void 0, void 0, void 0, function* () {
|
|
20274
|
-
if (label) onPurchase === null || onPurchase === void 0 ? void 0 : onPurchase(label);
|
|
20275
|
-
}), [onPurchase]);
|
|
20276
20340
|
if (salesOrders.isLoading) return jsx(Loader, {
|
|
20277
20341
|
message: t("loading.salesOrder")
|
|
20278
20342
|
});
|
|
@@ -20300,15 +20364,20 @@ const SalesOrder = ({
|
|
|
20300
20364
|
}, {
|
|
20301
20365
|
children: [jsx(ShipmentForm, {
|
|
20302
20366
|
addressPreference: addressPreference,
|
|
20367
|
+
onChangeAddress: onChangeAddress,
|
|
20368
|
+
onChangeShipmentFormMode: onChangeShipmentFormMode,
|
|
20303
20369
|
onShipmentDirty: handleShipmentDirty,
|
|
20304
20370
|
onShipmentUpdated: handleShipmentUpdated,
|
|
20371
|
+
onToggleAddressPreferenceDisclosure: onToggleAddressPreferenceDisclosure,
|
|
20305
20372
|
salesOrder: salesOrder,
|
|
20306
|
-
shipment: shipment
|
|
20373
|
+
shipment: shipment,
|
|
20374
|
+
shippingPresets: shippingPresets
|
|
20307
20375
|
}), jsx(RateForm, {
|
|
20308
20376
|
errors: [...((_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 : [])],
|
|
20309
20377
|
loading: calculateRates.isMutating,
|
|
20310
|
-
|
|
20311
|
-
|
|
20378
|
+
onLabelCreateFailure: onLabelCreateFailure,
|
|
20379
|
+
onLabelCreateSuccess: onLabelCreateSuccess,
|
|
20380
|
+
onRateSaved: onRateSaved,
|
|
20312
20381
|
rates: (_e = calculateRates.data) === null || _e === void 0 ? void 0 : _e.rates,
|
|
20313
20382
|
shipment: shipment
|
|
20314
20383
|
})]
|
|
@@ -20318,9 +20387,10 @@ const SalesOrder = ({
|
|
|
20318
20387
|
const Element$2 = registerElement("purchase-label", SalesOrder);
|
|
20319
20388
|
|
|
20320
20389
|
const Shipment = ({
|
|
20321
|
-
|
|
20390
|
+
onClickPrintLabel,
|
|
20391
|
+
onClickPurchaseLabel,
|
|
20322
20392
|
onClickVoidLabel,
|
|
20323
|
-
|
|
20393
|
+
shipmentId
|
|
20324
20394
|
}) => {
|
|
20325
20395
|
var _a, _b, _c;
|
|
20326
20396
|
|
|
@@ -20353,6 +20423,7 @@ const Shipment = ({
|
|
|
20353
20423
|
carriers: carriers.data,
|
|
20354
20424
|
labels: labels.data,
|
|
20355
20425
|
onClickPurchaseLabel: onClickPurchaseLabel,
|
|
20426
|
+
onClickPrintLabel: onClickPrintLabel,
|
|
20356
20427
|
onClickVoidLabel: onClickVoidLabel,
|
|
20357
20428
|
salesOrder: salesOrder,
|
|
20358
20429
|
shipment: shipment.data,
|
package/package.json
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipengine/elements",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"module": "./index.js",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"
|
|
10
|
-
"@shipengine/elements-
|
|
11
|
-
"react": "^18.
|
|
9
|
+
"react": "^18.2.0",
|
|
10
|
+
"@shipengine/elements-core": "0.5.0",
|
|
11
|
+
"react-i18next": "^11.18.4",
|
|
12
|
+
"i18next": "^21.9.1",
|
|
13
|
+
"i18next-http-backend": "^1.4.1",
|
|
14
|
+
"i18next-browser-languagedetector": "^6.1.4",
|
|
15
|
+
"@shipengine/elements-ui": "0.5.0"
|
|
12
16
|
},
|
|
13
17
|
"peerDependencies": {}
|
|
14
18
|
}
|