diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx index a59e42cec..cc8fa7bb7 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorContent.tsx @@ -24,16 +24,15 @@ export interface ProductVariantCreatorContentProps { warehouses: WarehouseFragment[]; } -const ProductVariantCreatorContent: React.FC = props => { - const { - attributes, - currencySymbol, - data, - dispatchFormDataAction, - errors, - step, - warehouses - } = props; +const ProductVariantCreatorContent: React.FC = ({ + attributes, + currencySymbol, + data, + dispatchFormDataAction, + errors, + step, + warehouses +}) => { const selectedAttributes = attributes.filter(attribute => isSelected( attribute.id, @@ -104,17 +103,26 @@ const ProductVariantCreatorContent: React.FC : ProductVariantCreateReducerActionType.changeApplyStockToAttributeId }) } - onAttributeValueChange={(valueId, price, type) => - dispatchFormDataAction( - type === "price" && { - changeAttributeValuePrice: { - price, - valueId - }, - type: - ProductVariantCreateReducerActionType.changeAttributeValuePrice - } - ) + onAttributePriceChange={(valueId, price) => + dispatchFormDataAction({ + changeAttributeValuePrice: { + price, + valueId + }, + type: + ProductVariantCreateReducerActionType.changeAttributeValuePrice + }) + } + onAttributeStockChange={(valueId, quantity, warehouseIndex) => + dispatchFormDataAction({ + changeAttributeValueStock: { + quantity, + valueId, + warehouseIndex + }, + type: + ProductVariantCreateReducerActionType.changeAttributeValueStock + }) } onWarehouseToggle={warehouseId => dispatchFormDataAction({ diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx index 89135c1af..1e95564e1 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPage.tsx @@ -50,11 +50,9 @@ function canHitNext( ) { return false; } - } else { - return true; } - if (data.stock.mode === "attribute" || data.stock.attribute) { + if (data.stock.mode === "attribute" && data.stock.attribute === "") { return false; } diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPriceAndSku.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPriceAndSku.tsx index a70bf1332..0d6829942 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPriceAndSku.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorPriceAndSku.tsx @@ -23,10 +23,11 @@ export interface ProductVariantCreatorPriceAndSkuProps { onApplyToAllPriceChange: (value: string) => void; onApplyToAllStockChange: (warehouseIndex: number, value: string) => void; onAttributeSelect: (id: string, type: PriceOrStock) => void; - onAttributeValueChange: ( + onAttributePriceChange: (id: string, value: string) => void; + onAttributeStockChange: ( id: string, - value: string, - type: PriceOrStock + quantity: number, + warehouseIndex: number ) => void; onWarehouseToggle: (id: string) => void; } @@ -40,7 +41,8 @@ const ProductVariantCreatorPriceAndSku: React.FC ( <> @@ -51,9 +53,7 @@ const ProductVariantCreatorPriceAndSku: React.FC onApplyToAllChange(value, "price")} onApplyToAllPriceChange={onApplyToAllPriceChange} onAttributeSelect={id => onAttributeSelect(id, "price")} - onAttributeValueChange={(id, value) => - onAttributeValueChange(id, value, "price") - } + onAttributeValueChange={onAttributePriceChange} /> onApplyToAllChange(value, "stock")} onApplyToAllStockChange={onApplyToAllStockChange} onAttributeSelect={id => onAttributeSelect(id, "stock")} - onAttributeValueChange={(id, value) => - onAttributeValueChange(id, value, "stock") - } + onAttributeValueChange={onAttributeStockChange} onWarehouseToggle={onWarehouseToggle} /> diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx index 1c9768f39..6606c2e69 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorStock.tsx @@ -27,6 +27,17 @@ import { getStockAttributeValues } from "./utils"; const useStyles = makeStyles( theme => ({ + attributeStockContainer: { + columnGap: theme.spacing(3) + "px", + display: "grid", + gridTemplateColumns: ({ data }: ProductVariantCreatorStockProps) => + `150px repeat(${data.warehouses.length}, 288px)`, + rowGap: theme.spacing(2) + "px" + }, + attributeStockScroll: { + overflowX: "scroll", + width: "100%" + }, hr: { marginBottom: theme.spacing(), marginTop: theme.spacing(0.5) @@ -75,7 +86,11 @@ export interface ProductVariantCreatorStockProps { onApplyToAllChange: (mode: VariantCreatorPricesAndSkuMode) => void; onApplyToAllStockChange: (warehouseIndex: number, value: string) => void; onAttributeSelect: (id: string) => void; - onAttributeValueChange: (id: string, value: string) => void; + onAttributeValueChange: ( + id: string, + quantity: number, + warehouseIndex: number + ) => void; onWarehouseToggle: (id: string) => void; } @@ -168,11 +183,8 @@ const ProductVariantCreatorStock: React.FC = pr {data.stock.mode === "all" && (
{data.warehouses.map((warehouseId, warehouseIndex) => ( -
- +
+ { warehouses.find(warehouse => warehouse.id === warehouseId) .name @@ -212,60 +224,74 @@ const ProductVariantCreatorStock: React.FC = pr {data.stock.mode === "attribute" && ( <> - -
- - - -
-
- -
-
- {stockAttributeValues && - stockAttributeValues.map(attributeValue => ( - -
- - -
- {attributeValue.name} -
-
- value.slug === attributeValue.slug - ).value - } - onChange={event => - onAttributeValueChange( - attributeValue.slug, - event.target.value + onAttributeSelect(event.target.value)} + /> + {stockAttributeValues && ( + <> +
+ +
+
+
+ {data.stock.attribute && + data.warehouses.map(warehouseId => ( + + { + warehouses.find( + warehouse => warehouse.id === warehouseId + ).name + } + + ))} + {stockAttributeValues.map(attributeValue => ( + + {attributeValue.name} + {data.warehouses.map( + (warehouseId, warehouseIndex) => ( + value.slug === attributeValue.slug + ).value[warehouseIndex] + } + onChange={event => + onAttributeValueChange( + attributeValue.slug, + parseInt(event.target.value, 10), + warehouseIndex + ) + } + key={warehouseId} + /> ) - } - /> -
- - - ))} + )} + + ))} +
+
+ + )} )} diff --git a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorSummary.tsx b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorSummary.tsx index 46a5dd80f..620c7ea31 100644 --- a/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorSummary.tsx +++ b/src/products/components/ProductVariantCreatorPage/ProductVariantCreatorSummary.tsx @@ -92,7 +92,7 @@ const useStyles = makeStyles< marginTop: theme.spacing(0.5) }, hr: { - gridColumn: props => `span ${4 + props.data.stock.value.length}` + gridColumn: props => `span ${4 + props.data.variants[0].stocks.length}` }, input: { "& input": { @@ -103,7 +103,7 @@ const useStyles = makeStyles< columnGap: theme.spacing(3), display: "grid", gridTemplateColumns: props => - `minmax(240px, auto) 170px repeat(${props.data.stock.value.length}, 140px) 140px 64px`, + `minmax(240px, auto) 170px repeat(${props.data.variants[0].stocks.length}, 140px) 140px 64px`, overflowX: "scroll", rowGap: theme.spacing() + "px" } diff --git a/src/products/components/ProductVariantCreatorPage/reducer.ts b/src/products/components/ProductVariantCreatorPage/reducer.ts index 64e7b785a..93f2dbd16 100644 --- a/src/products/components/ProductVariantCreatorPage/reducer.ts +++ b/src/products/components/ProductVariantCreatorPage/reducer.ts @@ -186,8 +186,8 @@ function changeAttributeValuePrice( function changeAttributeValueStock( state: ProductVariantCreateFormData, attributeValueSlug: string, - warehouseIndex: number, - quantity: number + quantity: number, + warehouseIndex: number ): ProductVariantCreateFormData { const index = state.stock.values.findIndex( value => value.slug === attributeValueSlug @@ -199,8 +199,12 @@ function changeAttributeValueStock( const values = updateAtIndex( { - slug: attributeValueSlug, - value: updateAtIndex(quantity, state.stock.value, warehouseIndex) + ...state.stock.values[index], + value: updateAtIndex( + quantity, + state.stock.values[index].value, + warehouseIndex + ) }, state.stock.values, index