Fix updating shipping rates (#565)
This commit is contained in:
parent
2a6334cb74
commit
4468857856
2 changed files with 16 additions and 5 deletions
|
@ -37,6 +37,7 @@ export interface FormData {
|
||||||
maxValue: string;
|
maxValue: string;
|
||||||
isFree: boolean;
|
isFree: boolean;
|
||||||
price: string;
|
price: string;
|
||||||
|
type: ShippingMethodTypeEnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShippingZoneRateDialogProps {
|
export interface ShippingZoneRateDialogProps {
|
||||||
|
@ -104,7 +105,8 @@ const ShippingZoneRateDialog: React.FC<ShippingZoneRateDialogProps> = props => {
|
||||||
minValue: "",
|
minValue: "",
|
||||||
name: "",
|
name: "",
|
||||||
noLimits: false,
|
noLimits: false,
|
||||||
price: ""
|
price: "",
|
||||||
|
type: null
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
isFree: maybe(() => rate.price.amount === 0, false),
|
isFree: maybe(() => rate.price.amount === 0, false),
|
||||||
|
@ -118,7 +120,8 @@ const ShippingZoneRateDialog: React.FC<ShippingZoneRateDialogProps> = props => {
|
||||||
: maybe(() => rate.minimumOrderWeight.value.toString(), ""),
|
: maybe(() => rate.minimumOrderWeight.value.toString(), ""),
|
||||||
name: maybe(() => rate.name, ""),
|
name: maybe(() => rate.name, ""),
|
||||||
noLimits: false,
|
noLimits: false,
|
||||||
price: maybe(() => rate.price.amount.toString(), "")
|
price: maybe(() => rate.price.amount.toString(), ""),
|
||||||
|
type: variant
|
||||||
};
|
};
|
||||||
if (action === "edit") {
|
if (action === "edit") {
|
||||||
initialForm.noLimits = !initialForm.maxValue && !initialForm.minValue;
|
initialForm.noLimits = !initialForm.maxValue && !initialForm.minValue;
|
||||||
|
|
|
@ -50,14 +50,22 @@ export function getUpdateShippingRateVariables(
|
||||||
params: ShippingZoneUrlQueryParams,
|
params: ShippingZoneUrlQueryParams,
|
||||||
id: string
|
id: string
|
||||||
): UpdateShippingRateVariables {
|
): UpdateShippingRateVariables {
|
||||||
|
const isPriceType = data.type === ShippingMethodTypeEnum.PRICE
|
||||||
|
const parsedMinValue = parseFloat(data.minValue)
|
||||||
|
const parsedMaxValue = parseFloat(data.maxValue)
|
||||||
|
const isPriceSet = !data.noLimits && isPriceType
|
||||||
|
const isWeightSet = !data.noLimits && !isPriceType
|
||||||
return {
|
return {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
input: {
|
input: {
|
||||||
maximumOrderPrice: data.noLimits ? null : parseFloat(data.maxValue),
|
maximumOrderPrice: isPriceSet ? parsedMaxValue : null,
|
||||||
minimumOrderPrice: data.noLimits ? null : parseFloat(data.minValue),
|
maximumOrderWeight: isWeightSet ? parsedMaxValue : null,
|
||||||
|
minimumOrderPrice: isPriceSet ? parsedMinValue : null,
|
||||||
|
minimumOrderWeight: isWeightSet ? parsedMinValue : null,
|
||||||
name: data.name,
|
name: data.name,
|
||||||
price: data.isFree ? 0 : parseFloat(data.price),
|
price: data.isFree ? 0 : parseFloat(data.price),
|
||||||
shippingZone: id
|
shippingZone: id,
|
||||||
|
type: data.type
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue