@shipengine/elements 0.10.0 → 0.10.2
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.
|
@@ -9,6 +9,6 @@ export type UseAddressProps = {
|
|
|
9
9
|
export declare const useAddress: ({ onChange, onValidation, salesOrder, shipment }: UseAddressProps) => {
|
|
10
10
|
addressErrors: SE.CodedError[] | undefined;
|
|
11
11
|
addressPreference: Templates.AddressPreference | undefined;
|
|
12
|
-
handleChangeAddress: (shipTo: SE.Address, { shouldValidate }: Templates.OnChangeAddressOptions) => Promise<
|
|
12
|
+
handleChangeAddress: (shipTo: SE.Address, { shouldValidate }: Templates.OnChangeAddressOptions) => Promise<SE.SalesOrderShipment | undefined>;
|
|
13
13
|
handleParseShipTo: ({ fullAddress }: Templates.AddressParserPayload) => Promise<SE.AddressParseResponse | undefined>;
|
|
14
14
|
};
|
|
@@ -13,11 +13,13 @@ export type UseRatesFormProps = {
|
|
|
13
13
|
export declare const useRatesForm: ({ onBeforeLabelCreate, onLabelCreateFailure, onLabelCreateSuccess, onRateSaved, onRatesCalculated, onShipmentUpdated, printLabelLayout, shipment, }: UseRatesFormProps) => {
|
|
14
14
|
carriers: SE.Carrier[] | undefined;
|
|
15
15
|
errors: SE.CodedError[] | undefined;
|
|
16
|
+
labelErrors: SE.CodedError[] | undefined;
|
|
16
17
|
isLoading: boolean;
|
|
17
18
|
onSave: ({ carrierId, serviceCode }: Pick<SE.Rate, "carrierId" | "serviceCode">) => Promise<void>;
|
|
18
19
|
onSubmit: (rateId: string) => Promise<void>;
|
|
19
20
|
rates: SE.Rate[] | undefined;
|
|
20
21
|
requestRates: (shipment: SE.SalesOrderShipment) => Promise<void>;
|
|
22
|
+
resetLabel: () => void;
|
|
21
23
|
resetRates: () => void;
|
|
22
24
|
shipment: SE.SalesOrderShipment | undefined;
|
|
23
25
|
};
|
|
@@ -17,7 +17,7 @@ export declare const useShipmentForm: ({ onAddressValidation, onApplyPreset, onC
|
|
|
17
17
|
customPackageTypes: SE.Package[] | undefined;
|
|
18
18
|
errors: SE.CodedError[] | undefined;
|
|
19
19
|
onApplyPreset: (preset: ShippingPreset) => Promise<void>;
|
|
20
|
-
onChangeAddress: (shipTo: SE.Address, { shouldValidate }: import("dist/elements-ui/components/templates").OnChangeAddressOptions) => Promise<
|
|
20
|
+
onChangeAddress: (shipTo: SE.Address, { shouldValidate }: import("dist/elements-ui/components/templates").OnChangeAddressOptions) => Promise<SE.SalesOrderShipment | undefined>;
|
|
21
21
|
onSubmit: (values: Partial<SE.SalesOrderShipment>) => Promise<SE.SalesOrderShipment | undefined>;
|
|
22
22
|
onSubmitParseShipTo: ({ fullAddress }: {
|
|
23
23
|
fullAddress: string;
|
package/index.cjs
CHANGED
|
@@ -18962,7 +18962,7 @@ const useAddress = ({
|
|
|
18962
18962
|
shouldValidate
|
|
18963
18963
|
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18964
18964
|
if (!shipment) return;
|
|
18965
|
-
yield updateShipment(Object.assign(Object.assign({}, shipment), {
|
|
18965
|
+
const updatedShipment = yield updateShipment(Object.assign(Object.assign({}, shipment), {
|
|
18966
18966
|
shipTo
|
|
18967
18967
|
}));
|
|
18968
18968
|
yield onChange === null || onChange === void 0 ? void 0 : onChange(shipment, Object.assign(Object.assign({}, shipment), {
|
|
@@ -18971,6 +18971,7 @@ const useAddress = ({
|
|
|
18971
18971
|
if (shouldValidate) {
|
|
18972
18972
|
yield handleValidateAddress(shipTo);
|
|
18973
18973
|
}
|
|
18974
|
+
return updatedShipment;
|
|
18974
18975
|
}), [handleValidateAddress, onChange, shipment, updateShipment]);
|
|
18975
18976
|
react.useEffect(() => {
|
|
18976
18977
|
if (!addressPreference && (shipment === null || shipment === void 0 ? void 0 : shipment.shipTo)) {
|
|
@@ -19339,6 +19340,8 @@ const useRatesForm = ({
|
|
|
19339
19340
|
shipmentId: shipment === null || shipment === void 0 ? void 0 : shipment.shipmentId
|
|
19340
19341
|
});
|
|
19341
19342
|
const {
|
|
19343
|
+
errors: labelErrors,
|
|
19344
|
+
reset: resetLabel,
|
|
19342
19345
|
trigger: createLabel
|
|
19343
19346
|
} = elementsCore.useCreateLabel(printLabelLayout);
|
|
19344
19347
|
const {
|
|
@@ -19389,10 +19392,11 @@ const useRatesForm = ({
|
|
|
19389
19392
|
serviceCode
|
|
19390
19393
|
}));
|
|
19391
19394
|
if (updatedShipment) {
|
|
19395
|
+
yield requestRates(updatedShipment);
|
|
19392
19396
|
yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(updatedShipment);
|
|
19393
19397
|
yield onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
|
|
19394
19398
|
}
|
|
19395
|
-
}), [onRateSaved, onShipmentUpdated, shipment, updateShipment]);
|
|
19399
|
+
}), [onRateSaved, onShipmentUpdated, requestRates, shipment, updateShipment]);
|
|
19396
19400
|
let errors = [...(ratesErrors !== null && ratesErrors !== void 0 ? ratesErrors : []), ...((_a = ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.errors) !== null && _a !== void 0 ? _a : [])];
|
|
19397
19401
|
if (beforeCreateError) errors = [...errors, beforeCreateError];
|
|
19398
19402
|
// Sometimes no rates are returned and no top-level errors are returned
|
|
@@ -19409,11 +19413,13 @@ const useRatesForm = ({
|
|
|
19409
19413
|
return {
|
|
19410
19414
|
carriers,
|
|
19411
19415
|
errors: errors.length > 0 ? errors : undefined,
|
|
19416
|
+
labelErrors: (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) ? labelErrors : undefined,
|
|
19412
19417
|
isLoading: ratesCalculating,
|
|
19413
19418
|
onSave: handleSave,
|
|
19414
19419
|
onSubmit: handleSubmit,
|
|
19415
19420
|
rates: ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates,
|
|
19416
19421
|
requestRates,
|
|
19422
|
+
resetLabel,
|
|
19417
19423
|
resetRates,
|
|
19418
19424
|
shipment
|
|
19419
19425
|
};
|
|
@@ -19516,21 +19522,27 @@ const ConfigureShipment = _a => {
|
|
|
19516
19522
|
shipment
|
|
19517
19523
|
} = _a,
|
|
19518
19524
|
props = __rest(_a, ["features", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "salesOrder", "shipment"]);
|
|
19525
|
+
const hydrateRef = react.useRef();
|
|
19519
19526
|
const _b = useRatesForm({
|
|
19520
19527
|
onBeforeLabelCreate,
|
|
19521
19528
|
onLabelCreateFailure,
|
|
19522
19529
|
onLabelCreateSuccess,
|
|
19523
|
-
onRateSaved
|
|
19530
|
+
onRateSaved: updatedShipment => {
|
|
19531
|
+
var _a;
|
|
19532
|
+
(_a = hydrateRef.current) === null || _a === void 0 ? void 0 : _a.call(hydrateRef, updatedShipment);
|
|
19533
|
+
onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
|
|
19534
|
+
},
|
|
19524
19535
|
onRatesCalculated,
|
|
19525
19536
|
onShipmentUpdated,
|
|
19526
19537
|
printLabelLayout,
|
|
19527
19538
|
shipment
|
|
19528
19539
|
}),
|
|
19529
19540
|
{
|
|
19541
|
+
requestRates,
|
|
19530
19542
|
resetRates,
|
|
19531
|
-
|
|
19543
|
+
resetLabel
|
|
19532
19544
|
} = _b,
|
|
19533
|
-
rateFormProps = __rest(_b, ["resetRates", "
|
|
19545
|
+
rateFormProps = __rest(_b, ["requestRates", "resetRates", "resetLabel"]);
|
|
19534
19546
|
const shipmentFormProps = useShipmentForm({
|
|
19535
19547
|
onAddressValidation,
|
|
19536
19548
|
onApplyPreset: react.useCallback((_preset, shipment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -19554,14 +19566,20 @@ const ConfigureShipment = _a => {
|
|
|
19554
19566
|
setRateFormDisabled(false);
|
|
19555
19567
|
}
|
|
19556
19568
|
}, []);
|
|
19569
|
+
const handleOnDirty = react.useCallback(() => {
|
|
19570
|
+
resetRates();
|
|
19571
|
+
resetLabel();
|
|
19572
|
+
}, [resetRates, resetLabel]);
|
|
19557
19573
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
19558
19574
|
children: [jsxRuntime.jsx(elementsUi.Templates.ShipmentForm, Object.assign({}, shipmentFormProps, props, {
|
|
19559
|
-
|
|
19575
|
+
hydrateRef: hydrateRef,
|
|
19576
|
+
onDirty: handleOnDirty,
|
|
19560
19577
|
onCharsetWarning: handleCharsetWarning,
|
|
19561
19578
|
features: features === null || features === void 0 ? void 0 : features.shipmentForm
|
|
19562
19579
|
})), jsxRuntime.jsx(elementsUi.Templates.RateForm, Object.assign({}, rateFormProps, {
|
|
19563
19580
|
disabled: rateFormDisabled,
|
|
19564
|
-
features: features === null || features === void 0 ? void 0 : features.rateForm
|
|
19581
|
+
features: features === null || features === void 0 ? void 0 : features.rateForm,
|
|
19582
|
+
onSelectRate: resetLabel
|
|
19565
19583
|
}))]
|
|
19566
19584
|
});
|
|
19567
19585
|
};
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useValidateAddresses, useUpdateShipment, useParseAddress, isDomesticAddress, useListCarriers, useListCustomPackageTypes, useCalculateRates, useCreateLabel, useListWarehouses, useListShipments, useCreateShipment, getPendingShipment, getIsCustomsRequiredForSalesOrder, getCustomsFromSalesOrder, useListSalesOrders, useListOrderSources, useRefreshOrderSource, registerElement, useGetShipment, useListLabels, useGetLabel, useVoidLabel } from '@shipengine/elements-core';
|
|
2
2
|
import { jsxs, Fragment, jsx } from '@emotion/react/jsx-runtime';
|
|
3
3
|
import { Templates, Loader } from '@shipengine/elements-ui';
|
|
4
|
-
import { useState, useCallback, useEffect } from 'react';
|
|
4
|
+
import { useState, useCallback, useEffect, useRef } from 'react';
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
|
|
7
7
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
@@ -18958,7 +18958,7 @@ const useAddress = ({
|
|
|
18958
18958
|
shouldValidate
|
|
18959
18959
|
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18960
18960
|
if (!shipment) return;
|
|
18961
|
-
yield updateShipment(Object.assign(Object.assign({}, shipment), {
|
|
18961
|
+
const updatedShipment = yield updateShipment(Object.assign(Object.assign({}, shipment), {
|
|
18962
18962
|
shipTo
|
|
18963
18963
|
}));
|
|
18964
18964
|
yield onChange === null || onChange === void 0 ? void 0 : onChange(shipment, Object.assign(Object.assign({}, shipment), {
|
|
@@ -18967,6 +18967,7 @@ const useAddress = ({
|
|
|
18967
18967
|
if (shouldValidate) {
|
|
18968
18968
|
yield handleValidateAddress(shipTo);
|
|
18969
18969
|
}
|
|
18970
|
+
return updatedShipment;
|
|
18970
18971
|
}), [handleValidateAddress, onChange, shipment, updateShipment]);
|
|
18971
18972
|
useEffect(() => {
|
|
18972
18973
|
if (!addressPreference && (shipment === null || shipment === void 0 ? void 0 : shipment.shipTo)) {
|
|
@@ -19335,6 +19336,8 @@ const useRatesForm = ({
|
|
|
19335
19336
|
shipmentId: shipment === null || shipment === void 0 ? void 0 : shipment.shipmentId
|
|
19336
19337
|
});
|
|
19337
19338
|
const {
|
|
19339
|
+
errors: labelErrors,
|
|
19340
|
+
reset: resetLabel,
|
|
19338
19341
|
trigger: createLabel
|
|
19339
19342
|
} = useCreateLabel(printLabelLayout);
|
|
19340
19343
|
const {
|
|
@@ -19385,10 +19388,11 @@ const useRatesForm = ({
|
|
|
19385
19388
|
serviceCode
|
|
19386
19389
|
}));
|
|
19387
19390
|
if (updatedShipment) {
|
|
19391
|
+
yield requestRates(updatedShipment);
|
|
19388
19392
|
yield onShipmentUpdated === null || onShipmentUpdated === void 0 ? void 0 : onShipmentUpdated(updatedShipment);
|
|
19389
19393
|
yield onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
|
|
19390
19394
|
}
|
|
19391
|
-
}), [onRateSaved, onShipmentUpdated, shipment, updateShipment]);
|
|
19395
|
+
}), [onRateSaved, onShipmentUpdated, requestRates, shipment, updateShipment]);
|
|
19392
19396
|
let errors = [...(ratesErrors !== null && ratesErrors !== void 0 ? ratesErrors : []), ...((_a = ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.errors) !== null && _a !== void 0 ? _a : [])];
|
|
19393
19397
|
if (beforeCreateError) errors = [...errors, beforeCreateError];
|
|
19394
19398
|
// Sometimes no rates are returned and no top-level errors are returned
|
|
@@ -19405,11 +19409,13 @@ const useRatesForm = ({
|
|
|
19405
19409
|
return {
|
|
19406
19410
|
carriers,
|
|
19407
19411
|
errors: errors.length > 0 ? errors : undefined,
|
|
19412
|
+
labelErrors: (labelErrors === null || labelErrors === void 0 ? void 0 : labelErrors.length) ? labelErrors : undefined,
|
|
19408
19413
|
isLoading: ratesCalculating,
|
|
19409
19414
|
onSave: handleSave,
|
|
19410
19415
|
onSubmit: handleSubmit,
|
|
19411
19416
|
rates: ratesResponse === null || ratesResponse === void 0 ? void 0 : ratesResponse.rates,
|
|
19412
19417
|
requestRates,
|
|
19418
|
+
resetLabel,
|
|
19413
19419
|
resetRates,
|
|
19414
19420
|
shipment
|
|
19415
19421
|
};
|
|
@@ -19512,21 +19518,27 @@ const ConfigureShipment = _a => {
|
|
|
19512
19518
|
shipment
|
|
19513
19519
|
} = _a,
|
|
19514
19520
|
props = __rest(_a, ["features", "onAddressValidation", "onApplyPreset", "onBeforeLabelCreate", "onChangeAddress", "onLabelCreateFailure", "onLabelCreateSuccess", "onRateSaved", "onRatesCalculated", "onShipmentUpdated", "printLabelLayout", "salesOrder", "shipment"]);
|
|
19521
|
+
const hydrateRef = useRef();
|
|
19515
19522
|
const _b = useRatesForm({
|
|
19516
19523
|
onBeforeLabelCreate,
|
|
19517
19524
|
onLabelCreateFailure,
|
|
19518
19525
|
onLabelCreateSuccess,
|
|
19519
|
-
onRateSaved
|
|
19526
|
+
onRateSaved: updatedShipment => {
|
|
19527
|
+
var _a;
|
|
19528
|
+
(_a = hydrateRef.current) === null || _a === void 0 ? void 0 : _a.call(hydrateRef, updatedShipment);
|
|
19529
|
+
onRateSaved === null || onRateSaved === void 0 ? void 0 : onRateSaved(updatedShipment);
|
|
19530
|
+
},
|
|
19520
19531
|
onRatesCalculated,
|
|
19521
19532
|
onShipmentUpdated,
|
|
19522
19533
|
printLabelLayout,
|
|
19523
19534
|
shipment
|
|
19524
19535
|
}),
|
|
19525
19536
|
{
|
|
19537
|
+
requestRates,
|
|
19526
19538
|
resetRates,
|
|
19527
|
-
|
|
19539
|
+
resetLabel
|
|
19528
19540
|
} = _b,
|
|
19529
|
-
rateFormProps = __rest(_b, ["resetRates", "
|
|
19541
|
+
rateFormProps = __rest(_b, ["requestRates", "resetRates", "resetLabel"]);
|
|
19530
19542
|
const shipmentFormProps = useShipmentForm({
|
|
19531
19543
|
onAddressValidation,
|
|
19532
19544
|
onApplyPreset: useCallback((_preset, shipment) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -19550,14 +19562,20 @@ const ConfigureShipment = _a => {
|
|
|
19550
19562
|
setRateFormDisabled(false);
|
|
19551
19563
|
}
|
|
19552
19564
|
}, []);
|
|
19565
|
+
const handleOnDirty = useCallback(() => {
|
|
19566
|
+
resetRates();
|
|
19567
|
+
resetLabel();
|
|
19568
|
+
}, [resetRates, resetLabel]);
|
|
19553
19569
|
return jsxs(Fragment, {
|
|
19554
19570
|
children: [jsx(Templates.ShipmentForm, Object.assign({}, shipmentFormProps, props, {
|
|
19555
|
-
|
|
19571
|
+
hydrateRef: hydrateRef,
|
|
19572
|
+
onDirty: handleOnDirty,
|
|
19556
19573
|
onCharsetWarning: handleCharsetWarning,
|
|
19557
19574
|
features: features === null || features === void 0 ? void 0 : features.shipmentForm
|
|
19558
19575
|
})), jsx(Templates.RateForm, Object.assign({}, rateFormProps, {
|
|
19559
19576
|
disabled: rateFormDisabled,
|
|
19560
|
-
features: features === null || features === void 0 ? void 0 : features.rateForm
|
|
19577
|
+
features: features === null || features === void 0 ? void 0 : features.rateForm,
|
|
19578
|
+
onSelectRate: resetLabel
|
|
19561
19579
|
}))]
|
|
19562
19580
|
});
|
|
19563
19581
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shipengine/elements",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@packlink/giger": "*",
|
|
6
6
|
"react-i18next": "*",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"types": "./index.d.ts",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"react": "^18.2.0",
|
|
15
|
-
"@shipengine/elements-core": "0.10.
|
|
16
|
-
"@shipengine/elements-ui": "0.10.
|
|
17
|
-
"@shipengine/types": "0.10.
|
|
15
|
+
"@shipengine/elements-core": "0.10.2",
|
|
16
|
+
"@shipengine/elements-ui": "0.10.2",
|
|
17
|
+
"@shipengine/types": "0.10.2",
|
|
18
18
|
"@emotion/react": "^11.10.0",
|
|
19
19
|
"@packlink/brands": "^3.18.0"
|
|
20
20
|
}
|