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;
|
||||
isFree: boolean;
|
||||
price: string;
|
||||
type: ShippingMethodTypeEnum;
|
||||
}
|
||||
|
||||
export interface ShippingZoneRateDialogProps {
|
||||
|
@ -104,7 +105,8 @@ const ShippingZoneRateDialog: React.FC<ShippingZoneRateDialogProps> = props => {
|
|||
minValue: "",
|
||||
name: "",
|
||||
noLimits: false,
|
||||
price: ""
|
||||
price: "",
|
||||
type: null
|
||||
}
|
||||
: {
|
||||
isFree: maybe(() => rate.price.amount === 0, false),
|
||||
|
@ -118,7 +120,8 @@ const ShippingZoneRateDialog: React.FC<ShippingZoneRateDialogProps> = props => {
|
|||
: maybe(() => rate.minimumOrderWeight.value.toString(), ""),
|
||||
name: maybe(() => rate.name, ""),
|
||||
noLimits: false,
|
||||
price: maybe(() => rate.price.amount.toString(), "")
|
||||
price: maybe(() => rate.price.amount.toString(), ""),
|
||||
type: variant
|
||||
};
|
||||
if (action === "edit") {
|
||||
initialForm.noLimits = !initialForm.maxValue && !initialForm.minValue;
|
||||
|
|
|
@ -50,14 +50,22 @@ export function getUpdateShippingRateVariables(
|
|||
params: ShippingZoneUrlQueryParams,
|
||||
id: string
|
||||
): 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 {
|
||||
id: params.id,
|
||||
input: {
|
||||
maximumOrderPrice: data.noLimits ? null : parseFloat(data.maxValue),
|
||||
minimumOrderPrice: data.noLimits ? null : parseFloat(data.minValue),
|
||||
maximumOrderPrice: isPriceSet ? parsedMaxValue : null,
|
||||
maximumOrderWeight: isWeightSet ? parsedMaxValue : null,
|
||||
minimumOrderPrice: isPriceSet ? parsedMinValue : null,
|
||||
minimumOrderWeight: isWeightSet ? parsedMinValue : null,
|
||||
name: data.name,
|
||||
price: data.isFree ? 0 : parseFloat(data.price),
|
||||
shippingZone: id
|
||||
shippingZone: id,
|
||||
type: data.type
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue