Add multiple warehouse selection

This commit is contained in:
dominik-zeglen 2020-04-08 12:05:05 +02:00
parent 64371d04a6
commit b776321e0a
4 changed files with 25 additions and 18 deletions

View file

@ -73,7 +73,7 @@ const data: ProductVariantCreateFormData = {
warehouses: selectedWarehouses.map(warehouse => warehouse.id)
};
const props: ProductVariantCreatorContentProps = {
attributes,
attributes: [0, 1, 4, 6].map(index => attributes[index]),
currencySymbol: "USD",
data: {
...data,

View file

@ -76,15 +76,21 @@ const ProductVariantCreatorContent: React.FC<ProductVariantCreatorContentProps>
: ProductVariantCreateReducerActionType.applyStockToAll
})
}
onApplyToAllPriceOrStockChange={(value, type) =>
onApplyToAllPriceChange={price =>
dispatchFormDataAction({
changeApplyPriceToAllValue: {
price: value
price
},
type:
type === "price"
? ProductVariantCreateReducerActionType.applyPriceToAll
: ProductVariantCreateReducerActionType.applyStockToAll
type: ProductVariantCreateReducerActionType.applyPriceToAll
})
}
onApplyToAllStockChange={(warehouseIndex, quantity) =>
dispatchFormDataAction({
changeApplyStockToAllValue: {
quantity: parseInt(quantity, 10),
warehouseIndex
},
type: ProductVariantCreateReducerActionType.applyStockToAll
})
}
onAttributeSelect={(attributeId, type) =>

View file

@ -20,7 +20,8 @@ export interface ProductVariantCreatorPriceAndSkuProps {
value: VariantCreatorPricesAndSkuMode,
type: PriceOrStock
) => void;
onApplyToAllPriceOrStockChange: (value: string, type: PriceOrStock) => void;
onApplyToAllPriceChange: (value: string) => void;
onApplyToAllStockChange: (warehouseIndex: number, value: string) => void;
onAttributeSelect: (id: string, type: PriceOrStock) => void;
onAttributeValueChange: (
id: string,
@ -35,8 +36,9 @@ const ProductVariantCreatorPriceAndSku: React.FC<ProductVariantCreatorPriceAndSk
currencySymbol,
data,
warehouses,
onApplyToAllPriceOrStockChange,
onApplyToAllChange,
onApplyToAllPriceChange,
onApplyToAllStockChange,
onAttributeSelect,
onAttributeValueChange,
onWarehouseToggle
@ -47,9 +49,7 @@ const ProductVariantCreatorPriceAndSku: React.FC<ProductVariantCreatorPriceAndSk
currencySymbol={currencySymbol}
data={data}
onApplyToAllChange={value => onApplyToAllChange(value, "price")}
onApplyToAllPriceChange={value =>
onApplyToAllPriceOrStockChange(value, "price")
}
onApplyToAllPriceChange={onApplyToAllPriceChange}
onAttributeSelect={id => onAttributeSelect(id, "price")}
onAttributeValueChange={(id, value) =>
onAttributeValueChange(id, value, "price")
@ -61,9 +61,7 @@ const ProductVariantCreatorPriceAndSku: React.FC<ProductVariantCreatorPriceAndSk
data={data}
warehouses={warehouses}
onApplyToAllChange={value => onApplyToAllChange(value, "stock")}
onApplyToAllStockChange={value =>
onApplyToAllPriceOrStockChange(value, "stock")
}
onApplyToAllStockChange={onApplyToAllStockChange}
onAttributeSelect={id => onAttributeSelect(id, "stock")}
onAttributeValueChange={(id, value) =>
onAttributeValueChange(id, value, "stock")

View file

@ -18,7 +18,7 @@ import CardTitle from "@saleor/components/CardTitle";
import { WarehouseFragment } from "@saleor/warehouses/types/WarehouseFragment";
import CardSpacer from "@saleor/components/CardSpacer";
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
import { isSelected, toggle } from "@saleor/utils/lists";
import { isSelected } from "@saleor/utils/lists";
import {
ProductVariantCreateFormData,
VariantCreatorPricesAndSkuMode
@ -73,7 +73,7 @@ export interface ProductVariantCreatorStockProps {
data: ProductVariantCreateFormData;
warehouses: WarehouseFragment[];
onApplyToAllChange: (mode: VariantCreatorPricesAndSkuMode) => void;
onApplyToAllStockChange: (value: string) => void;
onApplyToAllStockChange: (warehouseIndex: number, value: string) => void;
onAttributeSelect: (id: string) => void;
onAttributeValueChange: (id: string, value: string) => void;
onWarehouseToggle: (id: string) => void;
@ -190,7 +190,10 @@ const ProductVariantCreatorStock: React.FC<ProductVariantCreatorStockProps> = pr
})}
value={data.stock.value[warehouseIndex]}
onChange={event =>
onApplyToAllStockChange(event.target.value)
onApplyToAllStockChange(
warehouseIndex,
event.target.value
)
}
/>
</div>