saleor-dashboard/src/apps/views/AppInstall/AppInstall.tsx

113 lines
3.2 KiB
TypeScript
Raw Normal View History

Apps (#599) * create Apps view * create more app components, generate types and messages * apps refactor, update snapshots * show error message in tooltip when app installation fail * update apps components and view, add apps list to storybook * update defaultMessages * create app details view * update AppListPage with Skeleton component * create app activate/deactivate dialogs, create app details stories * add AppHeader to AppDetailsPage * update defaultMessages * update AppDetails view and components after review * create custom app details view * refactor webhooks * update webhooks fixtures * update WebhookDetailsPage story * update strings * create CustomAppCreate view and components * update AppListPage story * create AppInstall view and page * handle errors in AppInstall view * update defaultMessages * add AppInstallPage to storybook * add status prop to MessageManager * update defaultMessages * remove service account section * remove service account routes * remove as operator from notify status * add notifications for app installations * update styles for deactivated app * update app installations with local storage * update defaultMessages * AppInstall update * dd delete button to ongoin installations table * fix active installations condition * fix error messages in AppsList * update defaultMessages * add iframe to AppDetailsPage * create AppDetailsSettingsPage * install macaw-ui * apps styles clean up * update schema, fixtures * few apps updates * WebhookCreate - fix onBack button name * WebhookCreatePage story update * rename apps table from external to thirdparty * update defaultMessages * fix test, update snapshots * AppDetailsSettings - add token to headers * fix first number in local apps query * app details settings - use shop domain host * add onSettingsRowClick to InstalledApps * resolve conflicts * update changelog and messages * add noopener noreferrer do app privacy link * update snapshots * update snapshots * updates after review * update defaultMessages * CustomAppDetails - add missing notify status
2020-07-22 10:54:15 +00:00
import { WindowTitle } from "@saleor/components/WindowTitle";
import useLocalStorage from "@saleor/hooks/useLocalStorage";
import useNavigator from "@saleor/hooks/useNavigator";
import useNotifier from "@saleor/hooks/useNotifier";
import getAppErrorMessage from "@saleor/utils/errors/app";
import React, { useEffect } from "react";
import { useIntl } from "react-intl";
import { RouteComponentProps } from "react-router-dom";
import AppInstallErrorPage from "../../components/AppInstallErrorPage";
import AppInstallPage from "../../components/AppInstallPage";
import {
useAppInstallMutation,
useAppManifestFetchMutation
} from "../../mutations";
import {
AppInstallUrlQueryParams,
appsListUrl,
MANIFEST_ATTR
} from "../../urls";
interface InstallAppCreateProps extends RouteComponentProps {
params: AppInstallUrlQueryParams;
}
export const InstallAppCreate: React.FC<InstallAppCreateProps> = ({
params
}) => {
const [, setActiveInstallations] = useLocalStorage("activeInstallations", []);
const navigate = useNavigator();
const notify = useNotifier();
const intl = useIntl();
const manifestUrl = params[MANIFEST_ATTR];
const [fetchManifest, fetchManifestOpts] = useAppManifestFetchMutation({
onCompleted: data => {
if (data.appFetchManifest.errors.length) {
data.appFetchManifest.errors.forEach(error => {
notify({
status: "error",
text: getAppErrorMessage(error, intl)
});
});
}
}
});
const [installApp] = useAppInstallMutation({
onCompleted: data => {
const installationData = data.appInstall.appInstallation;
if (data.appInstall.errors.length === 0) {
setActiveInstallations(activeInstallations => [
...activeInstallations,
{ id: installationData.id, name: installationData.appName }
]);
navigateToAppsList();
} else {
data.appInstall.errors.forEach(error => {
notify({
status: "error",
text: getAppErrorMessage(error, intl)
});
});
}
}
});
const navigateToAppsList = () => navigate(appsListUrl());
const handleSubmit = () => {
const manifest = fetchManifestOpts?.data?.appFetchManifest?.manifest;
installApp({
variables: {
input: {
appName: manifest?.name,
manifestUrl,
permissions: manifest?.permissions.map(permission => permission.code)
}
}
});
};
useEffect(() => {
if (manifestUrl) {
fetchManifest({ variables: { manifestUrl } });
} else {
navigate(appsListUrl());
}
}, []);
return (
<>
<WindowTitle
title={intl.formatMessage({
defaultMessage: "Install App",
description: "window title"
})}
/>
{!!fetchManifestOpts.data?.appFetchManifest?.errors?.length ||
!!fetchManifestOpts.error ? (
<AppInstallErrorPage onBack={() => navigate("/")} />
) : (
<AppInstallPage
data={fetchManifestOpts?.data?.appFetchManifest?.manifest}
navigateToAppsList={navigateToAppsList}
onSubmit={handleSubmit}
loading={fetchManifestOpts?.loading}
/>
)}
</>
);
};
export default InstallAppCreate;