serviceHookSettingsForm.tsx 2.9 KB

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