index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {Fragment} from 'react';
  2. import {browserHistory, RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  5. import Alert from 'sentry/components/alert';
  6. import {Button} from 'sentry/components/button';
  7. import ApiForm from 'sentry/components/forms/apiForm';
  8. import HiddenField from 'sentry/components/forms/fields/hiddenField';
  9. import LoadingIndicator from 'sentry/components/loadingIndicator';
  10. import NarrowLayout from 'sentry/components/narrowLayout';
  11. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  12. import {t, tct} from 'sentry/locale';
  13. import {space} from 'sentry/styles/space';
  14. import {Organization} from 'sentry/types';
  15. import {useApiQuery} from 'sentry/utils/queryClient';
  16. import {useParams} from 'sentry/utils/useParams';
  17. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  18. type Props = RouteComponentProps<{orgId: string}, {}>;
  19. function OrganizationRestore(_props: Props) {
  20. const params = useParams<{orgId: string}>();
  21. return (
  22. <SentryDocumentTitle title={t('Restore Organization')}>
  23. <NarrowLayout>
  24. <h3>{t('Deletion Scheduled')}</h3>
  25. <OrganizationRestoreBody orgSlug={params.orgId} />
  26. </NarrowLayout>
  27. </SentryDocumentTitle>
  28. );
  29. }
  30. type BodyProps = {
  31. orgSlug: string;
  32. };
  33. function OrganizationRestoreBody({orgSlug}: BodyProps) {
  34. const endpoint = `/organizations/${orgSlug}/`;
  35. const {isLoading, isError, data} = useApiQuery<Organization>([endpoint], {
  36. staleTime: 0,
  37. });
  38. if (isLoading) {
  39. return <LoadingIndicator />;
  40. }
  41. if (isError) {
  42. return (
  43. <Alert type="error">{t('There was an error loading your organization.')}</Alert>
  44. );
  45. }
  46. if (data.status.id === 'active') {
  47. browserHistory.replace(normalizeUrl(`/organizations/${orgSlug}/issues/`));
  48. return null;
  49. }
  50. if (data.status.id === 'pending_deletion') {
  51. return <RestoreForm organization={data} endpoint={endpoint} />;
  52. }
  53. return (
  54. <p>
  55. {t(
  56. 'Sorry, but this organization is currently in progress of being deleted. No turning back.'
  57. )}
  58. </p>
  59. );
  60. }
  61. type RestoreFormProps = {
  62. endpoint: string;
  63. organization: Organization;
  64. };
  65. function RestoreForm({endpoint, organization}: RestoreFormProps) {
  66. return (
  67. <Fragment>
  68. <ApiForm
  69. apiEndpoint={endpoint}
  70. apiMethod="PUT"
  71. submitLabel={t('Restore Organization')}
  72. onSubmitSuccess={() => {
  73. addSuccessMessage(t('Organization Restored'));
  74. // Use window.location to ensure page reloads
  75. window.location.assign(
  76. normalizeUrl(`/organizations/${organization.slug}/issues/`)
  77. );
  78. }}
  79. initialData={{cancelDeletion: 1}}
  80. hideFooter
  81. >
  82. <HiddenField name="cancelDeletion" />
  83. <p>
  84. {tct('The [name] organization is currently scheduled for deletion.', {
  85. name: <strong>{organization.slug}</strong>,
  86. })}
  87. </p>
  88. <p>
  89. {t(
  90. 'Would you like to cancel this process and restore the organization back to the original state?'
  91. )}
  92. </p>
  93. <ButtonWrapper>
  94. <Button data-test-id="form-submit" priority="primary" type="submit">
  95. {t('Restore Organization')}
  96. </Button>
  97. </ButtonWrapper>
  98. </ApiForm>
  99. <p>
  100. {t(
  101. 'Note: Restoration is available until deletion has started. Once it begins, there is no recovering the data that has been removed.'
  102. )}
  103. </p>
  104. </Fragment>
  105. );
  106. }
  107. const ButtonWrapper = styled('div')`
  108. margin-bottom: ${space(2)};
  109. `;
  110. export default OrganizationRestore;