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

View file

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

View file

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

View file

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