index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import {Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  4. import {removeTeam, updateTeamSuccess} from 'sentry/actionCreators/teams';
  5. import {hasEveryAccess} from 'sentry/components/acl/access';
  6. import {Button} from 'sentry/components/button';
  7. import Confirm from 'sentry/components/confirm';
  8. import FieldGroup from 'sentry/components/forms/fieldGroup';
  9. import Form, {FormProps} from 'sentry/components/forms/form';
  10. import JsonForm from 'sentry/components/forms/jsonForm';
  11. import {Panel, PanelHeader} from 'sentry/components/panels';
  12. import teamSettingsFields from 'sentry/data/forms/teamSettingsFields';
  13. import {IconDelete} from 'sentry/icons';
  14. import {t, tct} from 'sentry/locale';
  15. import {Organization, Team} from 'sentry/types';
  16. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  17. import withOrganization from 'sentry/utils/withOrganization';
  18. import AsyncView from 'sentry/views/asyncView';
  19. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  20. type Props = RouteComponentProps<{teamId: string}, {}> & {
  21. organization: Organization;
  22. team: Team;
  23. };
  24. type State = AsyncView['state'];
  25. class TeamSettings extends AsyncView<Props, State> {
  26. getTitle() {
  27. return 'Team Settings';
  28. }
  29. getEndpoints() {
  30. return [];
  31. }
  32. handleSubmitSuccess: FormProps['onSubmitSuccess'] = (resp, _model, id) => {
  33. const {organization} = this.props;
  34. // Use the old slug when triggering the update so we correctly replace the
  35. // previous team in the store
  36. updateTeamSuccess(this.props.team.slug, resp);
  37. if (id === 'slug') {
  38. addSuccessMessage(t('Team name changed'));
  39. browserHistory.replace(
  40. normalizeUrl(`/settings/${organization.slug}/teams/${resp.slug}/settings/`)
  41. );
  42. this.setState({loading: true});
  43. }
  44. };
  45. handleRemoveTeam = async () => {
  46. const {organization, params} = this.props;
  47. try {
  48. await removeTeam(this.api, {orgId: organization.slug, teamId: params.teamId});
  49. browserHistory.replace(normalizeUrl(`/settings/${organization.slug}/teams/`));
  50. } catch {
  51. // removeTeam already displays an error message
  52. }
  53. };
  54. renderBody() {
  55. const {organization, team} = this.props;
  56. const idpProvisioned = team.flags['idp:provisioned'];
  57. const orgRoleList = organization.orgRoleList;
  58. const hasOrgRoleFlag = organization.features.includes('org-roles-for-teams');
  59. const hasTeamWrite = hasEveryAccess(['team:write'], {organization, team});
  60. const hasOrgAdmin = hasEveryAccess(['org:admin'], {organization, team});
  61. return (
  62. <Fragment>
  63. <PermissionAlert access={['team:write']} team={team} />
  64. <Form
  65. apiMethod="PUT"
  66. apiEndpoint={`/teams/${organization.slug}/${team.slug}/`}
  67. saveOnBlur
  68. allowUndo
  69. onSubmitSuccess={this.handleSubmitSuccess}
  70. onSubmitError={() => addErrorMessage(t('Unable to save change'))}
  71. initialData={{
  72. name: team.name,
  73. slug: team.slug,
  74. orgRole: team.orgRole,
  75. }}
  76. >
  77. <JsonForm
  78. additionalFieldProps={{
  79. idpProvisioned,
  80. hasOrgRoleFlag,
  81. hasTeamWrite,
  82. hasOrgAdmin,
  83. orgRoleList,
  84. }}
  85. forms={teamSettingsFields}
  86. />
  87. </Form>
  88. <Panel>
  89. <PanelHeader>{t('Remove Team')}</PanelHeader>
  90. <FieldGroup
  91. help={t(
  92. "This may affect team members' access to projects and associated alert delivery."
  93. )}
  94. >
  95. <div>
  96. <Confirm
  97. disabled={!hasOrgAdmin}
  98. onConfirm={this.handleRemoveTeam}
  99. priority="danger"
  100. message={tct('Are you sure you want to remove the team [team]?', {
  101. team: `#${team.slug}`,
  102. })}
  103. >
  104. <Button
  105. icon={<IconDelete />}
  106. priority="danger"
  107. data-test-id="button-remove-team"
  108. >
  109. {t('Remove Team')}
  110. </Button>
  111. </Confirm>
  112. </div>
  113. </FieldGroup>
  114. </Panel>
  115. </Fragment>
  116. );
  117. }
  118. }
  119. export default withOrganization(TeamSettings);