//@flow import React from "react"; import { compose } from "redux"; import { translate } from "react-i18next"; import injectSheet from "react-jss"; import type { Plugin } from "@scm-manager/ui-types"; import { apiClient, Button, ButtonGroup, Checkbox, ErrorNotification, Modal, Notification } from "@scm-manager/ui-components"; import classNames from "classnames"; import waitForRestart from "./waitForRestart"; import InstallSuccessNotification from "./InstallSuccessNotification"; type Props = { plugin: Plugin, refresh: () => void, onClose: () => void, // context props classes: any, t: (key: string, params?: Object) => string }; type State = { success: boolean, restart: boolean, loading: boolean, error?: Error }; const styles = { userLabelAlignment: { textAlign: "left", marginRight: 0, minWidth: "5.5em" }, userFieldFlex: { flexGrow: 4 } }; class PluginModal extends React.Component { constructor(props: Props) { super(props); this.state = { loading: false, restart: false, success: false }; } onInstallSuccess = () => { const { restart } = this.state; const { refresh, onClose } = this.props; const newState = { loading: false, error: undefined }; if (restart) { waitForRestart() .then(() => { this.setState({ ...newState, success: true }); }) .catch(error => { this.setState({ loading: false, success: false, error }); }); } else { this.setState(newState, () => { refresh(); onClose(); }); } }; install = (e: Event) => { const { restart } = this.state; const { plugin } = this.props; this.setState({ loading: true }); e.preventDefault(); apiClient .post(plugin._links.install.href + "?restart=" + restart.toString()) .then(this.onInstallSuccess) .catch(error => { this.setState({ loading: false, error: error }); }); }; footer = () => { const { onClose, t } = this.props; const { loading, error, restart, success } = this.state; let color = "primary"; let label = "plugins.modal.install"; if (restart) { color = "warning"; label = "plugins.modal.installAndRestart"; } return (