serviceHookSettingsForm.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 {Organization, 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. organization: Organization;
  16. projectId: string;
  17. hookId?: string;
  18. };
  19. export default class ServiceHookSettingsForm extends Component<Props> {
  20. onSubmitSuccess = () => {
  21. const {organization, projectId} = this.props;
  22. browserHistory.push(
  23. normalizeUrl(`/settings/${organization.slug}/projects/${projectId}/hooks/`)
  24. );
  25. };
  26. render() {
  27. const {initialData, organization, projectId, hookId} = this.props;
  28. const endpoint = hookId
  29. ? `/projects/${organization.slug}/${projectId}/hooks/${hookId}/`
  30. : `/projects/${organization.slug}/${projectId}/hooks/`;
  31. return (
  32. <Panel>
  33. <ApiForm
  34. apiMethod={hookId ? 'PUT' : 'POST'}
  35. apiEndpoint={endpoint}
  36. initialData={initialData}
  37. onSubmitSuccess={this.onSubmitSuccess}
  38. footerStyle={{
  39. marginTop: 0,
  40. paddingRight: 20,
  41. }}
  42. submitLabel={hookId ? t('Save Changes') : t('Create Hook')}
  43. >
  44. <PanelHeader>{t('Hook Configuration')}</PanelHeader>
  45. <PanelBody>
  46. <BooleanField name="isActive" label={t('Active')} />
  47. <TextField
  48. name="url"
  49. label={t('URL')}
  50. required
  51. help={t('The URL which will receive events.')}
  52. />
  53. <FormField
  54. name="events"
  55. label={t('Events')}
  56. inline={false}
  57. help={t('The event types you wish to subscribe to.')}
  58. >
  59. {({name, value, onChange}) => (
  60. <MultipleCheckbox onChange={onChange} value={value} name={name}>
  61. {EVENT_CHOICES.map(event => (
  62. <MultipleCheckbox.Item key={event} value={event}>
  63. {event}
  64. </MultipleCheckbox.Item>
  65. ))}
  66. </MultipleCheckbox>
  67. )}
  68. </FormField>
  69. </PanelBody>
  70. </ApiForm>
  71. </Panel>
  72. );
  73. }
  74. }