Fix types
This commit is contained in:
parent
cd7426c7a9
commit
61a989a061
4 changed files with 59 additions and 40 deletions
|
@ -50,9 +50,11 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
|
|||
data={data}
|
||||
onValueClick={(attributeId, valueId) =>
|
||||
dispatchFormDataAction({
|
||||
attributeId,
|
||||
type: ProductVariantCreateReducerActionType.selectValue,
|
||||
valueId
|
||||
selectValue: {
|
||||
attributeId,
|
||||
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({
|
||||
type:
|
||||
type === "price"
|
||||
? ProductVariantCreateReducerActionType.changeApplyPriceToAllValue
|
||||
: ProductVariantCreateReducerActionType.changeApplyStockToAllValue,
|
||||
value
|
||||
})
|
||||
// Stock change is not fixed in this PR so we wo't include it here
|
||||
onApplyToAllChange={(price, type) =>
|
||||
dispatchFormDataAction(
|
||||
type === "price" && {
|
||||
changeApplyPriceToAllValue: {
|
||||
price
|
||||
},
|
||||
type:
|
||||
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,
|
||||
valueId
|
||||
})
|
||||
// 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({
|
||||
field,
|
||||
type: ProductVariantCreateReducerActionType.changeVariantData,
|
||||
value,
|
||||
variantIndex
|
||||
changeVariantData: {
|
||||
field,
|
||||
value,
|
||||
variantIndex
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.changeVariantData
|
||||
})
|
||||
}
|
||||
onVariantStockDataChange={(variantIndex, warehouse, value) =>
|
||||
dispatchFormDataAction({
|
||||
stock: {
|
||||
quantity: parseInt(value, 10),
|
||||
warehouse
|
||||
changeVariantStockData: {
|
||||
stock: {
|
||||
quantity: parseInt(value, 10),
|
||||
warehouse
|
||||
},
|
||||
variantIndex
|
||||
},
|
||||
type:
|
||||
ProductVariantCreateReducerActionType.changeVariantStockData,
|
||||
variantIndex
|
||||
type: ProductVariantCreateReducerActionType.changeVariantStockData
|
||||
})
|
||||
}
|
||||
onVariantDelete={variantIndex =>
|
||||
dispatchFormDataAction({
|
||||
type: ProductVariantCreateReducerActionType.deleteVariant,
|
||||
variantIndex
|
||||
deleteVariant: {
|
||||
variantIndex
|
||||
},
|
||||
type: ProductVariantCreateReducerActionType.deleteVariant
|
||||
})
|
||||
}
|
||||
warehouses={warehouses}
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue