// @flow import React from "react"; import { translate } from "react-i18next"; import type { Group } from "@scm-manager/ui-types"; import { Subtitle, DeleteButton, confirmAlert } from "@scm-manager/ui-components"; import { getDeleteGroupFailure, isDeleteGroupPending } from "../modules/groups"; import { connect } from "react-redux"; import { ErrorNotification } from "@scm-manager/ui-components"; type Props = { loading: boolean, error: Error, group: Group, confirmDialog?: boolean, deleteGroup: (group: Group) => void, t: string => string }; export class DeleteGroup extends React.Component { static defaultProps = { confirmDialog: true }; deleteGroup = () => { this.props.deleteGroup(this.props.group); }; confirmDelete = () => { const { t } = this.props; confirmAlert({ title: t("deleteGroup.confirmAlert.title"), message: t("deleteGroup.confirmAlert.message"), buttons: [ { label: t("deleteGroup.confirmAlert.submit"), onClick: () => this.deleteGroup() }, { label: t("deleteGroup.confirmAlert.cancel"), onClick: () => null } ] }); }; isDeletable = () => { return this.props.group._links.delete; }; render() { const { loading, error, confirmDialog, t } = this.props; const action = confirmDialog ? this.confirmDelete : this.deleteGroup; if (!this.isDeletable()) { return null; } return ( <>
); } } const mapStateToProps = (state, ownProps) => { const loading = isDeleteGroupPending(state, ownProps.group.name); const error = getDeleteGroupFailure(state, ownProps.group.name); return { loading, error }; }; export default connect(mapStateToProps)(translate("groups")(DeleteGroup));