import {browserHistory} from 'react-router'; import styled from '@emotion/styled'; import { addErrorMessage, addLoadingMessage, clearIndicators, } from 'sentry/actionCreators/indicator'; import Button from 'sentry/components/button'; import ButtonBar from 'sentry/components/buttonBar'; import Confirm from 'sentry/components/confirm'; import {IconDelete, IconEdit} from 'sentry/icons'; import {t} from 'sentry/locale'; import space from 'sentry/styles/space'; import {logException} from 'sentry/utils/logging'; import useApi from 'sentry/utils/useApi'; import {Monitor} from './types'; type Props = { monitor: Monitor; onUpdate: (data: Monitor) => void; orgId: string; }; const MonitorHeaderActions = ({monitor, orgId, onUpdate}: Props) => { const api = useApi(); const handleDelete = () => { const redirectPath = `/organizations/${orgId}/monitors/`; addLoadingMessage(t('Deleting Monitor...')); api .requestPromise(`/monitors/${monitor.id}/`, { method: 'DELETE', }) .then(() => { browserHistory.push(redirectPath); }) .catch(() => { addErrorMessage(t('Unable to remove monitor.')); }); }; const updateMonitor = (data: Partial) => { addLoadingMessage(); api .requestPromise(`/monitors/${monitor.id}/`, { method: 'PUT', data, }) .then(resp => { clearIndicators(); onUpdate?.(resp); }) .catch(err => { logException(err); addErrorMessage(t('Unable to update monitor.')); }); }; const toggleStatus = () => updateMonitor({ status: monitor.status === 'disabled' ? 'active' : 'disabled', }); return ( ); }; const ButtonContainer = styled('div')` margin-bottom: ${space(3)}; display: flex; flex-shrink: 1; `; export default MonitorHeaderActions;