import {Component} from 'react'; import { addErrorMessage, addLoadingMessage, addSuccessMessage, } from 'sentry/actionCreators/indicator'; import type {Client} from 'sentry/api'; import BooleanField from 'sentry/components/forms/fields/booleanField'; import TextField from 'sentry/components/forms/fields/textField'; import withApi from 'sentry/utils/withApi'; import type { AdminConfirmParams, AdminConfirmRenderProps, } from 'admin/components/adminConfirmationModal'; type Props = {api: Client; orgId: string} & AdminConfirmRenderProps; type State = { deliveryEmail: string; dryRun: boolean; targetEmail: string; }; /** * Rendered as part of a openAdminConfirmModal call */ class SendWeeklyEmailAction extends Component { state: State = { dryRun: true, targetEmail: '', deliveryEmail: '', }; componentDidMount() { this.props.setConfirmCallback(this.handleConfirm); } handleConfirm = (_params: AdminConfirmParams) => { const {targetEmail, deliveryEmail, dryRun} = this.state; addLoadingMessage('Sending Email'); this.props.api .requestPromise(`/customers/${this.props.orgId}/send-weekly-email/`, { method: 'POST', data: {targetEmail, deliveryEmail, dryRun}, }) .then(() => { addSuccessMessage('Email queued'); }) .catch(res => { if (res.status === 404) { addErrorMessage('User is not a member of the organization!'); } else { addErrorMessage(res.responseText || res.name); } }); }; render() { return (
this.setState({targetEmail})} /> this.setState({deliveryEmail})} /> this.setState({dryRun})} />
); } } export default withApi(SendWeeklyEmailAction);