Add error handling to non-existent apps (#1723)
This commit is contained in:
parent
d4a28fedf2
commit
ed262f913d
2 changed files with 32 additions and 12 deletions
|
@ -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,6 +53,7 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
|
|||
refetch();
|
||||
closeModal();
|
||||
} else {
|
||||
if (appExists) {
|
||||
errors.forEach(error =>
|
||||
notify({
|
||||
status: "error",
|
||||
|
@ -57,6 +62,7 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
const [deactivateApp, deactivateAppResult] = useAppDeactivateMutation({
|
||||
onCompleted: data => {
|
||||
|
@ -72,6 +78,7 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
|
|||
refetch();
|
||||
closeModal();
|
||||
} else {
|
||||
if (appExists) {
|
||||
errors.forEach(error =>
|
||||
notify({
|
||||
status: "error",
|
||||
|
@ -80,6 +87,7 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const [openModal, closeModal] = createDialogActionHandlers<
|
||||
|
@ -94,6 +102,10 @@ export const AppDetails: React.FC<AppDetailsProps> = ({ id, params }) => {
|
|||
deactivateApp(mutationOpts);
|
||||
};
|
||||
|
||||
if (!appExists) {
|
||||
return <NotFoundPage onBack={() => navigate(appsListPath)} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<AppActivateDialog
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue