2022-02-02 15:30:34 +00:00
|
|
|
import { appMessages } from "@saleor/apps/messages";
|
2022-01-11 12:34:48 +00:00
|
|
|
import NotFoundPage from "@saleor/components/NotFoundPage";
|
2020-07-22 10:54:15 +00:00
|
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
|
|
import useNotifier from "@saleor/hooks/useNotifier";
|
|
|
|
import React from "react";
|
|
|
|
import { useIntl } from "react-intl";
|
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
import AppPage from "../../components/AppPage";
|
2020-07-22 10:54:15 +00:00
|
|
|
import { useAppDetails } from "../../queries";
|
2022-02-02 15:30:34 +00:00
|
|
|
import { appDetailsUrl, appsListPath } from "../../urls";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
interface AppSettingsProps {
|
2020-07-22 10:54:15 +00:00
|
|
|
id: string;
|
|
|
|
}
|
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
export const AppSettings: React.FC<AppSettingsProps> = ({ id }) => {
|
2020-07-22 10:54:15 +00:00
|
|
|
const { data } = useAppDetails({
|
|
|
|
displayLoader: true,
|
|
|
|
variables: { id }
|
|
|
|
});
|
2022-01-11 12:34:48 +00:00
|
|
|
|
|
|
|
const appExists = data?.app !== null;
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const navigate = useNavigator();
|
|
|
|
const notify = useNotifier();
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2022-01-11 12:34:48 +00:00
|
|
|
if (!appExists) {
|
|
|
|
return <NotFoundPage onBack={() => navigate(appsListPath)} />;
|
|
|
|
}
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
return (
|
2022-02-02 15:30:34 +00:00
|
|
|
<AppPage
|
2020-07-22 10:54:15 +00:00
|
|
|
data={data?.app}
|
2022-02-02 15:30:34 +00:00
|
|
|
url={data?.app.configurationUrl}
|
|
|
|
navigateToAbout={() => navigate(appDetailsUrl(id))}
|
2020-07-22 10:54:15 +00:00
|
|
|
onBack={() => navigate(appsListPath)}
|
|
|
|
onError={() =>
|
|
|
|
notify({
|
|
|
|
status: "error",
|
2022-02-02 15:30:34 +00:00
|
|
|
text: intl.formatMessage(appMessages.failedToFetchAppSettings)
|
2020-07-22 10:54:15 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
export default AppSettings;
|