import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { compose, graphql } from 'react-apollo'; import DeploymentGroupDeleteMutation from '@graphql/DeploymentGroupDeleteMutation.gql'; import DeploymentGroupQuery from '@graphql/DeploymentGroup.gql'; import { Loader, ErrorMessage } from '@components/messaging'; import { DeploymentGroupDelete as DeploymentGroupDeleteComponent } from '@components/deployment-group'; import { Modal, ModalHeading, Button } from 'joyent-ui-toolkit'; class DeploymentGroupDelete extends Component { constructor(props) { super(props); this.state = { error: null } } render() { const { loading, error } = this.props; const handleCloseClick = evt => { const closeUrl = match.url.split('/').slice(0, -2).join('/'); history.replace(closeUrl); }; if (loading) { return ( ); } if (error) { return ( ); } const { deploymentGroup, deleteDeploymentGroup, history, match } = this.props; if (this.state.error) { return ( Deleting a deployment group:
{deploymentGroup.name}
); } const handleConfirmClick = evt => { deleteDeploymentGroup(deploymentGroup.id) .then(() => handleCloseClick()) .catch((err) => { this.setState({ error: err }); }); }; return ( ); } } DeploymentGroupDelete.propTypes = { deploymentGroup: PropTypes.object, history: PropTypes.object, deleteDeploymentGroup: PropTypes.func.isRequired }; const DeleteDeploymentGroupGql = graphql(DeploymentGroupDeleteMutation, { props: ({ mutate }) => ({ deleteDeploymentGroup: deploymentGroupId => mutate({ variables: { id: deploymentGroupId } }) }) }); const DeploymentGroupGql = graphql(DeploymentGroupQuery, { options(props) { const params = props.match.params; const deploymentGroupSlug = params.deploymentGroup; return { variables: { deploymentGroupSlug } }; }, props: ({ data: { deploymentGroup, loading, error } }) => ({ deploymentGroup, loading, error }) }); const DeploymentGroupDeleteWithData = compose( DeleteDeploymentGroupGql, DeploymentGroupGql )(DeploymentGroupDelete); export default DeploymentGroupDeleteWithData;