Fix updating shipping rates (#565)

This commit is contained in:
natalia 2020-06-25 10:18:46 +03:00 committed by GitHub
parent 2a6334cb74
commit 4468857856
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View file

@ -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;

View file

@ -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
}
};
}