index.tsx 4.2 KB

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