Fix type errors
This commit is contained in:
parent
d0e082dc21
commit
8b5b3c81d5
18 changed files with 103 additions and 77 deletions
|
@ -165,12 +165,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
|||
MultiAutocompleteChoiceType[]
|
||||
>([]);
|
||||
|
||||
const [productType, setProductType] = React.useState<ProductType>({
|
||||
hasVariants: false,
|
||||
id: "",
|
||||
name: "",
|
||||
productAttributes: []
|
||||
});
|
||||
const [productType, setProductType] = React.useState<ProductType>(null);
|
||||
|
||||
const categories = getChoices(categoryChoiceList);
|
||||
const collections = getChoices(collectionChoiceList);
|
||||
|
@ -253,7 +248,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
|||
onChange={change}
|
||||
/>
|
||||
<CardSpacer />
|
||||
{!productType.hasVariants && (
|
||||
{!!productType && !productType.hasVariants && (
|
||||
<>
|
||||
<ProductStocks
|
||||
data={data}
|
||||
|
@ -296,7 +291,7 @@ export const ProductCreatePage: React.FC<ProductCreatePageProps> = ({
|
|||
fetchMoreProductTypes={fetchMoreProductTypes}
|
||||
fetchProductTypes={fetchProductTypes}
|
||||
productType={productType}
|
||||
productTypeInputDisplayValue={productType.name}
|
||||
productTypeInputDisplayValue={productType?.name || ""}
|
||||
productTypes={productTypes}
|
||||
onCategoryChange={handleCategorySelect}
|
||||
onCollectionChange={handleCollectionSelect}
|
||||
|
|
|
@ -175,7 +175,7 @@ const ProductStocks: React.FC<ProductStocksProps> = ({
|
|||
{renderCollection(
|
||||
stocks,
|
||||
stock => (
|
||||
<TableRow>
|
||||
<TableRow key={stock.id}>
|
||||
<TableCell className={classes.colName}>{stock.label}</TableCell>
|
||||
<TableCell className={classes.colQuantity}>
|
||||
<TextField
|
||||
|
|
|
@ -45,7 +45,6 @@ interface ProductVariantCreatePageProps {
|
|||
disabled: boolean;
|
||||
errors: ProductErrorFragment[];
|
||||
header: string;
|
||||
loading: boolean;
|
||||
product: ProductVariantCreateData_product;
|
||||
saveButtonBarState: ConfirmButtonTransitionState;
|
||||
warehouses: SearchWarehouses_search_edges_node[];
|
||||
|
@ -59,7 +58,6 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
|||
currencySymbol,
|
||||
disabled,
|
||||
errors,
|
||||
loading,
|
||||
header,
|
||||
product,
|
||||
saveButtonBarState,
|
||||
|
@ -133,7 +131,7 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
|||
<div>
|
||||
<ProductVariantAttributes
|
||||
attributes={attributes}
|
||||
disabled={loading}
|
||||
disabled={disabled}
|
||||
errors={errors}
|
||||
onChange={handleAttributeChange}
|
||||
/>
|
||||
|
@ -143,7 +141,7 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
|||
priceOverride={data.priceOverride}
|
||||
currencySymbol={currencySymbol}
|
||||
costPrice={data.costPrice}
|
||||
loading={loading}
|
||||
loading={disabled}
|
||||
onChange={change}
|
||||
/>
|
||||
<CardSpacer />
|
||||
|
@ -159,7 +157,7 @@ const ProductVariantCreatePage: React.FC<ProductVariantCreatePageProps> = ({
|
|||
</div>
|
||||
</Grid>
|
||||
<SaveButtonBar
|
||||
disabled={loading || !onSubmit || !hasChanged}
|
||||
disabled={disabled || !onSubmit || !hasChanged}
|
||||
labels={{
|
||||
delete: intl.formatMessage({
|
||||
defaultMessage: "Delete Variant",
|
||||
|
|
|
@ -3,7 +3,7 @@ import React from "react";
|
|||
|
||||
import Decorator from "@saleor/storybook//Decorator";
|
||||
import { warehouseList } from "@saleor/warehouses/fixtures";
|
||||
import { formError } from "@saleor/storybook/misc";
|
||||
import { StockErrorCode } from "@saleor/types/globalTypes";
|
||||
import ProductWarehousesDialog, {
|
||||
ProductWarehousesDialogProps
|
||||
} from "./ProductWarehousesDialog";
|
||||
|
@ -15,21 +15,8 @@ const props: ProductWarehousesDialogProps = {
|
|||
onClose: () => undefined,
|
||||
onConfirm: () => undefined,
|
||||
open: true,
|
||||
stocks: [
|
||||
{
|
||||
__typename: "Stock",
|
||||
id: "5123",
|
||||
quantity: 2,
|
||||
warehouse: warehouseList[0]
|
||||
},
|
||||
{
|
||||
__typename: "Stock",
|
||||
id: "5223",
|
||||
quantity: 4,
|
||||
warehouse: warehouseList[2]
|
||||
}
|
||||
],
|
||||
warehouses: warehouseList
|
||||
warehouses: warehouseList,
|
||||
warehousesWithStocks: [warehouseList[0].id, warehouseList[2].id]
|
||||
};
|
||||
|
||||
storiesOf("Views / Products / Edit warehouses", module)
|
||||
|
@ -46,5 +33,14 @@ storiesOf("Views / Products / Edit warehouses", module)
|
|||
/>
|
||||
))
|
||||
.add("with error", () => (
|
||||
<ProductWarehousesDialog {...props} errors={[formError(null)]} />
|
||||
<ProductWarehousesDialog
|
||||
{...props}
|
||||
errors={[
|
||||
{
|
||||
__typename: "StockError",
|
||||
code: StockErrorCode.INVALID,
|
||||
field: null
|
||||
}
|
||||
]}
|
||||
/>
|
||||
));
|
||||
|
|
|
@ -60,7 +60,7 @@ function getErrorMessage(
|
|||
case "BulkStockError":
|
||||
return getBulkStockErrorMessage(err, intl);
|
||||
default:
|
||||
getStockErrorMessage(err, intl);
|
||||
return getStockErrorMessage(err, intl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1247,21 +1247,30 @@ export const variant = (placeholderImage: string): ProductVariant => ({
|
|||
}
|
||||
]
|
||||
},
|
||||
quantity: 19,
|
||||
quantityAllocated: 12,
|
||||
sku: "1230959124123",
|
||||
stock: [
|
||||
stocks: [
|
||||
{
|
||||
__typename: "Stock",
|
||||
id: "1",
|
||||
quantity: 1
|
||||
quantity: 1,
|
||||
warehouse: {
|
||||
__typename: "Warehouse",
|
||||
id: "123",
|
||||
name: "Warehouse 1"
|
||||
}
|
||||
},
|
||||
{
|
||||
__typename: "Stock",
|
||||
id: "2",
|
||||
quantity: 4
|
||||
quantity: 4,
|
||||
warehouse: {
|
||||
__typename: "Warehouse",
|
||||
id: "1234",
|
||||
name: "Warehouse 2"
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
trackInventory: true
|
||||
});
|
||||
export const variantImages = (placeholderImage: string) =>
|
||||
variant(placeholderImage).images;
|
||||
|
|
|
@ -59,11 +59,7 @@ export const ProductCreateView: React.FC<ProductCreateViewProps> = ({
|
|||
} = useProductTypeSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
const {
|
||||
loadMore: loadMoreWarehouses,
|
||||
search: searchWarehouses,
|
||||
result: searchWarehousesOpts
|
||||
} = useWarehouseSearch({
|
||||
const { result: searchWarehousesOpts } = useWarehouseSearch({
|
||||
variables: {
|
||||
...DEFAULT_INITIAL_SEARCH_DATA,
|
||||
first: 20
|
||||
|
|
|
@ -74,11 +74,7 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
|||
} = useCollectionSearch({
|
||||
variables: DEFAULT_INITIAL_SEARCH_DATA
|
||||
});
|
||||
const {
|
||||
loadMore: loadMoreWarehouses,
|
||||
search: searchWarehouses,
|
||||
result: searchWarehousesOpts
|
||||
} = useWarehouseSearch({
|
||||
const { result: searchWarehousesOpts } = useWarehouseSearch({
|
||||
variables: {
|
||||
...DEFAULT_INITIAL_SEARCH_DATA,
|
||||
first: 20
|
||||
|
|
|
@ -52,11 +52,7 @@ export const ProductVariant: React.FC<ProductUpdateProps> = ({
|
|||
setErrors([]);
|
||||
}, [variantId]);
|
||||
|
||||
const {
|
||||
loadMore: loadMoreWarehouses,
|
||||
search: searchWarehouses,
|
||||
result: searchWarehousesOpts
|
||||
} = useWarehouseSearch({
|
||||
const { result: searchWarehousesOpts } = useWarehouseSearch({
|
||||
variables: {
|
||||
...DEFAULT_INITIAL_SEARCH_DATA,
|
||||
first: 20
|
||||
|
|
|
@ -41,11 +41,7 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
|||
const notify = useNotifier();
|
||||
const shop = useShop();
|
||||
const intl = useIntl();
|
||||
const {
|
||||
loadMore: loadMoreWarehouses,
|
||||
search: searchWarehouses,
|
||||
result: searchWarehousesOpts
|
||||
} = useWarehouseSearch({
|
||||
const { result: searchWarehousesOpts } = useWarehouseSearch({
|
||||
variables: {
|
||||
...DEFAULT_INITIAL_SEARCH_DATA,
|
||||
first: 20
|
||||
|
@ -127,7 +123,7 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
|||
/>
|
||||
<ProductVariantCreatePage
|
||||
currencySymbol={shop?.defaultCurrency}
|
||||
disabled={productLoading}
|
||||
disabled={disableForm}
|
||||
errors={
|
||||
variantCreateResult.data?.productVariantCreate.errors ||
|
||||
[]
|
||||
|
@ -136,7 +132,6 @@ export const ProductVariant: React.FC<ProductVariantCreateProps> = ({
|
|||
defaultMessage: "Create Variant",
|
||||
description: "header"
|
||||
})}
|
||||
loading={disableForm}
|
||||
product={data?.product}
|
||||
onBack={handleBack}
|
||||
onSubmit={handleSubmit}
|
||||
|
|
|
@ -11,7 +11,7 @@ import makeStyles from "@material-ui/core/styles/makeStyles";
|
|||
import ConfirmButton, {
|
||||
ConfirmButtonTransitionState
|
||||
} from "@saleor/components/ConfirmButton";
|
||||
import { DialogProps, UserError } from "@saleor/types";
|
||||
import { DialogProps } from "@saleor/types";
|
||||
import { AddressTypeInput } from "@saleor/customers/types";
|
||||
import useModalDialogOpen from "@saleor/hooks/useModalDialogOpen";
|
||||
import useModalDialogErrors from "@saleor/hooks/useModalDialogErrors";
|
||||
|
@ -24,6 +24,7 @@ import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
|||
import { ShopInfo_shop_countries } from "@saleor/components/Shop/types/ShopInfo";
|
||||
import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler";
|
||||
import FormSpacer from "@saleor/components/FormSpacer";
|
||||
import { WarehouseErrorFragment } from "@saleor/warehouses/types/WarehouseErrorFragment";
|
||||
|
||||
export interface ShippingZoneAddWarehouseDialogSubmitData
|
||||
extends AddressTypeInput {
|
||||
|
@ -33,7 +34,7 @@ export interface ShippingZoneAddWarehouseDialogProps extends DialogProps {
|
|||
confirmButtonState: ConfirmButtonTransitionState;
|
||||
countries: ShopInfo_shop_countries[];
|
||||
disabled: boolean;
|
||||
errors: UserError[];
|
||||
errors: WarehouseErrorFragment[];
|
||||
onSubmit: (data: ShippingZoneAddWarehouseDialogSubmitData) => void;
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ const ShippingZoneDetails: React.FC<ShippingZoneDetailsProps> = ({
|
|||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(`Updating failed: ${updateErrors[0].message}`);
|
||||
throw new Error(`Updating failed: ${updateErrors[0].code}`);
|
||||
}
|
||||
} catch (err) {
|
||||
notify({
|
||||
|
|
|
@ -3,6 +3,7 @@ import React from "react";
|
|||
|
||||
import { fetchMoreProps } from "@saleor/fixtures";
|
||||
import { ProductErrorCode } from "@saleor/types/globalTypes";
|
||||
import { warehouseList } from "@saleor/warehouses/fixtures";
|
||||
import ProductCreatePage, {
|
||||
ProductCreatePageSubmitData
|
||||
} from "../../../products/components/ProductCreatePage";
|
||||
|
@ -32,6 +33,8 @@ storiesOf("Views / Products / Create product", module)
|
|||
onBack={() => undefined}
|
||||
onSubmit={() => undefined}
|
||||
saveButtonBarState="default"
|
||||
onWarehouseEdit={() => undefined}
|
||||
warehouses={warehouseList}
|
||||
/>
|
||||
))
|
||||
.add("When loading", () => (
|
||||
|
@ -52,6 +55,8 @@ storiesOf("Views / Products / Create product", module)
|
|||
onBack={() => undefined}
|
||||
onSubmit={() => undefined}
|
||||
saveButtonBarState="default"
|
||||
onWarehouseEdit={() => undefined}
|
||||
warehouses={undefined}
|
||||
/>
|
||||
))
|
||||
.add("form errors", () => (
|
||||
|
@ -78,5 +83,7 @@ storiesOf("Views / Products / Create product", module)
|
|||
onBack={() => undefined}
|
||||
onSubmit={() => undefined}
|
||||
saveButtonBarState="default"
|
||||
onWarehouseEdit={() => undefined}
|
||||
warehouses={warehouseList}
|
||||
/>
|
||||
));
|
||||
|
|
|
@ -30,11 +30,11 @@ const props: ProductUpdatePageProps = {
|
|||
onDelete: () => undefined,
|
||||
onImageDelete: () => undefined,
|
||||
onImageUpload: () => undefined,
|
||||
onProductShow: () => undefined,
|
||||
onSubmit: () => undefined,
|
||||
onVariantAdd: () => undefined,
|
||||
onVariantShow: () => undefined,
|
||||
onVariantsAdd: () => undefined,
|
||||
onWarehousesEdit: () => undefined,
|
||||
placeholderImage,
|
||||
product,
|
||||
saveButtonBarState: "default",
|
||||
|
@ -73,7 +73,28 @@ storiesOf("Views / Products / Product edit", module)
|
|||
{...props}
|
||||
product={{
|
||||
...props.product,
|
||||
variants: []
|
||||
productType: {
|
||||
...product.productType,
|
||||
hasVariants: false
|
||||
}
|
||||
}}
|
||||
/>
|
||||
))
|
||||
.add("no stock and no variants", () => (
|
||||
<ProductUpdatePage
|
||||
{...props}
|
||||
product={{
|
||||
...product,
|
||||
productType: {
|
||||
...product.productType,
|
||||
hasVariants: false
|
||||
},
|
||||
variants: [
|
||||
{
|
||||
...product.variants[0],
|
||||
stocks: []
|
||||
}
|
||||
]
|
||||
}}
|
||||
/>
|
||||
))
|
||||
|
|
|
@ -3,6 +3,7 @@ import React from "react";
|
|||
|
||||
import placeholderImage from "@assets/images/placeholder255x255.png";
|
||||
import { ProductErrorCode } from "@saleor/types/globalTypes";
|
||||
import { warehouseList } from "@saleor/warehouses/fixtures";
|
||||
import ProductVariantCreatePage from "../../../products/components/ProductVariantCreatePage";
|
||||
import { product as productFixture } from "../../../products/fixtures";
|
||||
import Decorator from "../../Decorator";
|
||||
|
@ -14,19 +15,22 @@ storiesOf("Views / Products / Create product variant", module)
|
|||
.add("default", () => (
|
||||
<ProductVariantCreatePage
|
||||
currencySymbol="USD"
|
||||
disabled={false}
|
||||
errors={[]}
|
||||
header="Add variant"
|
||||
loading={false}
|
||||
product={product}
|
||||
onBack={() => undefined}
|
||||
onSubmit={() => undefined}
|
||||
onVariantClick={undefined}
|
||||
saveButtonBarState="default"
|
||||
warehouses={warehouseList}
|
||||
onWarehouseEdit={() => undefined}
|
||||
/>
|
||||
))
|
||||
.add("with errors", () => (
|
||||
<ProductVariantCreatePage
|
||||
currencySymbol="USD"
|
||||
disabled={false}
|
||||
errors={[
|
||||
{
|
||||
code: ProductErrorCode.REQUIRED,
|
||||
|
@ -45,33 +49,36 @@ storiesOf("Views / Products / Create product variant", module)
|
|||
...error
|
||||
}))}
|
||||
header="Add variant"
|
||||
loading={false}
|
||||
product={product}
|
||||
onBack={() => undefined}
|
||||
onSubmit={() => undefined}
|
||||
onVariantClick={undefined}
|
||||
saveButtonBarState="default"
|
||||
warehouses={warehouseList}
|
||||
onWarehouseEdit={() => undefined}
|
||||
/>
|
||||
))
|
||||
.add("when loading data", () => (
|
||||
<ProductVariantCreatePage
|
||||
currencySymbol="USD"
|
||||
disabled={true}
|
||||
errors={[]}
|
||||
header="Add variant"
|
||||
loading={true}
|
||||
product={undefined}
|
||||
onBack={() => undefined}
|
||||
onSubmit={() => undefined}
|
||||
onVariantClick={undefined}
|
||||
saveButtonBarState="default"
|
||||
warehouses={warehouseList}
|
||||
onWarehouseEdit={() => undefined}
|
||||
/>
|
||||
))
|
||||
.add("add first variant", () => (
|
||||
<ProductVariantCreatePage
|
||||
currencySymbol="USD"
|
||||
disabled={false}
|
||||
errors={[]}
|
||||
header="Add variant"
|
||||
loading={false}
|
||||
product={{
|
||||
...product,
|
||||
variants: []
|
||||
|
@ -80,5 +87,7 @@ storiesOf("Views / Products / Create product variant", module)
|
|||
onSubmit={() => undefined}
|
||||
onVariantClick={undefined}
|
||||
saveButtonBarState="default"
|
||||
warehouses={warehouseList}
|
||||
onWarehouseEdit={() => undefined}
|
||||
/>
|
||||
));
|
||||
|
|
|
@ -23,6 +23,7 @@ storiesOf("Views / Products / Product variant details", module)
|
|||
onSubmit={() => undefined}
|
||||
onVariantClick={() => undefined}
|
||||
saveButtonBarState="default"
|
||||
onWarehousesEdit={() => undefined}
|
||||
/>
|
||||
))
|
||||
.add("when loading data", () => (
|
||||
|
@ -38,6 +39,7 @@ storiesOf("Views / Products / Product variant details", module)
|
|||
onSubmit={() => undefined}
|
||||
onVariantClick={() => undefined}
|
||||
saveButtonBarState="default"
|
||||
onWarehousesEdit={() => undefined}
|
||||
/>
|
||||
))
|
||||
.add("attribute errors", () => (
|
||||
|
@ -69,5 +71,6 @@ storiesOf("Views / Products / Product variant details", module)
|
|||
message: "Generic form error",
|
||||
...error
|
||||
}))}
|
||||
onWarehousesEdit={() => undefined}
|
||||
/>
|
||||
));
|
||||
|
|
|
@ -2,8 +2,8 @@ import { storiesOf } from "@storybook/react";
|
|||
import React from "react";
|
||||
|
||||
import Decorator from "@saleor/storybook/Decorator";
|
||||
import { formError } from "@saleor/storybook/misc";
|
||||
import { countries } from "@saleor/fixtures";
|
||||
import { WarehouseErrorCode } from "@saleor/types/globalTypes";
|
||||
import WarehouseCreatePage, {
|
||||
WarehouseCreatePageProps,
|
||||
WarehouseCreatePageFormData
|
||||
|
@ -39,8 +39,10 @@ storiesOf("Views / Warehouses / Create warehouse", module)
|
|||
"postalCode",
|
||||
"streetAddress1",
|
||||
"streetAddress2"
|
||||
] as Array<keyof WarehouseCreatePageFormData>).map(field =>
|
||||
formError(field)
|
||||
)}
|
||||
] as Array<keyof WarehouseCreatePageFormData>).map(field => ({
|
||||
__typename: "WarehouseError",
|
||||
code: WarehouseErrorCode.INVALID,
|
||||
field
|
||||
}))}
|
||||
/>
|
||||
));
|
||||
|
|
|
@ -3,7 +3,7 @@ import React from "react";
|
|||
|
||||
import { address, countries } from "@saleor/fixtures";
|
||||
import Decorator from "@saleor/storybook/Decorator";
|
||||
import { formError } from "@saleor/storybook/misc";
|
||||
import { WarehouseErrorCode } from "@saleor/types/globalTypes";
|
||||
import { warehouseList } from "../../fixtures";
|
||||
import WarehouseDetailsPage, {
|
||||
WarehouseDetailsPageProps,
|
||||
|
@ -48,8 +48,10 @@ storiesOf("Views / Warehouses / Warehouse details", module)
|
|||
"postalCode",
|
||||
"streetAddress1",
|
||||
"streetAddress2"
|
||||
] as Array<keyof WarehouseDetailsPageFormData>).map(field =>
|
||||
formError(field)
|
||||
)}
|
||||
] as Array<keyof WarehouseDetailsPageFormData>).map(field => ({
|
||||
__typename: "WarehouseError",
|
||||
code: WarehouseErrorCode.INVALID,
|
||||
field
|
||||
}))}
|
||||
/>
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue