integrationMainSettings.tsx 1.7 KB

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