Fix issues with stocks (#954)

This commit is contained in:
Jakub Majorek 2021-01-21 10:07:16 +01:00 committed by GitHub
parent 77ed12664d
commit 37bb52d087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View file

@ -268,7 +268,7 @@ const ProductStocks: React.FC<ProductStocksProps> = ({
{stock.label}
</TableCell>
<TableCell className={classes.colQuantity}>
{stock.data.quantityAllocated}
{stock.data?.quantityAllocated || 0}
</TableCell>
<TableCell className={classes.colQuantity}>
<TextField

View file

@ -274,7 +274,9 @@ function useProductUpdateForm(
const handleStockAdd = (id: string) => {
triggerChange();
stocks.add({
data: null,
data: {
quantityAllocated: 0
},
id,
label: opts.warehouses.find(warehouse => warehouse.id === id).name,
value: "0"
@ -317,7 +319,6 @@ function useProductUpdateForm(
...data,
...getStocksData(product, stocks.data),
...getMetadata(data, isMetadataModified, isPrivateMetadataModified),
addStocks: [],
attributes: attributes.data,
attributesWithNewFileValue: attributesWithNewFileValue.data,
description: description.current

View file

@ -30,7 +30,7 @@ import { FetchMoreProps, ReorderEvent } from "@saleor/types";
import useMetadataChangeTrigger from "@saleor/utils/metadata/useMetadataChangeTrigger";
import React from "react";
import { ProductStockInput } from "../ProductStocks";
import { ProductStockFormsetData, ProductStockInput } from "../ProductStocks";
export interface ProductVariantCreateFormData extends MetadataFormData {
sku: string;
@ -112,7 +112,7 @@ function useProductVariantCreateForm(
const form = useForm(initial);
const attributes = useFormset(attributeInput);
const attributesWithNewFileValue = useFormset<null, File>([]);
const stocks = useFormset<null, string>([]);
const stocks = useFormset<ProductStockFormsetData, string>([]);
const channels = useFormset(channelsInput);
const {
makeChangeHandler: makeMetadataChangeHandler
@ -163,7 +163,9 @@ function useProductVariantCreateForm(
const handleStockAdd = (id: string) => {
triggerChange();
stocks.add({
data: null,
data: {
quantityAllocated: 0
},
id,
label: opts.warehouses.find(warehouse => warehouse.id === id).name,
value: "0"