serviceHookSettingsForm.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {Component} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import ApiForm from 'sentry/components/forms/apiForm';
  4. import MultipleCheckbox from 'sentry/components/forms/controls/multipleCheckbox';
  5. import BooleanField from 'sentry/components/forms/fields/booleanField';
  6. import TextField from 'sentry/components/forms/fields/textField';
  7. import FormField from 'sentry/components/forms/formField';
  8. import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels';
  9. import {t} from 'sentry/locale';
  10. import {ServiceHook} from 'sentry/types';
  11. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  12. const EVENT_CHOICES = ['event.alert', 'event.created'];
  13. type Props = {
  14. initialData: Partial<ServiceHook> & {isActive: boolean};
  15. orgId: string;
  16. projectId: string;
  17. hookId?: string;
  18. };
  19. export default class ServiceHookSettingsForm extends Component<Props> {
  20. onSubmitSuccess = () => {
  21. const {orgId, projectId} = this.props;
  22. browserHistory.push(normalizeUrl(`/settings/${orgId}/projects/${projectId}/hooks/`));
  23. };
  24. render() {
  25. const {initialData, orgId, projectId, hookId} = this.props;
  26. const endpoint = hookId
  27. ? `/projects/${orgId}/${projectId}/hooks/${hookId}/`
  28. : `/projects/${orgId}/${projectId}/hooks/`;
  29. return (
  30. <Panel>
  31. <ApiForm
  32. apiMethod={hookId ? 'PUT' : 'POST'}
  33. apiEndpoint={endpoint}
  34. initialData={initialData}
  35. onSubmitSuccess={this.onSubmitSuccess}
  36. footerStyle={{
  37. marginTop: 0,
  38. paddingRight: 20,
  39. }}
  40. submitLabel={hookId ? t('Save Changes') : t('Create Hook')}
  41. >
  42. <PanelHeader>{t('Hook Configuration')}</PanelHeader>
  43. <PanelBody>
  44. <BooleanField name="isActive" label={t('Active')} />
  45. <TextField
  46. name="url"
  47. label={t('URL')}
  48. required
  49. help={t('The URL which will receive events.')}
  50. />
  51. <FormField
  52. name="events"
  53. label={t('Events')}
  54. inline={false}
  55. help={t('The event types you wish to subscribe to.')}
  56. >
  57. {({name, value, onChange}) => (
  58. <MultipleCheckbox onChange={onChange} value={value} name={name}>
  59. {EVENT_CHOICES.map(event => (
  60. <MultipleCheckbox.Item key={event} value={event}>
  61. {event}
  62. </MultipleCheckbox.Item>
  63. ))}
  64. </MultipleCheckbox>
  65. )}
  66. </FormField>
  67. </PanelBody>
  68. </ApiForm>
  69. </Panel>
  70. );
  71. }
  72. }