index.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import {browserHistory} from 'react-router';
  4. import {addLoadingMessage} from 'sentry/actionCreators/indicator';
  5. import {
  6. changeOrganizationSlug,
  7. removeAndRedirectToRemainingOrganization,
  8. updateOrganization,
  9. } from 'sentry/actionCreators/organizations';
  10. import {Button} from 'sentry/components/button';
  11. import Confirm from 'sentry/components/confirm';
  12. import FieldGroup from 'sentry/components/forms/fieldGroup';
  13. import List from 'sentry/components/list';
  14. import ListItem from 'sentry/components/list/listItem';
  15. import Panel from 'sentry/components/panels/panel';
  16. import PanelHeader from 'sentry/components/panels/panelHeader';
  17. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  18. import {t, tct} from 'sentry/locale';
  19. import type {Organization, Project} from 'sentry/types';
  20. import {trackAnalytics} from 'sentry/utils/analytics';
  21. import useApi from 'sentry/utils/useApi';
  22. import useOrganization from 'sentry/utils/useOrganization';
  23. import withProjects from 'sentry/utils/withProjects';
  24. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  25. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  26. import PermissionAlert from 'sentry/views/settings/organization/permissionAlert';
  27. import {OrganizationRegionAction} from 'sentry/views/settings/organizationGeneralSettings/organizationRegionAction';
  28. import OrganizationSettingsForm from './organizationSettingsForm';
  29. type Props = {
  30. projects: Project[];
  31. } & RouteComponentProps<{}, {}>;
  32. function OrganizationGeneralSettings({projects}: Props) {
  33. const api = useApi();
  34. const organization = useOrganization();
  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<typeof OrganizationSettingsForm>['onSave'] =
  60. (prevData: Organization, updated: Organization) => {
  61. if (updated.slug && updated.slug !== prevData.slug) {
  62. changeOrganizationSlug(prevData, updated);
  63. if (updated.features.includes('customer-domains')) {
  64. const {organizationUrl} = updated.links;
  65. window.location.replace(`${organizationUrl}/settings/organization/`);
  66. } else {
  67. browserHistory.replace(`/settings/${updated.slug}/`);
  68. }
  69. } else {
  70. if (prevData.codecovAccess !== updated.codecovAccess) {
  71. trackAnalytics('organization_settings.codecov_access_updated', {
  72. organization: updated,
  73. has_access: updated.codecovAccess,
  74. });
  75. }
  76. // This will update OrganizationStore (as well as OrganizationsStore
  77. // which is slightly incorrect because it has summaries vs a detailed org)
  78. updateOrganization(updated);
  79. }
  80. };
  81. const handleConfirmRemoveOrg = () => {
  82. if (!organization) {
  83. return;
  84. }
  85. addLoadingMessage();
  86. removeAndRedirectToRemainingOrganization(api, {
  87. orgId: organization.slug,
  88. successMessage: `${organization.name} is queued for deletion.`,
  89. errorMessage: `Error removing the ${organization.name} organization`,
  90. });
  91. };
  92. const organizationRegionInfo = OrganizationRegionAction({
  93. organization,
  94. });
  95. return (
  96. <Fragment>
  97. <SentryDocumentTitle title={t('General Settings')} orgSlug={organization.slug} />
  98. <div>
  99. <SettingsPageHeader
  100. title={t('Organization Settings')}
  101. action={organizationRegionInfo}
  102. />
  103. <PermissionAlert />
  104. <OrganizationSettingsForm initialData={organization} onSave={handleSaveForm} />
  105. {organization.access.includes('org:admin') && !organization.isDefault && (
  106. <Panel>
  107. <PanelHeader>{t('Remove Organization')}</PanelHeader>
  108. <FieldGroup
  109. label={t('Remove Organization')}
  110. help={t(
  111. 'Removing this organization will delete all data including projects and their associated events.'
  112. )}
  113. >
  114. <div>
  115. <Confirm
  116. priority="danger"
  117. confirmText={t('Remove Organization')}
  118. message={removeConfirmMessage}
  119. onConfirm={handleConfirmRemoveOrg}
  120. >
  121. <Button priority="danger">{t('Remove Organization')}</Button>
  122. </Confirm>
  123. </div>
  124. </FieldGroup>
  125. </Panel>
  126. )}
  127. </div>
  128. </Fragment>
  129. );
  130. }
  131. export default withProjects(OrganizationGeneralSettings);