organizationSettingsForm.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {RouteComponentProps} from 'react-router';
  2. import {Location} from 'history';
  3. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  4. import {updateOrganization} from 'sentry/actionCreators/organizations';
  5. import AsyncComponent from 'sentry/components/asyncComponent';
  6. import AvatarChooser from 'sentry/components/avatarChooser';
  7. import Form from 'sentry/components/forms/form';
  8. import JsonForm from 'sentry/components/forms/jsonForm';
  9. import organizationSettingsFields from 'sentry/data/forms/organizationGeneralSettings';
  10. import {Organization, Scope} from 'sentry/types';
  11. import withOrganization from 'sentry/utils/withOrganization';
  12. type Props = {
  13. access: Set<Scope>;
  14. initialData: Organization;
  15. location: Location;
  16. onSave: (previous: Organization, updated: Record<string, any>) => void;
  17. organization: Organization;
  18. } & RouteComponentProps<{orgId: string}, {}>;
  19. type State = AsyncComponent['state'] & {
  20. authProvider: object;
  21. };
  22. class OrganizationSettingsForm extends AsyncComponent<Props, State> {
  23. getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
  24. const {organization} = this.props;
  25. return [['authProvider', `/organizations/${organization.slug}/auth-provider/`]];
  26. }
  27. render() {
  28. const {initialData, organization, onSave, access} = this.props;
  29. const {authProvider} = this.state;
  30. const endpoint = `/organizations/${organization.slug}/`;
  31. const jsonFormSettings = {
  32. additionalFieldProps: {hasSsoEnabled: !!authProvider},
  33. features: new Set(organization.features),
  34. access,
  35. location: this.props.location,
  36. disabled: !access.has('org:write'),
  37. };
  38. return (
  39. <Form
  40. data-test-id="organization-settings"
  41. apiMethod="PUT"
  42. apiEndpoint={endpoint}
  43. saveOnBlur
  44. allowUndo
  45. initialData={initialData}
  46. onSubmitSuccess={(_resp, model) => {
  47. // Special case for slug, need to forward to new slug
  48. if (typeof onSave === 'function') {
  49. onSave(initialData, model.initialData);
  50. }
  51. }}
  52. onSubmitError={() => addErrorMessage('Unable to save change')}
  53. >
  54. <JsonForm {...jsonFormSettings} forms={organizationSettingsFields} />
  55. <AvatarChooser
  56. type="organization"
  57. allowGravatar={false}
  58. endpoint={`${endpoint}avatar/`}
  59. model={initialData}
  60. onSave={updateOrganization}
  61. disabled={!access.has('org:write')}
  62. />
  63. </Form>
  64. );
  65. }
  66. }
  67. export default withOrganization(OrganizationSettingsForm);