/* * MIT License * * Copyright (c) 2020-present Cloudogu GmbH and Contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import React, { FC, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import classNames from "classnames"; import styled from "styled-components"; import { Plugin } from "@scm-manager/ui-types"; import { Button, ButtonGroup, Checkbox, ErrorNotification, Modal, Notification } from "@scm-manager/ui-components"; import SuccessNotification from "./SuccessNotification"; import { useInstallPlugin, useUninstallPlugin, useUpdatePlugins } from "@scm-manager/ui-api"; import { PluginAction } from "../containers/PluginsOverview"; type Props = { plugin: Plugin; pluginAction: string; onClose: () => void; }; const ListParent = styled.div` margin-right: 0; min-width: ${props => (props.pluginAction === PluginAction.INSTALL ? "5.5em" : "10em")}; text-align: left; `; const ListChild = styled.div` flex-grow: 4; `; const PluginModal: FC = ({ onClose, pluginAction, plugin }) => { const [t] = useTranslation("admin"); const [shouldRestart, setShouldRestart] = useState(false); const { isLoading: isInstalling, error: installError, install, isInstalled } = useInstallPlugin(); const { isLoading: isUninstalling, error: uninstallError, uninstall, isUninstalled } = useUninstallPlugin(); const { isLoading: isUpdating, error: updateError, update, isUpdated } = useUpdatePlugins(); const error = installError || uninstallError || updateError; const loading = isInstalling || isUninstalling || isUpdating; const isDone = isInstalled || isUninstalled || isUpdated; useEffect(() => { if (isDone && !shouldRestart) { onClose(); } }, [isDone]); const handlePluginAction = (e: Event) => { e.preventDefault(); switch (pluginAction) { case PluginAction.INSTALL: install(plugin, { restart: shouldRestart }); break; case PluginAction.UNINSTALL: uninstall(plugin, { restart: shouldRestart }); break; case PluginAction.UPDATE: update(plugin, { restart: shouldRestart }); break; default: throw new Error(`Unkown plugin action ${pluginAction}`); } }; const footer = () => { let color = pluginAction === PluginAction.UNINSTALL ? "warning" : "primary"; let label = `plugins.modal.${pluginAction}`; if (shouldRestart) { color = "warning"; label = `plugins.modal.${pluginAction}AndRestart`; } return (