index.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import {Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import {addLoadingMessage} from 'sentry/actionCreators/indicator';
  4. import {
  5. changeOrganizationSlug,
  6. removeAndRedirectToRemainingOrganization,
  7. updateOrganization,
  8. } from 'sentry/actionCreators/organizations';
  9. import {Button} from 'sentry/components/button';
  10. import Confirm from 'sentry/components/confirm';
  11. import FieldGroup from 'sentry/components/forms/fieldGroup';
  12. import List from 'sentry/components/list';
  13. import ListItem from 'sentry/components/list/listItem';
  14. import {Panel, PanelHeader} from 'sentry/components/panels';
  15. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  16. import {t, tct} from 'sentry/locale';
  17. import {Organization, Project} from 'sentry/types';
  18. import {trackAnalytics} from 'sentry/utils/analytics';
  19. import useApi from 'sentry/utils/useApi';
  20. import withOrganization from 'sentry/utils/withOrganization';
  21. import withProjects from 'sentry/utils/withProjects';
  22. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  23. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  24. import PermissionAlert from 'sentry/views/settings/organization/permissionAlert';
  25. import OrganizationSettingsForm from './organizationSettingsForm';
  26. type Props = {
  27. organization: Organization;
  28. projects: Project[];
  29. } & RouteComponentProps<{}, {}>;
  30. function OrganizationGeneralSettings(props: Props) {
  31. const api = useApi();
  32. const {organization, projects} = props;
  33. const access = new Set(organization.access);
  34. const removeConfirmMessage = (
  35. <Fragment>
  36. <TextBlock>
  37. {tct(
  38. 'Removing the organization, [name] is permanent and cannot be undone! Are you sure you want to continue?',
  39. {
  40. name: organization && <strong>{organization.name}</strong>,
  41. }
  42. )}
  43. </TextBlock>
  44. {!!projects.length && (
  45. <Fragment>
  46. <TextBlock>
  47. {t('This will also remove the following associated projects:')}
  48. </TextBlock>
  49. <List symbol="bullet" data-test-id="removed-projects-list">
  50. {projects.map(project => (
  51. <ListItem key={project.slug}>{project.slug}</ListItem>
  52. ))}
  53. </List>
  54. </Fragment>
  55. )}
  56. </Fragment>
  57. );
  58. const handleSaveForm: React.ComponentProps<
  59. typeof OrganizationSettingsForm
  60. >['onSave'] = (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. return (
  93. <Fragment>
  94. <SentryDocumentTitle title={t('General Settings')} orgSlug={organization.slug} />
  95. <div>
  96. <SettingsPageHeader title={t('Organization Settings')} />
  97. <PermissionAlert />
  98. <OrganizationSettingsForm
  99. {...props}
  100. initialData={organization}
  101. access={access}
  102. onSave={handleSaveForm}
  103. />
  104. {access.has('org:admin') && !organization.isDefault && (
  105. <Panel>
  106. <PanelHeader>{t('Remove Organization')}</PanelHeader>
  107. <FieldGroup
  108. label={t('Remove Organization')}
  109. help={t(
  110. 'Removing this organization will delete all data including projects and their associated events.'
  111. )}
  112. >
  113. <div>
  114. <Confirm
  115. priority="danger"
  116. confirmText={t('Remove Organization')}
  117. message={removeConfirmMessage}
  118. onConfirm={handleConfirmRemoveOrg}
  119. >
  120. <Button priority="danger">{t('Remove Organization')}</Button>
  121. </Confirm>
  122. </div>
  123. </FieldGroup>
  124. </Panel>
  125. )}
  126. </div>
  127. </Fragment>
  128. );
  129. }
  130. export default withProjects(withOrganization(OrganizationGeneralSettings));