Fix types

This commit is contained in:
dominik-zeglen 2020-04-10 13:03:36 +02:00
parent cd7426c7a9
commit 61a989a061
4 changed files with 59 additions and 40 deletions

View file

@ -50,9 +50,11 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
data={data}
onValueClick={(attributeId, valueId) =>
dispatchFormDataAction({
selectValue: {
attributeId,
type: ProductVariantCreateReducerActionType.selectValue,
valueId
},
type: ProductVariantCreateReducerActionType.selectValue
})
}
/>
@ -64,40 +66,50 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
data={data}
onApplyPriceOrStockChange={(all, type) =>
dispatchFormDataAction({
all,
applyPriceOrStockToAll: {
all
},
type:
type === "price"
? ProductVariantCreateReducerActionType.applyPriceToAll
: ProductVariantCreateReducerActionType.applyStockToAll
})
}
onApplyToAllChange={(value, type) =>
dispatchFormDataAction({
// Stock change is not fixed in this PR so we wo't include it here
onApplyToAllChange={(price, type) =>
dispatchFormDataAction(
type === "price" && {
changeApplyPriceToAllValue: {
price
},
type:
type === "price"
? ProductVariantCreateReducerActionType.changeApplyPriceToAllValue
: ProductVariantCreateReducerActionType.changeApplyStockToAllValue,
value
})
ProductVariantCreateReducerActionType.changeApplyPriceToAllValue
}
)
}
onAttributeSelect={(attributeId, type) =>
dispatchFormDataAction({
attributeId,
changeApplyPriceOrStockToAttributeId: {
attributeId
},
type:
type === "price"
? ProductVariantCreateReducerActionType.changeApplyPriceToAttributeId
: ProductVariantCreateReducerActionType.changeApplyStockToAttributeId
})
}
onAttributeValueChange={(valueId, value, type) =>
dispatchFormDataAction({
type:
type === "price"
? ProductVariantCreateReducerActionType.changeAttributeValuePrice
: ProductVariantCreateReducerActionType.changeAttributeValueStock,
value,
// Stock change is not fixed in this PR so we wo't include it here
onAttributeValueChange={(valueId, price, type) =>
dispatchFormDataAction(
type === "price" && {
changeAttributeValuePrice: {
price,
valueId
})
},
type:
ProductVariantCreateReducerActionType.changeAttributeValuePrice
}
)
}
/>
)}
@ -109,27 +121,32 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
errors={errors}
onVariantDataChange={(variantIndex, field, value) =>
dispatchFormDataAction({
changeVariantData: {
field,
type: ProductVariantCreateReducerActionType.changeVariantData,
value,
variantIndex
},
type: ProductVariantCreateReducerActionType.changeVariantData
})
}
onVariantStockDataChange={(variantIndex, warehouse, value) =>
dispatchFormDataAction({
changeVariantStockData: {
stock: {
quantity: parseInt(value, 10),
warehouse
},
type:
ProductVariantCreateReducerActionType.changeVariantStockData,
variantIndex
},
type: ProductVariantCreateReducerActionType.changeVariantStockData
})
}
onVariantDelete={variantIndex =>
dispatchFormDataAction({
type: ProductVariantCreateReducerActionType.deleteVariant,
deleteVariant: {
variantIndex
},
type: ProductVariantCreateReducerActionType.deleteVariant
})
}
warehouses={warehouses}

View file

@ -130,7 +130,9 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = props
);
const reloadForm = () =>
dispatchFormDataAction({
data: createInitialForm(attributes, defaultPrice, warehouses),
reload: {
data: createInitialForm(attributes, defaultPrice, warehouses)
},
type: ProductVariantCreateReducerActionType.reload
});

View file

@ -73,7 +73,7 @@ describe("Reducer is able to", () => {
});
it("select price for all variants", () => {
const value = "45.99";
const price = "45.99";
const state = execActions(thirdStep, reducer, [
{
applyPriceOrStockToAll: {
@ -83,7 +83,7 @@ describe("Reducer is able to", () => {
},
{
changeApplyPriceToAllValue: {
value
price
},
type: ProductVariantCreateReducerActionType.changeApplyPriceToAllValue
},
@ -93,7 +93,7 @@ describe("Reducer is able to", () => {
]);
expect(state.price.all).toBeTruthy();
expect(state.price.value).toBe(value);
expect(state.price.value).toBe(price);
expect(state).toMatchSnapshot();
});

View file

@ -31,7 +31,7 @@ export interface ProductVariantCreateReducerAction {
all: boolean;
};
changeApplyPriceToAllValue?: {
value: string;
price: string;
};
changeApplyPriceOrStockToAttributeId?: {
attributeId: string;
@ -378,7 +378,7 @@ function reduceProductVariantCreateFormData(
case ProductVariantCreateReducerActionType.changeApplyPriceToAllValue:
return changeApplyPriceToAllValue(
prevState,
action.changeApplyPriceToAllValue.value
action.changeApplyPriceToAllValue.price
);
case ProductVariantCreateReducerActionType.changeApplyStockToAllValue:
return changeApplyStockToAllValue(