2017-06-26 15:25:46 +03:00
|
|
|
import React, { Component } from 'react';
|
2017-06-16 17:12:28 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-23 23:22:06 +03:00
|
|
|
import { compose, graphql } from 'react-apollo';
|
2017-06-19 15:10:57 +03:00
|
|
|
import ServicesDeleteMutation from '@graphql/ServicesDeleteMutation.gql';
|
2017-06-16 17:12:28 +03:00
|
|
|
import { Loader, ErrorMessage } from '@components/messaging';
|
|
|
|
import { ServiceDelete as ServiceDeleteComponent } from '@components/service';
|
|
|
|
import { Modal } from 'joyent-ui-toolkit';
|
|
|
|
import ServiceGql from './service-gql';
|
|
|
|
|
2017-06-26 15:25:46 +03:00
|
|
|
class ServiceDelete extends Component {
|
2017-06-16 17:12:28 +03:00
|
|
|
render() {
|
|
|
|
if (this.props.loading) {
|
|
|
|
return <Loader />;
|
|
|
|
}
|
|
|
|
if (this.props.error) {
|
|
|
|
return (
|
|
|
|
<ErrorMessage message="Oops, an error occured while loading your service." />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { service, deleteServices, history, match } = this.props;
|
|
|
|
|
|
|
|
const handleCloseClick = evt => {
|
|
|
|
const closeUrl = match.url.split('/').slice(0, -2).join('/');
|
|
|
|
history.replace(closeUrl);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleConfirmClick = evt => {
|
2017-06-26 15:25:46 +03:00
|
|
|
deleteServices(service.id).then(() => handleCloseClick());
|
2017-06-16 17:12:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal width={460} onCloseClick={handleCloseClick}>
|
|
|
|
<ServiceDeleteComponent
|
|
|
|
service={service}
|
|
|
|
onConfirmClick={handleConfirmClick}
|
|
|
|
onCancelClick={handleCloseClick}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceDelete.propTypes = {
|
|
|
|
service: PropTypes.object,
|
|
|
|
history: PropTypes.object,
|
|
|
|
deleteServices: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2017-06-19 15:10:57 +03:00
|
|
|
const DeleteServicesGql = graphql(ServicesDeleteMutation, {
|
2017-06-16 17:12:28 +03:00
|
|
|
props: ({ mutate }) => ({
|
2017-06-26 15:25:46 +03:00
|
|
|
deleteServices: serviceId =>
|
|
|
|
mutate({
|
2017-07-12 14:54:55 +03:00
|
|
|
variables: { ids: [serviceId] }
|
2017-06-26 15:25:46 +03:00
|
|
|
})
|
2017-06-16 17:12:28 +03:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
const ServiceDeleteWithData = compose(DeleteServicesGql, ServiceGql)(
|
|
|
|
ServiceDelete
|
|
|
|
);
|
|
|
|
|
|
|
|
export default ServiceDeleteWithData;
|