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) warehouses: selectedWarehouses.map(warehouse => warehouse.id)
}; };
const props: ProductVariantCreatorContentProps = { const props: ProductVariantCreatorContentProps = {
attributes, attributes: [0, 1, 4, 6].map(index => attributes[index]),
currencySymbol: "USD", currencySymbol: "USD",
data: { data: {
...data, ...data,

View file

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

View file

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

View file

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