Add simple product stock management
This commit is contained in:
parent
c161de1270
commit
db3b51f931
9 changed files with 485 additions and 19 deletions
|
@ -252,7 +252,10 @@ export const ProductUpdatePage: React.FC<ProductUpdatePageProps> = ({
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
stocks={stocks}
|
stocks={stocks}
|
||||||
onChange={changeStockData}
|
onChange={(id, value) => {
|
||||||
|
triggerChange();
|
||||||
|
changeStockData(id, value);
|
||||||
|
}}
|
||||||
onFormDataChange={change}
|
onFormDataChange={change}
|
||||||
onWarehousesEdit={onWarehousesEdit}
|
onWarehousesEdit={onWarehousesEdit}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -13,13 +13,14 @@ import ConfirmButton, {
|
||||||
ConfirmButtonTransitionState
|
ConfirmButtonTransitionState
|
||||||
} from "@saleor/components/ConfirmButton";
|
} from "@saleor/components/ConfirmButton";
|
||||||
import { buttonMessages } from "@saleor/intl";
|
import { buttonMessages } from "@saleor/intl";
|
||||||
import { UserError } from "@saleor/types";
|
|
||||||
import { SearchWarehouses_search_edges_node } from "@saleor/searches/types/SearchWarehouses";
|
import { SearchWarehouses_search_edges_node } from "@saleor/searches/types/SearchWarehouses";
|
||||||
import Skeleton from "@saleor/components/Skeleton";
|
import Skeleton from "@saleor/components/Skeleton";
|
||||||
import { Product_variants_stocks } from "@saleor/products/types/Product";
|
import { Product_variants_stocks } from "@saleor/products/types/Product";
|
||||||
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
import ControlledCheckbox from "@saleor/components/ControlledCheckbox";
|
||||||
import { isSelected, toggle } from "@saleor/utils/lists";
|
import { isSelected, toggle } from "@saleor/utils/lists";
|
||||||
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
import useStateFromProps from "@saleor/hooks/useStateFromProps";
|
||||||
|
import { BulkStockErrorFragment } from "@saleor/products/types/BulkStockErrorFragment";
|
||||||
|
import { StockErrorFragment } from "@saleor/products/types/StockErrorFragment";
|
||||||
|
|
||||||
const useStyles = makeStyles(
|
const useStyles = makeStyles(
|
||||||
theme => ({
|
theme => ({
|
||||||
|
@ -41,7 +42,7 @@ const useStyles = makeStyles(
|
||||||
export interface ProductWarehousesDialogProps {
|
export interface ProductWarehousesDialogProps {
|
||||||
confirmButtonState: ConfirmButtonTransitionState;
|
confirmButtonState: ConfirmButtonTransitionState;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
errors: UserError[];
|
errors: Array<BulkStockErrorFragment | StockErrorFragment>;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
stocks: Product_variants_stocks[];
|
stocks: Product_variants_stocks[];
|
||||||
warehouses: SearchWarehouses_search_edges_node[];
|
warehouses: SearchWarehouses_search_edges_node[];
|
||||||
|
|
|
@ -71,6 +71,19 @@ export const bulkProductErrorFragment = gql`
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
const bulkStockErrorFragment = gql`
|
||||||
|
fragment BulkStockErrorFragment on BulkStockError {
|
||||||
|
code
|
||||||
|
field
|
||||||
|
index
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const stockErrorFragment = gql`
|
||||||
|
fragment StockErrorFragment on StockError {
|
||||||
|
code
|
||||||
|
field
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export const productImageCreateMutation = gql`
|
export const productImageCreateMutation = gql`
|
||||||
${productErrorFragment}
|
${productErrorFragment}
|
||||||
|
@ -179,8 +192,10 @@ export const TypedProductUpdateMutation = TypedMutation<
|
||||||
>(productUpdateMutation);
|
>(productUpdateMutation);
|
||||||
|
|
||||||
export const simpleProductUpdateMutation = gql`
|
export const simpleProductUpdateMutation = gql`
|
||||||
|
${bulkStockErrorFragment}
|
||||||
${productErrorFragment}
|
${productErrorFragment}
|
||||||
${productFragmentDetails}
|
${productFragmentDetails}
|
||||||
|
${stockErrorFragment}
|
||||||
${fragmentVariant}
|
${fragmentVariant}
|
||||||
mutation SimpleProductUpdate(
|
mutation SimpleProductUpdate(
|
||||||
$id: ID!
|
$id: ID!
|
||||||
|
@ -196,6 +211,9 @@ export const simpleProductUpdateMutation = gql`
|
||||||
$productVariantId: ID!
|
$productVariantId: ID!
|
||||||
$productVariantInput: ProductVariantInput!
|
$productVariantInput: ProductVariantInput!
|
||||||
$seo: SeoInput
|
$seo: SeoInput
|
||||||
|
$addStocks: [StockInput!]!
|
||||||
|
$deleteStocks: [ID!]!
|
||||||
|
$updateStocks: [StockInput!]!
|
||||||
) {
|
) {
|
||||||
productUpdate(
|
productUpdate(
|
||||||
id: $id
|
id: $id
|
||||||
|
@ -227,6 +245,39 @@ export const simpleProductUpdateMutation = gql`
|
||||||
...ProductVariant
|
...ProductVariant
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
productVariantStocksCreate(
|
||||||
|
stocks: $addStocks
|
||||||
|
variantId: $productVariantId
|
||||||
|
) {
|
||||||
|
errors: bulkStockErrors {
|
||||||
|
...BulkStockErrorFragment
|
||||||
|
}
|
||||||
|
productVariant {
|
||||||
|
...ProductVariant
|
||||||
|
}
|
||||||
|
}
|
||||||
|
productVariantStocksDelete(
|
||||||
|
warehouseIds: $deleteStocks
|
||||||
|
variantId: $productVariantId
|
||||||
|
) {
|
||||||
|
errors: stockErrors {
|
||||||
|
...StockErrorFragment
|
||||||
|
}
|
||||||
|
productVariant {
|
||||||
|
...ProductVariant
|
||||||
|
}
|
||||||
|
}
|
||||||
|
productVariantStocksUpdate(
|
||||||
|
stocks: $updateStocks
|
||||||
|
variantId: $productVariantId
|
||||||
|
) {
|
||||||
|
errors: bulkStockErrors {
|
||||||
|
...BulkStockErrorFragment
|
||||||
|
}
|
||||||
|
productVariant {
|
||||||
|
...ProductVariant
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
export const TypedSimpleProductUpdateMutation = TypedMutation<
|
export const TypedSimpleProductUpdateMutation = TypedMutation<
|
||||||
|
@ -499,6 +550,7 @@ export const TypedProductVariantBulkDeleteMutation = TypedMutation<
|
||||||
>(ProductVariantBulkDeleteMutation);
|
>(ProductVariantBulkDeleteMutation);
|
||||||
|
|
||||||
const addOrRemoveStocks = gql`
|
const addOrRemoveStocks = gql`
|
||||||
|
${bulkStockErrorFragment}
|
||||||
${stockFragment}
|
${stockFragment}
|
||||||
mutation AddOrRemoveStocks(
|
mutation AddOrRemoveStocks(
|
||||||
$variantId: ID!
|
$variantId: ID!
|
||||||
|
@ -506,10 +558,8 @@ const addOrRemoveStocks = gql`
|
||||||
$remove: [ID!]!
|
$remove: [ID!]!
|
||||||
) {
|
) {
|
||||||
productVariantStocksCreate(stocks: $add, variantId: $variantId) {
|
productVariantStocksCreate(stocks: $add, variantId: $variantId) {
|
||||||
bulkStockErrors {
|
errors: bulkStockErrors {
|
||||||
code
|
...BulkStockErrorFragment
|
||||||
field
|
|
||||||
index
|
|
||||||
}
|
}
|
||||||
productVariant {
|
productVariant {
|
||||||
id
|
id
|
||||||
|
@ -519,7 +569,7 @@ const addOrRemoveStocks = gql`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
productVariantStocksDelete(warehouseIds: $remove, variantId: $variantId) {
|
productVariantStocksDelete(warehouseIds: $remove, variantId: $variantId) {
|
||||||
stockErrors {
|
errors: stockErrors {
|
||||||
code
|
code
|
||||||
field
|
field
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { StockInput, ProductErrorCode, StockErrorCode } from "./../../types/glob
|
||||||
// GraphQL mutation operation: AddOrRemoveStocks
|
// GraphQL mutation operation: AddOrRemoveStocks
|
||||||
// ====================================================
|
// ====================================================
|
||||||
|
|
||||||
export interface AddOrRemoveStocks_productVariantStocksCreate_bulkStockErrors {
|
export interface AddOrRemoveStocks_productVariantStocksCreate_errors {
|
||||||
__typename: "BulkStockError";
|
__typename: "BulkStockError";
|
||||||
code: ProductErrorCode;
|
code: ProductErrorCode;
|
||||||
field: string | null;
|
field: string | null;
|
||||||
|
@ -36,11 +36,11 @@ export interface AddOrRemoveStocks_productVariantStocksCreate_productVariant {
|
||||||
|
|
||||||
export interface AddOrRemoveStocks_productVariantStocksCreate {
|
export interface AddOrRemoveStocks_productVariantStocksCreate {
|
||||||
__typename: "ProductVariantStocksCreate";
|
__typename: "ProductVariantStocksCreate";
|
||||||
bulkStockErrors: AddOrRemoveStocks_productVariantStocksCreate_bulkStockErrors[];
|
errors: AddOrRemoveStocks_productVariantStocksCreate_errors[];
|
||||||
productVariant: AddOrRemoveStocks_productVariantStocksCreate_productVariant | null;
|
productVariant: AddOrRemoveStocks_productVariantStocksCreate_productVariant | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AddOrRemoveStocks_productVariantStocksDelete_stockErrors {
|
export interface AddOrRemoveStocks_productVariantStocksDelete_errors {
|
||||||
__typename: "StockError";
|
__typename: "StockError";
|
||||||
code: StockErrorCode;
|
code: StockErrorCode;
|
||||||
field: string | null;
|
field: string | null;
|
||||||
|
@ -67,7 +67,7 @@ export interface AddOrRemoveStocks_productVariantStocksDelete_productVariant {
|
||||||
|
|
||||||
export interface AddOrRemoveStocks_productVariantStocksDelete {
|
export interface AddOrRemoveStocks_productVariantStocksDelete {
|
||||||
__typename: "ProductVariantStocksDelete";
|
__typename: "ProductVariantStocksDelete";
|
||||||
stockErrors: AddOrRemoveStocks_productVariantStocksDelete_stockErrors[];
|
errors: AddOrRemoveStocks_productVariantStocksDelete_errors[];
|
||||||
productVariant: AddOrRemoveStocks_productVariantStocksDelete_productVariant | null;
|
productVariant: AddOrRemoveStocks_productVariantStocksDelete_productVariant | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/products/types/BulkStockErrorFragment.ts
Normal file
16
src/products/types/BulkStockErrorFragment.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// This file was automatically generated and should not be edited.
|
||||||
|
|
||||||
|
import { ProductErrorCode } from "./../../types/globalTypes";
|
||||||
|
|
||||||
|
// ====================================================
|
||||||
|
// GraphQL fragment: BulkStockErrorFragment
|
||||||
|
// ====================================================
|
||||||
|
|
||||||
|
export interface BulkStockErrorFragment {
|
||||||
|
__typename: "BulkStockError";
|
||||||
|
code: ProductErrorCode;
|
||||||
|
field: string | null;
|
||||||
|
index: number | null;
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// This file was automatically generated and should not be edited.
|
// This file was automatically generated and should not be edited.
|
||||||
|
|
||||||
import { AttributeValueInput, ProductVariantInput, SeoInput, ProductErrorCode, AttributeInputTypeEnum } from "./../../types/globalTypes";
|
import { AttributeValueInput, ProductVariantInput, SeoInput, StockInput, ProductErrorCode, AttributeInputTypeEnum, StockErrorCode } from "./../../types/globalTypes";
|
||||||
|
|
||||||
// ====================================================
|
// ====================================================
|
||||||
// GraphQL mutation operation: SimpleProductUpdate
|
// GraphQL mutation operation: SimpleProductUpdate
|
||||||
|
@ -315,9 +315,380 @@ export interface SimpleProductUpdate_productVariantUpdate {
|
||||||
productVariant: SimpleProductUpdate_productVariantUpdate_productVariant | null;
|
productVariant: SimpleProductUpdate_productVariantUpdate_productVariant | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_errors {
|
||||||
|
__typename: "BulkStockError";
|
||||||
|
code: ProductErrorCode;
|
||||||
|
field: string | null;
|
||||||
|
index: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes_attribute_values {
|
||||||
|
__typename: "AttributeValue";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes_attribute {
|
||||||
|
__typename: "Attribute";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
valueRequired: boolean;
|
||||||
|
values: (SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes_attribute_values | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes_values {
|
||||||
|
__typename: "AttributeValue";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes {
|
||||||
|
__typename: "SelectedAttribute";
|
||||||
|
attribute: SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes_attribute;
|
||||||
|
values: (SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes_values | null)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_costPrice {
|
||||||
|
__typename: "Money";
|
||||||
|
amount: number;
|
||||||
|
currency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_priceOverride {
|
||||||
|
__typename: "Money";
|
||||||
|
amount: number;
|
||||||
|
currency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_product_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
alt: string;
|
||||||
|
sortOrder: number | null;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_product_thumbnail {
|
||||||
|
__typename: "Image";
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_product_variants_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_product_variants {
|
||||||
|
__typename: "ProductVariant";
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
sku: string;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksCreate_productVariant_product_variants_images | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_product {
|
||||||
|
__typename: "Product";
|
||||||
|
id: string;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksCreate_productVariant_product_images | null)[] | null;
|
||||||
|
name: string;
|
||||||
|
thumbnail: SimpleProductUpdate_productVariantStocksCreate_productVariant_product_thumbnail | null;
|
||||||
|
variants: (SimpleProductUpdate_productVariantStocksCreate_productVariant_product_variants | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks_warehouse {
|
||||||
|
__typename: "Warehouse";
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks {
|
||||||
|
__typename: "Stock";
|
||||||
|
id: string;
|
||||||
|
quantity: number;
|
||||||
|
warehouse: SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks_warehouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate_productVariant {
|
||||||
|
__typename: "ProductVariant";
|
||||||
|
id: string;
|
||||||
|
attributes: SimpleProductUpdate_productVariantStocksCreate_productVariant_attributes[];
|
||||||
|
costPrice: SimpleProductUpdate_productVariantStocksCreate_productVariant_costPrice | null;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksCreate_productVariant_images | null)[] | null;
|
||||||
|
name: string;
|
||||||
|
priceOverride: SimpleProductUpdate_productVariantStocksCreate_productVariant_priceOverride | null;
|
||||||
|
product: SimpleProductUpdate_productVariantStocksCreate_productVariant_product;
|
||||||
|
sku: string;
|
||||||
|
stocks: (SimpleProductUpdate_productVariantStocksCreate_productVariant_stocks | null)[] | null;
|
||||||
|
trackInventory: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksCreate {
|
||||||
|
__typename: "ProductVariantStocksCreate";
|
||||||
|
errors: SimpleProductUpdate_productVariantStocksCreate_errors[];
|
||||||
|
productVariant: SimpleProductUpdate_productVariantStocksCreate_productVariant | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_errors {
|
||||||
|
__typename: "StockError";
|
||||||
|
code: StockErrorCode;
|
||||||
|
field: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes_attribute_values {
|
||||||
|
__typename: "AttributeValue";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes_attribute {
|
||||||
|
__typename: "Attribute";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
valueRequired: boolean;
|
||||||
|
values: (SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes_attribute_values | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes_values {
|
||||||
|
__typename: "AttributeValue";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes {
|
||||||
|
__typename: "SelectedAttribute";
|
||||||
|
attribute: SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes_attribute;
|
||||||
|
values: (SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes_values | null)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_costPrice {
|
||||||
|
__typename: "Money";
|
||||||
|
amount: number;
|
||||||
|
currency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_priceOverride {
|
||||||
|
__typename: "Money";
|
||||||
|
amount: number;
|
||||||
|
currency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_product_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
alt: string;
|
||||||
|
sortOrder: number | null;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_product_thumbnail {
|
||||||
|
__typename: "Image";
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_product_variants_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_product_variants {
|
||||||
|
__typename: "ProductVariant";
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
sku: string;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksDelete_productVariant_product_variants_images | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_product {
|
||||||
|
__typename: "Product";
|
||||||
|
id: string;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksDelete_productVariant_product_images | null)[] | null;
|
||||||
|
name: string;
|
||||||
|
thumbnail: SimpleProductUpdate_productVariantStocksDelete_productVariant_product_thumbnail | null;
|
||||||
|
variants: (SimpleProductUpdate_productVariantStocksDelete_productVariant_product_variants | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks_warehouse {
|
||||||
|
__typename: "Warehouse";
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks {
|
||||||
|
__typename: "Stock";
|
||||||
|
id: string;
|
||||||
|
quantity: number;
|
||||||
|
warehouse: SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks_warehouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete_productVariant {
|
||||||
|
__typename: "ProductVariant";
|
||||||
|
id: string;
|
||||||
|
attributes: SimpleProductUpdate_productVariantStocksDelete_productVariant_attributes[];
|
||||||
|
costPrice: SimpleProductUpdate_productVariantStocksDelete_productVariant_costPrice | null;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksDelete_productVariant_images | null)[] | null;
|
||||||
|
name: string;
|
||||||
|
priceOverride: SimpleProductUpdate_productVariantStocksDelete_productVariant_priceOverride | null;
|
||||||
|
product: SimpleProductUpdate_productVariantStocksDelete_productVariant_product;
|
||||||
|
sku: string;
|
||||||
|
stocks: (SimpleProductUpdate_productVariantStocksDelete_productVariant_stocks | null)[] | null;
|
||||||
|
trackInventory: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksDelete {
|
||||||
|
__typename: "ProductVariantStocksDelete";
|
||||||
|
errors: SimpleProductUpdate_productVariantStocksDelete_errors[];
|
||||||
|
productVariant: SimpleProductUpdate_productVariantStocksDelete_productVariant | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_errors {
|
||||||
|
__typename: "BulkStockError";
|
||||||
|
code: ProductErrorCode;
|
||||||
|
field: string | null;
|
||||||
|
index: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes_attribute_values {
|
||||||
|
__typename: "AttributeValue";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes_attribute {
|
||||||
|
__typename: "Attribute";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
valueRequired: boolean;
|
||||||
|
values: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes_attribute_values | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes_values {
|
||||||
|
__typename: "AttributeValue";
|
||||||
|
id: string;
|
||||||
|
name: string | null;
|
||||||
|
slug: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes {
|
||||||
|
__typename: "SelectedAttribute";
|
||||||
|
attribute: SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes_attribute;
|
||||||
|
values: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes_values | null)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_costPrice {
|
||||||
|
__typename: "Money";
|
||||||
|
amount: number;
|
||||||
|
currency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_priceOverride {
|
||||||
|
__typename: "Money";
|
||||||
|
amount: number;
|
||||||
|
currency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
alt: string;
|
||||||
|
sortOrder: number | null;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_thumbnail {
|
||||||
|
__typename: "Image";
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_variants_images {
|
||||||
|
__typename: "ProductImage";
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_variants {
|
||||||
|
__typename: "ProductVariant";
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
sku: string;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_variants_images | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_product {
|
||||||
|
__typename: "Product";
|
||||||
|
id: string;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_images | null)[] | null;
|
||||||
|
name: string;
|
||||||
|
thumbnail: SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_thumbnail | null;
|
||||||
|
variants: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_product_variants | null)[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks_warehouse {
|
||||||
|
__typename: "Warehouse";
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks {
|
||||||
|
__typename: "Stock";
|
||||||
|
id: string;
|
||||||
|
quantity: number;
|
||||||
|
warehouse: SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks_warehouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate_productVariant {
|
||||||
|
__typename: "ProductVariant";
|
||||||
|
id: string;
|
||||||
|
attributes: SimpleProductUpdate_productVariantStocksUpdate_productVariant_attributes[];
|
||||||
|
costPrice: SimpleProductUpdate_productVariantStocksUpdate_productVariant_costPrice | null;
|
||||||
|
images: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_images | null)[] | null;
|
||||||
|
name: string;
|
||||||
|
priceOverride: SimpleProductUpdate_productVariantStocksUpdate_productVariant_priceOverride | null;
|
||||||
|
product: SimpleProductUpdate_productVariantStocksUpdate_productVariant_product;
|
||||||
|
sku: string;
|
||||||
|
stocks: (SimpleProductUpdate_productVariantStocksUpdate_productVariant_stocks | null)[] | null;
|
||||||
|
trackInventory: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SimpleProductUpdate_productVariantStocksUpdate {
|
||||||
|
__typename: "ProductVariantStocksUpdate";
|
||||||
|
errors: SimpleProductUpdate_productVariantStocksUpdate_errors[];
|
||||||
|
productVariant: SimpleProductUpdate_productVariantStocksUpdate_productVariant | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface SimpleProductUpdate {
|
export interface SimpleProductUpdate {
|
||||||
productUpdate: SimpleProductUpdate_productUpdate | null;
|
productUpdate: SimpleProductUpdate_productUpdate | null;
|
||||||
productVariantUpdate: SimpleProductUpdate_productVariantUpdate | null;
|
productVariantUpdate: SimpleProductUpdate_productVariantUpdate | null;
|
||||||
|
productVariantStocksCreate: SimpleProductUpdate_productVariantStocksCreate | null;
|
||||||
|
productVariantStocksDelete: SimpleProductUpdate_productVariantStocksDelete | null;
|
||||||
|
productVariantStocksUpdate: SimpleProductUpdate_productVariantStocksUpdate | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SimpleProductUpdateVariables {
|
export interface SimpleProductUpdateVariables {
|
||||||
|
@ -334,4 +705,7 @@ export interface SimpleProductUpdateVariables {
|
||||||
productVariantId: string;
|
productVariantId: string;
|
||||||
productVariantInput: ProductVariantInput;
|
productVariantInput: ProductVariantInput;
|
||||||
seo?: SeoInput | null;
|
seo?: SeoInput | null;
|
||||||
|
addStocks: StockInput[];
|
||||||
|
deleteStocks: string[];
|
||||||
|
updateStocks: StockInput[];
|
||||||
}
|
}
|
||||||
|
|
15
src/products/types/StockErrorFragment.ts
Normal file
15
src/products/types/StockErrorFragment.ts
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/* tslint:disable */
|
||||||
|
/* eslint-disable */
|
||||||
|
// This file was automatically generated and should not be edited.
|
||||||
|
|
||||||
|
import { StockErrorCode } from "./../../types/globalTypes";
|
||||||
|
|
||||||
|
// ====================================================
|
||||||
|
// GraphQL fragment: StockErrorFragment
|
||||||
|
// ====================================================
|
||||||
|
|
||||||
|
export interface StockErrorFragment {
|
||||||
|
__typename: "StockError";
|
||||||
|
code: StockErrorCode;
|
||||||
|
field: string | null;
|
||||||
|
}
|
|
@ -88,8 +88,8 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
const [addOrRemoveStocks, addOrRemoveStocksOpts] = useAddOrRemoveStocks({
|
const [addOrRemoveStocks, addOrRemoveStocksOpts] = useAddOrRemoveStocks({
|
||||||
onCompleted: data => {
|
onCompleted: data => {
|
||||||
if (
|
if (
|
||||||
data.productVariantStocksCreate.bulkStockErrors.length === 0 &&
|
data.productVariantStocksCreate.errors.length === 0 &&
|
||||||
data.productVariantStocksDelete.stockErrors.length === 0
|
data.productVariantStocksDelete.errors.length === 0
|
||||||
) {
|
) {
|
||||||
notify({
|
notify({
|
||||||
text: intl.formatMessage(commonMessages.savedChanges)
|
text: intl.formatMessage(commonMessages.savedChanges)
|
||||||
|
@ -376,11 +376,12 @@ export const ProductUpdate: React.FC<ProductUpdateProps> = ({ id, params }) => {
|
||||||
{!product?.productType?.hasVariants && (
|
{!product?.productType?.hasVariants && (
|
||||||
<ProductWarehousesDialog
|
<ProductWarehousesDialog
|
||||||
confirmButtonState={addOrRemoveStocksOpts.status}
|
confirmButtonState={addOrRemoveStocksOpts.status}
|
||||||
|
disabled={addOrRemoveStocksOpts.loading}
|
||||||
errors={[
|
errors={[
|
||||||
...(addOrRemoveStocksOpts.data
|
...(addOrRemoveStocksOpts.data
|
||||||
?.productVariantStocksCreate.bulkStockErrors || []),
|
?.productVariantStocksCreate.errors || []),
|
||||||
addOrRemoveStocksOpts.data?.productVariantStocksDelete
|
...(addOrRemoveStocksOpts.data
|
||||||
.stockErrors || []
|
?.productVariantStocksDelete.errors || [])
|
||||||
]}
|
]}
|
||||||
onClose={closeModal}
|
onClose={closeModal}
|
||||||
stocks={product?.variants[0].stocks || []}
|
stocks={product?.variants[0].stocks || []}
|
||||||
|
|
|
@ -40,11 +40,17 @@ export function createUpdateHandler(
|
||||||
} else {
|
} else {
|
||||||
updateSimpleProduct({
|
updateSimpleProduct({
|
||||||
...productVariables,
|
...productVariables,
|
||||||
|
addStocks: [],
|
||||||
|
deleteStocks: [],
|
||||||
productVariantId: product.variants[0].id,
|
productVariantId: product.variants[0].id,
|
||||||
productVariantInput: {
|
productVariantInput: {
|
||||||
sku: data.sku,
|
sku: data.sku,
|
||||||
trackInventory: data.trackInventory
|
trackInventory: data.trackInventory
|
||||||
}
|
},
|
||||||
|
updateStocks: data.stocks.map(stock => ({
|
||||||
|
quantity: parseInt(stock.value, 0),
|
||||||
|
warehouse: stock.id
|
||||||
|
}))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue