Skip to content

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

Handle image upload errors

dominik-zeglenafb1570397b7
diff --git a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
index 295629d9c5..530820afc7 100644
--- a/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
+++ b/saleor/static/dashboard-next/categories/views/CategoryDetails/index.tsx
@@ -14,6 +14,7 @@ import { WindowTitle } from "../../../components/WindowTitle";
import i18n from "../../../i18n";
import { getMutationState, maybe } from "../../../misc";
import { productAddUrl, productUrl } from "../../../products/urls";
+import { CategoryInput } from "../../../types/globalTypes";
import {
CategoryPageTab,
CategoryUpdatePage
@@ -24,6 +25,7 @@ import {
} from "../../mutations";
import { TypedCategoryDetailsQuery } from "../../queries";
import { CategoryDelete } from "../../types/CategoryDelete";
+import { CategoryUpdate } from "../../types/CategoryUpdate";
import { categoryAddUrl, categoryListUrl, categoryUrl } from "../../urls";
import { categoryDeletePath, categoryDeleteUrl } from "./urls";
@@ -52,7 +54,7 @@ export const CategoryDetails: React.StatelessComponent<
{navigate => (
<Messages>
{pushMessage => {
- const onCategoryDelete = (data: CategoryDelete) => {
+ const handleCategoryDelete = (data: CategoryDelete) => {
if (data.categoryDelete.errors.length === 0) {
pushMessage({
text: i18n.t("Category deleted", {
@@ -62,6 +64,19 @@ export const CategoryDetails: React.StatelessComponent<
navigate(categoryListUrl);
}
};
+ const handleCategoryUpdate = (data: CategoryUpdate) => {
+ if (data.categoryUpdate.errors.length > 0) {
+ const backgroundImageError = data.categoryUpdate.errors.find(
+ error =>
+ error.field === ("backgroundImage" as keyof CategoryInput)
+ );
+ if (backgroundImageError) {
+ pushMessage({
+ text: backgroundImageError.message
+ });
+ }
+ }
+ };
const changeTab = (tabName: CategoryPageTab) =>
navigate(
@@ -72,9 +87,9 @@ export const CategoryDetails: React.StatelessComponent<
);
return (
- <TypedCategoryDeleteMutation onCompleted={onCategoryDelete}>
+ <TypedCategoryDeleteMutation onCompleted={handleCategoryDelete}>
{(deleteCategory, deleteResult) => (
- <TypedCategoryUpdateMutation>
+ <TypedCategoryUpdateMutation onCompleted={handleCategoryUpdate}>
{(updateCategory, updateResult) => {
const paginationState = createPaginationState(
PAGINATE_BY,
diff --git a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
index be9636e58a..4f1cd0b20d 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionCreate.tsx
@@ -5,6 +5,7 @@ import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
import { getMutationState, maybe } from "../../misc";
+import { CollectionCreateInput } from "../../types/globalTypes";
import CollectionCreatePage from "../components/CollectionCreatePage/CollectionCreatePage";
import { TypedCollectionCreateMutation } from "../mutations";
import { CreateCollection } from "../types/CreateCollection";
@@ -23,6 +24,17 @@ export const CollectionCreate: React.StatelessComponent<{}> = () => (
})
});
navigate(collectionUrl(data.collectionCreate.collection.id));
+ } else {
+ const backgroundImageError = data.collectionCreate.errors.find(
+ error =>
+ error.field ===
+ ("backgroundImage" as keyof CollectionCreateInput)
+ );
+ if (backgroundImageError) {
+ pushMessage({
+ text: backgroundImageError.message
+ });
+ }
}
};
return (
diff --git a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
index d14e58894b..93cd6a4ab1 100644
--- a/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
+++ b/saleor/static/dashboard-next/collections/views/CollectionDetails.tsx
@@ -10,6 +10,7 @@ import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
import { getMutationState, maybe } from "../../misc";
import { productUrl } from "../../products/urls";
+import { CollectionInput } from "../../types/globalTypes";
import CollectionAssignProductDialog from "../components/CollectionAssignProductDialog/CollectionAssignProductDialog";
import CollectionDetailsPage, {
CollectionDetailsPageFormData
@@ -68,6 +69,17 @@ export const CollectionDetails: React.StatelessComponent<
})
});
navigate(collectionUrl(id));
+ } else {
+ const backgroundImageError = data.collectionUpdate.errors.find(
+ error =>
+ error.field ===
+ ("backgroundImage" as keyof CollectionInput)
+ );
+ if (backgroundImageError) {
+ pushMessage({
+ text: backgroundImageError.message
+ });
+ }
}
};