Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add attribute mutations

dominik-zeglen2c6e29358b2e
diff --git a/saleor/static/dashboard-next/productTypes/containers/AttributeCreate.tsx b/saleor/static/dashboard-next/productTypes/containers/AttributeCreate.tsx
new file mode 100644
index 0000000000..288792b2a1
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/containers/AttributeCreate.tsx
@@ -0,0 +1,35 @@
+import * as React from "react";
+
+import {
+ PartialMutationProviderProps,
+ PartialMutationProviderRenderProps
+} from "../..";
+import { TypedAttributeCreateMutation } from "../mutations";
+import {
+ AttributeCreate,
+ AttributeCreateVariables
+} from "../types/AttributeCreate";
+
+interface AttributeCreateProviderProps extends PartialMutationProviderProps {
+ children: PartialMutationProviderRenderProps<
+ AttributeCreate,
+ AttributeCreateVariables
+ >;
+}
+
+const AttributeCreateProvider: React.StatelessComponent<
+ AttributeCreateProviderProps
+> = ({ children, onError, onSuccess }) => (
+ <TypedAttributeCreateMutation onCompleted={onSuccess} onError={onError}>
+ {(mutate, { data, loading, error }) => {
+ return children({
+ data,
+ error,
+ loading,
+ mutate
+ });
+ }}
+ </TypedAttributeCreateMutation>
+);
+
+export default AttributeCreateProvider;
diff --git a/saleor/static/dashboard-next/productTypes/containers/AttributeDelete.tsx b/saleor/static/dashboard-next/productTypes/containers/AttributeDelete.tsx
new file mode 100644
index 0000000000..ee797e8a85
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/containers/AttributeDelete.tsx
@@ -0,0 +1,35 @@
+import * as React from "react";
+
+import {
+ PartialMutationProviderProps,
+ PartialMutationProviderRenderProps
+} from "../..";
+import { TypedAttributeDeleteMutation } from "../mutations";
+import {
+ AttributeDelete,
+ AttributeDeleteVariables
+} from "../types/AttributeDelete";
+
+interface AttributeDeleteProviderProps extends PartialMutationProviderProps {
+ children: PartialMutationProviderRenderProps<
+ AttributeDelete,
+ AttributeDeleteVariables
+ >;
+}
+
+const AttributeDeleteProvider: React.StatelessComponent<
+ AttributeDeleteProviderProps
+> = ({ children, onError, onSuccess }) => (
+ <TypedAttributeDeleteMutation onCompleted={onSuccess} onError={onError}>
+ {(mutate, { data, loading, error }) => {
+ return children({
+ data,
+ error,
+ loading,
+ mutate
+ });
+ }}
+ </TypedAttributeDeleteMutation>
+);
+
+export default AttributeDeleteProvider;
diff --git a/saleor/static/dashboard-next/productTypes/containers/AttributeUpdate.tsx b/saleor/static/dashboard-next/productTypes/containers/AttributeUpdate.tsx
new file mode 100644
index 0000000000..13d86ebac5
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/containers/AttributeUpdate.tsx
@@ -0,0 +1,35 @@
+import * as React from "react";
+
+import {
+ PartialMutationProviderProps,
+ PartialMutationProviderRenderProps
+} from "../..";
+import { TypedAttributeUpdateMutation } from "../mutations";
+import {
+ AttributeUpdate,
+ AttributeUpdateVariables
+} from "../types/AttributeUpdate";
+
+interface AttributeUpdateProviderProps extends PartialMutationProviderProps {
+ children: PartialMutationProviderRenderProps<
+ AttributeUpdate,
+ AttributeUpdateVariables
+ >;
+}
+
+const AttributeUpdateProvider: React.StatelessComponent<
+ AttributeUpdateProviderProps
+> = ({ children, onError, onSuccess }) => (
+ <TypedAttributeUpdateMutation onCompleted={onSuccess} onError={onError}>
+ {(mutate, { data, loading, error }) => {
+ return children({
+ data,
+ error,
+ loading,
+ mutate
+ });
+ }}
+ </TypedAttributeUpdateMutation>
+);
+
+export default AttributeUpdateProvider;
diff --git a/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx b/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx
index 51405e7460..c328a1f035 100644
--- a/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx
+++ b/saleor/static/dashboard-next/productTypes/containers/ProductTypeOperations.tsx
@@ -5,6 +5,18 @@ import {
MutationProviderRenderProps,
PartialMutationProviderOutput
} from "../..";
+import {
+ AttributeCreate,
+ AttributeCreateVariables
+} from "../types/AttributeCreate";
+import {
+ AttributeDelete,
+ AttributeDeleteVariables
+} from "../types/AttributeDelete";
+import {
+ AttributeUpdate,
+ AttributeUpdateVariables
+} from "../types/AttributeUpdate";
import {
ProductTypeDelete,
ProductTypeDeleteVariables
@@ -13,49 +25,124 @@ import {
ProductTypeUpdate,
ProductTypeUpdateVariables
} from "../types/ProductTypeUpdate";
+import AttributeCreateProvider from "./AttributeCreate";
+import AttributeDeleteProvider from "./AttributeDelete";
+import AttributeUpdateProvider from "./AttributeUpdate";
import ProductTypeDeleteProvider from "./ProductTypeDelete";
import ProductTypeUpdateProvider from "./ProductTypeUpdate";
interface ProductTypeOperationsProps extends MutationProviderProps {
id: string;
children: MutationProviderRenderProps<{
+ attributeCreate: PartialMutationProviderOutput<
+ AttributeCreate,
+ AttributeCreateVariables
+ >;
+ deleteAttribute: PartialMutationProviderOutput<
+ AttributeDelete,
+ AttributeDeleteVariables
+ >;
deleteProductType: PartialMutationProviderOutput<
ProductTypeDelete,
ProductTypeDeleteVariables
>;
+ updateAttribute: PartialMutationProviderOutput<
+ AttributeUpdate,
+ AttributeUpdateVariables
+ >;
updateProductType: PartialMutationProviderOutput<
ProductTypeUpdate,
ProductTypeUpdateVariables
>;
loading: boolean;
}>;
- onDelete?: (data: ProductTypeDelete) => void;
- onUpdate?: (data: ProductTypeUpdate) => void;
+ onAttributeCreate: (data: AttributeCreate) => void;
+ onAttributeDelete: (data: AttributeDelete) => void;
+ onAttributeUpdate: (data: AttributeUpdate) => void;
+ onProductTypeDelete: (data: ProductTypeDelete) => void;
+ onProductTypeUpdate: (data: ProductTypeUpdate) => void;
}
const ProductTypeOperations: React.StatelessComponent<
ProductTypeOperationsProps
-> = ({ id, children, onError, onDelete, onUpdate }) => {
+> = ({
+ id,
+ children,
+ onAttributeCreate,
+ onAttributeDelete,
+ onAttributeUpdate,
+ onError,
+ onProductTypeDelete,
+ onProductTypeUpdate
+}) => {
return (
- <ProductTypeDeleteProvider id={id} onError={onError} onSuccess={onDelete}>
+ <ProductTypeDeleteProvider
+ id={id}
+ onError={onError}
+ onSuccess={onProductTypeDelete}
+ >
{deleteProductType => (
- <ProductTypeUpdateProvider onError={onError} onSuccess={onUpdate}>
- {updateProductType =>
- children({
- deleteProductType: {
- data: deleteProductType.data,
- loading: deleteProductType.loading,
- mutate: () => deleteProductType.mutate({ variables: { id } })
- },
- errors: [],
- loading: deleteProductType.loading,
- updateProductType: {
- data: updateProductType.data,
- loading: updateProductType.loading,
- mutate: variables => updateProductType.mutate({ variables })
- }
- })
- }
+ <ProductTypeUpdateProvider
+ onError={onError}
+ onSuccess={onProductTypeUpdate}
+ >
+ {updateProductType => (
+ <AttributeCreateProvider
+ onError={onError}
+ onSuccess={onAttributeCreate}
+ >
+ {createAttribute => (
+ <AttributeDeleteProvider
+ onError={onError}
+ onSuccess={onAttributeDelete}
+ >
+ {deleteAttribute => (
+ <AttributeUpdateProvider
+ onError={onError}
+ onSuccess={onAttributeUpdate}
+ >
+ {updateAttribute =>
+ children({
+ attributeCreate: {
+ data: createAttribute.data,
+ loading: createAttribute.loading,
+ mutate: variables =>
+ createAttribute.mutate({ variables })
+ },
+ deleteAttribute: {
+ data: deleteAttribute.data,
+ loading: deleteAttribute.loading,
+ mutate: variables =>
+ deleteAttribute.mutate({ variables })
+ },
+ deleteProductType: {
+ data: deleteProductType.data,
+ loading: deleteProductType.loading,
+ mutate: () =>
+ deleteProductType.mutate({ variables: { id } })
+ },
+ errors: [],
+ loading: deleteProductType.loading,
+ updateAttribute: {
+ data: updateAttribute.data,
+ loading: updateAttribute.loading,
+ mutate: variables =>
+ updateAttribute.mutate({ variables })
+ },
+ updateProductType: {
+ data: updateProductType.data,
+ loading: updateProductType.loading,
+ mutate: variables =>
+ updateProductType.mutate({ variables })
+ }
+ })
+ }
+ </AttributeUpdateProvider>
+ )}
+ </AttributeDeleteProvider>
+ )}
+ </AttributeCreateProvider>
+ )}
</ProductTypeUpdateProvider>
)}
</ProductTypeDeleteProvider>
diff --git a/saleor/static/dashboard-next/productTypes/mutations.ts b/saleor/static/dashboard-next/productTypes/mutations.ts
index 416f1177d7..6f01fbcc5e 100644
--- a/saleor/static/dashboard-next/productTypes/mutations.ts
+++ b/saleor/static/dashboard-next/productTypes/mutations.ts
@@ -1,6 +1,19 @@
import gql from "graphql-tag";
import { TypedMutation } from "../mutations";
+import { productTypeDetailsFragment } from "./queries";
+import {
+ AttributeCreate,
+ AttributeCreateVariables
+} from "./types/AttributeCreate";
+import {
+ AttributeDelete,
+ AttributeDeleteVariables
+} from "./types/AttributeDelete";
+import {
+ AttributeUpdate,
+ AttributeUpdateVariables
+} from "./types/AttributeUpdate";
import {
ProductTypeCreate,
ProductTypeCreateVariables
@@ -33,6 +46,7 @@ export const TypedProductTypeDeleteMutation = TypedMutation<
>(productTypeDeleteMutation);
export const productTypeUpdateMutation = gql`
+ ${productTypeDetailsFragment}
mutation ProductTypeUpdate($id: ID!, $input: ProductTypeInput!) {
productTypeUpdate(id: $id, input: $input) {
errors {
@@ -40,21 +54,7 @@ export const productTypeUpdateMutation = gql`
message
}
productType {
- id
- name
- hasVariants
- taxRate
- productAttributes {
- id
- slug
- name
- }
- variantAttributes {
- id
- slug
- name
- }
- isShippingRequired
+ ...ProductTypeDetailsFragment
}
}
}
@@ -65,6 +65,7 @@ export const TypedProductTypeUpdateMutation = TypedMutation<
>(productTypeUpdateMutation);
export const productTypeCreateMutation = gql`
+ ${productTypeDetailsFragment}
mutation ProductTypeCreate($input: ProductTypeInput!) {
productTypeCreate(input: $input) {
errors {
@@ -72,20 +73,7 @@ export const productTypeCreateMutation = gql`
message
}
productType {
- id
- name
- hasVariants
- productAttributes {
- id
- slug
- name
- }
- variantAttributes {
- id
- slug
- name
- }
- isShippingRequired
+ ...ProductTypeDetailsFragment
}
}
}
@@ -94,3 +82,52 @@ export const TypedProductTypeCreateMutation = TypedMutation<
ProductTypeCreate,
ProductTypeCreateVariables
>(productTypeCreateMutation);
+
+export const attributeCreateMutation = gql`
+ mutation AttributeCreate(
+ $id: ID!
+ $input: AttributeCreateInput!
+ $type: AttributeTypeEnum!
+ ) {
+ attributeCreate(id: $id, input: $input, type: $type) {
+ errors {
+ field
+ message
+ }
+ }
+ }
+`;
+export const TypedAttributeCreateMutation = TypedMutation<
+ AttributeCreate,
+ AttributeCreateVariables
+>(attributeCreateMutation);
+
+export const attributeUpdateMutation = gql`
+ mutation AttributeUpdate($id: ID!, $input: AttributeUpdateInput!) {
+ attributeUpdate(id: $id, input: $input) {
+ errors {
+ field
+ message
+ }
+ }
+ }
+`;
+export const TypedAttributeUpdateMutation = TypedMutation<
+ AttributeUpdate,
+ AttributeUpdateVariables
+>(attributeUpdateMutation);
+
+export const attributeDeleteMutation = gql`
+ mutation AttributeDelete($id: ID!) {
+ attributeDelete(id: $id) {
+ errors {
+ field
+ message
+ }
+ }
+ }
+`;
+export const TypedAttributeDeleteMutation = TypedMutation<
+ AttributeDelete,
+ AttributeDeleteVariables
+>(attributeDeleteMutation);
diff --git a/saleor/static/dashboard-next/productTypes/types/AttributeCreate.ts b/saleor/static/dashboard-next/productTypes/types/AttributeCreate.ts
new file mode 100644
index 0000000000..48a2b83f70
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/types/AttributeCreate.ts
@@ -0,0 +1,29 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { AttributeCreateInput, AttributeTypeEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: AttributeCreate
+// ====================================================
+
+export interface AttributeCreate_attributeCreate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface AttributeCreate_attributeCreate {
+ __typename: "AttributeCreate";
+ errors: (AttributeCreate_attributeCreate_errors | null)[] | null;
+}
+
+export interface AttributeCreate {
+ attributeCreate: AttributeCreate_attributeCreate | null;
+}
+
+export interface AttributeCreateVariables {
+ id: string;
+ input: AttributeCreateInput;
+ type: AttributeTypeEnum;
+}
diff --git a/saleor/static/dashboard-next/productTypes/types/AttributeDelete.ts b/saleor/static/dashboard-next/productTypes/types/AttributeDelete.ts
new file mode 100644
index 0000000000..7dd5091c49
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/types/AttributeDelete.ts
@@ -0,0 +1,25 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL mutation operation: AttributeDelete
+// ====================================================
+
+export interface AttributeDelete_attributeDelete_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface AttributeDelete_attributeDelete {
+ __typename: "AttributeDelete";
+ errors: (AttributeDelete_attributeDelete_errors | null)[] | null;
+}
+
+export interface AttributeDelete {
+ attributeDelete: AttributeDelete_attributeDelete | null;
+}
+
+export interface AttributeDeleteVariables {
+ id: string;
+}
diff --git a/saleor/static/dashboard-next/productTypes/types/AttributeUpdate.ts b/saleor/static/dashboard-next/productTypes/types/AttributeUpdate.ts
new file mode 100644
index 0000000000..3df7c1b38d
--- /dev/null
+++ b/saleor/static/dashboard-next/productTypes/types/AttributeUpdate.ts
@@ -0,0 +1,28 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { AttributeUpdateInput } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: AttributeUpdate
+// ====================================================
+
+export interface AttributeUpdate_attributeUpdate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface AttributeUpdate_attributeUpdate {
+ __typename: "AttributeUpdate";
+ errors: (AttributeUpdate_attributeUpdate_errors | null)[] | null;
+}
+
+export interface AttributeUpdate {
+ attributeUpdate: AttributeUpdate_attributeUpdate | null;
+}
+
+export interface AttributeUpdateVariables {
+ id: string;
+ input: AttributeUpdateInput;
+}
diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts
index 270df45bce..cf1780fab1 100644
--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts
+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeCreate.ts
@@ -1,7 +1,7 @@
/* tslint:disable */
// This file was automatically generated and should not be edited.
-import { ProductTypeInput } from "./../../types/globalTypes";
+import { ProductTypeInput, TaxRateType } from "./../../types/globalTypes";
// ====================================================
// GraphQL mutation operation: ProductTypeCreate
@@ -13,18 +13,40 @@ export interface ProductTypeCreate_productTypeCreate_errors {
message: string | null;
}
+export interface ProductTypeCreate_productTypeCreate_productType_productAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ slug: string | null;
+}
+
export interface ProductTypeCreate_productTypeCreate_productType_productAttributes {
__typename: "Attribute";
id: string;
+ name: string | null;
slug: string | null;
+ values: (ProductTypeCreate_productTypeCreate_productType_productAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeCreate_productTypeCreate_productType_variantAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
name: string | null;
+ slug: string | null;
}
export interface ProductTypeCreate_productTypeCreate_productType_variantAttributes {
__typename: "Attribute";
id: string;
- slug: string | null;
name: string | null;
+ slug: string | null;
+ values: (ProductTypeCreate_productTypeCreate_productType_variantAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeCreate_productTypeCreate_productType_weight {
+ __typename: "Weight";
+ unit: string;
+ value: number;
}
export interface ProductTypeCreate_productTypeCreate_productType {
@@ -32,9 +54,11 @@ export interface ProductTypeCreate_productTypeCreate_productType {
id: string;
name: string;
hasVariants: boolean;
+ isShippingRequired: boolean;
+ taxRate: TaxRateType | null;
productAttributes: (ProductTypeCreate_productTypeCreate_productType_productAttributes | null)[] | null;
variantAttributes: (ProductTypeCreate_productTypeCreate_productType_variantAttributes | null)[] | null;
- isShippingRequired: boolean;
+ weight: ProductTypeCreate_productTypeCreate_productType_weight | null;
}
export interface ProductTypeCreate_productTypeCreate {
diff --git a/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts b/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts
index 583799d63a..d5c75ec5e6 100644
--- a/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts
+++ b/saleor/static/dashboard-next/productTypes/types/ProductTypeUpdate.ts
@@ -13,18 +13,40 @@ export interface ProductTypeUpdate_productTypeUpdate_errors {
message: string | null;
}
+export interface ProductTypeUpdate_productTypeUpdate_productType_productAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ slug: string | null;
+}
+
export interface ProductTypeUpdate_productTypeUpdate_productType_productAttributes {
__typename: "Attribute";
id: string;
+ name: string | null;
slug: string | null;
+ values: (ProductTypeUpdate_productTypeUpdate_productType_productAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeUpdate_productTypeUpdate_productType_variantAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
name: string | null;
+ slug: string | null;
}
export interface ProductTypeUpdate_productTypeUpdate_productType_variantAttributes {
__typename: "Attribute";
id: string;
- slug: string | null;
name: string | null;
+ slug: string | null;
+ values: (ProductTypeUpdate_productTypeUpdate_productType_variantAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeUpdate_productTypeUpdate_productType_weight {
+ __typename: "Weight";
+ unit: string;
+ value: number;
}
export interface ProductTypeUpdate_productTypeUpdate_productType {
@@ -32,10 +54,11 @@ export interface ProductTypeUpdate_productTypeUpdate_productType {
id: string;
name: string;
hasVariants: boolean;
+ isShippingRequired: boolean;
taxRate: TaxRateType | null;
productAttributes: (ProductTypeUpdate_productTypeUpdate_productType_productAttributes | null)[] | null;
variantAttributes: (ProductTypeUpdate_productTypeUpdate_productType_variantAttributes | null)[] | null;
- isShippingRequired: boolean;
+ weight: ProductTypeUpdate_productTypeUpdate_productType_weight | null;
}
export interface ProductTypeUpdate_productTypeUpdate {
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
index d40664c43b..f295731280 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate.tsx
@@ -2,7 +2,6 @@ import * as React from "react";
import Navigator from "../../components/Navigator";
import { productTypeListUrl } from "..";
-import ErrorMessageCard from "../../components/ErrorMessageCard";
import Messages from "../../components/messages";
import i18n from "../../i18n";
import { maybe } from "../../misc";
@@ -11,6 +10,9 @@ import ProductTypeDetailsPage, {
} from "../components/ProductTypeDetailsPage";
import ProductTypeOperations from "../containers/ProductTypeOperations";
import { TypedProductTypeDetailsQuery } from "../queries";
+import { AttributeCreate } from "../types/AttributeCreate";
+import { AttributeDelete } from "../types/AttributeDelete";
+import { AttributeUpdate } from "../types/AttributeUpdate";
import { ProductTypeDelete } from "../types/ProductTypeDelete";
import { ProductTypeUpdate as ProductTypeUpdateMutation } from "../types/ProductTypeUpdate";
@@ -26,28 +28,54 @@ export const ProductTypeUpdate: React.StatelessComponent<
<Navigator>
{navigate => (
<TypedProductTypeDetailsQuery variables={{ id }}>
- {({ data, error, loading: dataLoading }) => {
- if (error) {
- return (
- <ErrorMessageCard
- message={i18n.t("Something went terribly wrong")}
- />
- );
- }
- const handleDeleteSuccess = (deleteData: ProductTypeDelete) => {
+ {({ data, loading: dataLoading }) => {
+ const handleAttributeCreateSuccess = (data: AttributeCreate) => {
+ if (!maybe(() => data.attributeCreate.errors.length)) {
+ pushMessage({
+ text: i18n.t("Attribute created", {
+ context: "notification"
+ })
+ });
+ }
+ };
+ const handleAttributeDeleteSuccess = (data: AttributeDelete) => {
+ if (!maybe(() => data.attributeDelete.errors.length)) {
+ pushMessage({
+ text: i18n.t("Attribute deleted", {
+ context: "notification"
+ })
+ });
+ }
+ };
+ const handleAttributeUpdateSuccess = (data: AttributeUpdate) => {
+ if (!maybe(() => data.attributeUpdate.errors.length)) {
+ pushMessage({
+ text: i18n.t("Attribute updated", {
+ context: "notification"
+ })
+ });
+ }
+ };
+ const handleProductTypeDeleteSuccess = (
+ deleteData: ProductTypeDelete
+ ) => {
if (deleteData.productTypeDelete.errors.length === 0) {
pushMessage({
- text: i18n.t("Successfully deleted product type")
+ text: i18n.t("Product type deleted", {
+ context: "notification"
+ })
});
navigate(productTypeListUrl);
}
};
- const handleUpdateSuccess = (
+ const handleProductTypeUpdateSuccess = (
updateData: ProductTypeUpdateMutation
) => {
if (updateData.productTypeUpdate.errors.length === 0) {
pushMessage({
- text: i18n.t("Successfully updated product type")
+ text: i18n.t("Product type updated", {
+ context: "notification"
+ })
});
}
};
@@ -55,8 +83,11 @@ export const ProductTypeUpdate: React.StatelessComponent<
return (
<ProductTypeOperations
id={id}
- onDelete={handleDeleteSuccess}
- onUpdate={handleUpdateSuccess}
+ onAttributeCreate={handleAttributeCreateSuccess}
+ onAttributeDelete={handleAttributeDeleteSuccess}
+ onAttributeUpdate={handleAttributeUpdateSuccess}
+ onProductTypeDelete={handleProductTypeDeleteSuccess}
+ onProductTypeUpdate={handleProductTypeUpdateSuccess}
>
{({
deleteProductType,
@@ -64,8 +95,11 @@ export const ProductTypeUpdate: React.StatelessComponent<
loading: mutationLoading,
updateProductType
}) => {
- const handleDelete = () => deleteProductType.mutate({ id });
- const handleUpdate = (formData: ProductTypeForm) => {
+ const handleProductTypeDelete = () =>
+ deleteProductType.mutate({ id });
+ const handleProductTypeUpdate = (
+ formData: ProductTypeForm
+ ) => {
updateProductType.mutate({
id,
input: {
@@ -101,8 +135,8 @@ export const ProductTypeUpdate: React.StatelessComponent<
onAttributeAdd={() => undefined}
onAttributeUpdate={() => undefined}
onBack={() => navigate(productTypeListUrl)}
- onDelete={handleDelete}
- onSubmit={handleUpdate}
+ onDelete={handleProductTypeDelete}
+ onSubmit={handleProductTypeUpdate}
/>
);
}}
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index a0aad36b2c..554d65faec 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -5,6 +5,11 @@
// START Enums and Input Objects
//==============================================================
+export enum AttributeTypeEnum {
+ PRODUCT = "PRODUCT",
+ VARIANT = "VARIANT",
+}
+
export enum AuthorizationKeyType {
FACEBOOK = "FACEBOOK",
GOOGLE_OAUTH2 = "GOOGLE_OAUTH2",
@@ -121,14 +126,30 @@ export interface AddressInput {
phone?: string | null;
}
+export interface AttributeCreateInput {
+ name: string;
+ values?: (AttributeCreateValueInput | null)[] | null;
+}
+
+export interface AttributeCreateValueInput {
+ name: string;
+ value: string;
+}
+
+export interface AttributeUpdateInput {
+ name?: string | null;
+ removeValues: (string | null)[];
+ addValues: (AttributeCreateValueInput | null)[];
+}
+
export interface AttributeValueInput {
slug: string;
value: string;
}
export interface AuthorizationKeyInput {
- key?: string | null;
- password?: string | null;
+ key: string;
+ password: string;
}
export interface DraftOrderInput {