From 61a989a0610d047fe5f20a6784b2a842ae3e925a Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Fri, 10 Apr 2020 13:03:36 +0200 Subject: [PATCH] Fix types --- .../ProductVariantCreatorContent.tsx | 85 +++++++++++-------- .../ProductVariantCreatorPage.tsx | 4 +- .../ProductVariantCreatorPage/reducer.test.ts | 6 +- .../ProductVariantCreatorPage/reducer.ts | 4 +- 4 files changed, 59 insertions(+), 40 deletions(-) diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx index 536a6c46f..4e6d935a6 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx @@ -50,9 +50,11 @@ const ProductVariantCreatorContent: React.FC 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 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 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} diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx index d30f767ae..28817c83e 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx @@ -130,7 +130,9 @@ const ProductVariantCreatePage: React.FC = props ); const reloadForm = () => dispatchFormDataAction({ - data: createInitialForm(attributes, defaultPrice, warehouses), + reload: { + data: createInitialForm(attributes, defaultPrice, warehouses) + }, type: ProductVariantCreateReducerActionType.reload }); diff --git a/src/products/components/ProductVariantCreatorPage/reducer.test.ts b/src/products/components/ProductVariantCreatorPage/reducer.test.ts index b7cfca23b..1d9059117 100644 --- a/src/products/components/ProductVariantCreatorPage/reducer.test.ts +++ b/src/products/components/ProductVariantCreatorPage/reducer.test.ts @@ -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(); }); diff --git a/src/products/components/ProductVariantCreatorPage/reducer.ts b/src/products/components/ProductVariantCreatorPage/reducer.ts index ebc4ba734..ec2c26a33 100644 --- a/src/products/components/ProductVariantCreatorPage/reducer.ts +++ b/src/products/components/ProductVariantCreatorPage/reducer.ts @@ -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(