integrationMainSettings.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {Component} from 'react';
  2. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  3. import Form from 'sentry/components/forms/form';
  4. import JsonForm from 'sentry/components/forms/jsonForm';
  5. import type {Field} from 'sentry/components/forms/types';
  6. import {t} from 'sentry/locale';
  7. import type {Integration} from 'sentry/types/integrations';
  8. import type {Organization} from 'sentry/types/organization';
  9. type Props = {
  10. integration: Integration;
  11. onUpdate: () => void;
  12. organization: Organization;
  13. };
  14. type State = {
  15. integration: Integration;
  16. };
  17. class IntegrationMainSettings extends Component<Props, State> {
  18. state: State = {
  19. integration: this.props.integration,
  20. };
  21. handleSubmitSuccess = (data: Integration) => {
  22. addSuccessMessage(t('Integration updated.'));
  23. this.props.onUpdate();
  24. this.setState({integration: data});
  25. };
  26. get initialData() {
  27. const {integration} = this.props;
  28. return {
  29. name: integration.name,
  30. domain: integration.domainName || '',
  31. };
  32. }
  33. get formFields(): Field[] {
  34. const fields: any[] = [
  35. {
  36. name: 'name',
  37. type: 'string',
  38. required: false,
  39. label: t('Integration Name'),
  40. },
  41. {
  42. name: 'domain',
  43. type: 'string',
  44. required: false,
  45. label: t('Full URL'),
  46. },
  47. ];
  48. return fields;
  49. }
  50. render() {
  51. const {integration} = this.state;
  52. const {organization} = this.props;
  53. return (
  54. <Form
  55. initialData={this.initialData}
  56. apiMethod="PUT"
  57. apiEndpoint={`/organizations/${organization.slug}/integrations/${integration.id}/`}
  58. onSubmitSuccess={this.handleSubmitSuccess}
  59. submitLabel={t('Save Settings')}
  60. >
  61. <JsonForm fields={this.formFields} />
  62. </Form>
  63. );
  64. }
  65. }
  66. export default IntegrationMainSettings;