Add error handling to non-existent apps (#1723)

This commit is contained in:
Wojciech Mista 2022-01-11 13:34:48 +01:00 committed by GitHub
parent d4a28fedf2
commit ed262f913d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 12 deletions

View file

@ -1,3 +1,4 @@
import NotFoundPage from "@saleor/components/NotFoundPage";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import getAppErrorMessage from "@saleor/utils/errors/app";
@ -31,6 +32,9 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
displayLoader: true,
variables: { id }
});
const appExists = data?.app !== null;
const navigate = useNavigator();
const notify = useNotifier();
const intl = useIntl();
@ -49,12 +53,14 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
refetch();
closeModal();
} else {
errors.forEach(error =>
notify({
status: "error",
text: getAppErrorMessage(error, intl)
})
);
if (appExists) {
errors.forEach(error =>
notify({
status: "error",
text: getAppErrorMessage(error, intl)
})
);
}
}
}
});
@ -72,12 +78,14 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
refetch();
closeModal();
} else {
errors.forEach(error =>
notify({
status: "error",
text: getAppErrorMessage(error, intl)
})
);
if (appExists) {
errors.forEach(error =>
notify({
status: "error",
text: getAppErrorMessage(error, intl)
})
);
}
}
}
});
@ -94,6 +102,10 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
deactivateApp(mutationOpts);
};
if (!appExists) {
return <NotFoundPage onBack={() => navigate(appsListPath)} />;
}
return (
<>
<AppActivateDialog

View file

@ -1,3 +1,4 @@
import NotFoundPage from "@saleor/components/NotFoundPage";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import React from "react";
@ -18,10 +19,17 @@ export const AppDetailsSettings: React.FC<AppDetailsSetttingsProps> = ({
displayLoader: true,
variables: { id }
});
const appExists = data?.app !== null;
const navigate = useNavigator();
const notify = useNotifier();
const intl = useIntl();
if (!appExists) {
return <NotFoundPage onBack={() => navigate(appsListPath)} />;
}
return (
<AppDetailsSettingsPage
data={data?.app}