index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import {Fragment} from 'react';
  2. import {addLoadingMessage} from 'sentry/actionCreators/indicator';
  3. import {
  4. changeOrganizationSlug,
  5. removeAndRedirectToRemainingOrganization,
  6. updateOrganization,
  7. } from 'sentry/actionCreators/organizations';
  8. import {Button} from 'sentry/components/button';
  9. import Confirm from 'sentry/components/confirm';
  10. import FieldGroup from 'sentry/components/forms/fieldGroup';
  11. import List from 'sentry/components/list';
  12. import ListItem from 'sentry/components/list/listItem';
  13. import Panel from 'sentry/components/panels/panel';
  14. import PanelHeader from 'sentry/components/panels/panelHeader';
  15. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  16. import {t, tct} from 'sentry/locale';
  17. import ConfigStore from 'sentry/stores/configStore';
  18. import type {RouteComponentProps} from 'sentry/types/legacyReactRouter';
  19. import type {Organization} from 'sentry/types/organization';
  20. import {trackAnalytics} from 'sentry/utils/analytics';
  21. import useApi from 'sentry/utils/useApi';
  22. import {useNavigate} from 'sentry/utils/useNavigate';
  23. import useOrganization from 'sentry/utils/useOrganization';
  24. import useProjects from 'sentry/utils/useProjects';
  25. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  26. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  27. import PermissionAlert from 'sentry/views/settings/organization/permissionAlert';
  28. import {OrganizationRegionAction} from 'sentry/views/settings/organizationGeneralSettings/organizationRegionAction';
  29. import OrganizationSettingsForm from './organizationSettingsForm';
  30. export default function OrganizationGeneralSettings({}: RouteComponentProps<{}, {}>) {
  31. const api = useApi();
  32. const organization = useOrganization();
  33. const {projects} = useProjects();
  34. const navigate = useNavigate();
  35. const removeConfirmMessage = (
  36. <Fragment>
  37. <TextBlock>
  38. {tct(
  39. 'Removing the organization, [name] is permanent and cannot be undone! Are you sure you want to continue?',
  40. {
  41. name: organization && <strong>{organization.name}</strong>,
  42. }
  43. )}
  44. </TextBlock>
  45. {!!projects.length && (
  46. <Fragment>
  47. <TextBlock>
  48. {t('This will also remove the following associated projects:')}
  49. </TextBlock>
  50. <List symbol="bullet" data-test-id="removed-projects-list">
  51. {projects.map(project => (
  52. <ListItem key={project.slug}>{project.slug}</ListItem>
  53. ))}
  54. </List>
  55. </Fragment>
  56. )}
  57. </Fragment>
  58. );
  59. const handleSaveForm: React.ComponentProps<
  60. typeof OrganizationSettingsForm
  61. >['onSave'] = (prevData: Organization, updated: Organization) => {
  62. if (updated.slug && updated.slug !== prevData.slug) {
  63. changeOrganizationSlug(prevData, updated);
  64. if (ConfigStore.get('features').has('system:multi-region')) {
  65. const {organizationUrl} = updated.links;
  66. window.location.replace(`${organizationUrl}/settings/organization/`);
  67. } else {
  68. navigate(`/settings/${updated.slug}/`, {replace: true});
  69. }
  70. } else {
  71. if (prevData.codecovAccess !== updated.codecovAccess) {
  72. trackAnalytics('organization_settings.codecov_access_updated', {
  73. organization: updated,
  74. has_access: updated.codecovAccess,
  75. });
  76. }
  77. // This will update OrganizationStore (as well as OrganizationsStore
  78. // which is slightly incorrect because it has summaries vs a detailed org)
  79. updateOrganization(updated);
  80. }
  81. };
  82. const handleConfirmRemoveOrg = () => {
  83. if (!organization) {
  84. return;
  85. }
  86. addLoadingMessage();
  87. removeAndRedirectToRemainingOrganization(api, {
  88. orgId: organization.slug,
  89. successMessage: `${organization.name} is queued for deletion.`,
  90. errorMessage: `Error removing the ${organization.name} organization`,
  91. });
  92. };
  93. const organizationRegionInfo = OrganizationRegionAction({
  94. organization,
  95. });
  96. return (
  97. <Fragment>
  98. <SentryDocumentTitle title={t('General Settings')} orgSlug={organization.slug} />
  99. <div>
  100. <SettingsPageHeader
  101. title={t('Organization Settings')}
  102. action={organizationRegionInfo}
  103. />
  104. <PermissionAlert />
  105. <OrganizationSettingsForm initialData={organization} onSave={handleSaveForm} />
  106. {organization.access.includes('org:admin') && !organization.isDefault && (
  107. <Panel>
  108. <PanelHeader>{t('Remove Organization')}</PanelHeader>
  109. <FieldGroup
  110. label={t('Remove Organization')}
  111. help={t(
  112. 'Removing this organization will delete all data including projects and their associated events.'
  113. )}
  114. >
  115. <div>
  116. <Confirm
  117. priority="danger"
  118. confirmText={t('Remove Organization')}
  119. message={removeConfirmMessage}
  120. onConfirm={handleConfirmRemoveOrg}
  121. >
  122. <Button priority="danger">{t('Remove Organization')}</Button>
  123. </Confirm>
  124. </div>
  125. </FieldGroup>
  126. </Panel>
  127. )}
  128. </div>
  129. </Fragment>
  130. );
  131. }