index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import {RouteComponentProps} from 'react-router';
  2. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  3. import SelectField from 'sentry/components/forms/fields/selectField';
  4. import Form from 'sentry/components/forms/form';
  5. import NarrowLayout from 'sentry/components/narrowLayout';
  6. import {t, tct} from 'sentry/locale';
  7. import ConfigStore from 'sentry/stores/configStore';
  8. import {Organization, Project} from 'sentry/types';
  9. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  10. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  11. type Props = RouteComponentProps<{}, {}>;
  12. type TransferDetails = {
  13. organizations: Organization[];
  14. project: Project;
  15. };
  16. type State = {
  17. transferDetails: TransferDetails | null;
  18. } & DeprecatedAsyncView['state'];
  19. class AcceptProjectTransfer extends DeprecatedAsyncView<Props, State> {
  20. disableErrorReport = false;
  21. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  22. const query = this.props.location.query;
  23. return [['transferDetails', '/accept-transfer/', {query}]];
  24. }
  25. getTitle() {
  26. return t('Accept Project Transfer');
  27. }
  28. handleSubmit = formData => {
  29. this.api.request('/accept-transfer/', {
  30. method: 'POST',
  31. data: {
  32. data: this.props.location.query.data,
  33. organization: formData.organization,
  34. },
  35. success: () => {
  36. const orgSlug = formData.organization;
  37. const projectSlug = this.state?.transferDetails?.project.slug;
  38. const sentryUrl = ConfigStore.get('links').sentryUrl;
  39. if (!projectSlug) {
  40. window.location.href = `${sentryUrl}/organizations/${orgSlug}/projects/`;
  41. } else {
  42. window.location.href = `${sentryUrl}/organizations/${orgSlug}/settings/projects/${projectSlug}/teams/`;
  43. // done this way since we need to change subdomains
  44. }
  45. },
  46. error: error => {
  47. const errorMsg =
  48. error && error.responseJSON && typeof error.responseJSON.detail === 'string'
  49. ? error.responseJSON.detail
  50. : '';
  51. addErrorMessage(
  52. t('Unable to transfer project') + errorMsg ? `: ${errorMsg}` : ''
  53. );
  54. },
  55. });
  56. };
  57. renderError(error) {
  58. let disableLog = false;
  59. // Check if there is an error message with `transferDetails` endpoint
  60. // If so, show as toast and ignore, otherwise log to sentry
  61. if (error && error.responseJSON && typeof error.responseJSON.detail === 'string') {
  62. addErrorMessage(error.responseJSON.detail);
  63. disableLog = true;
  64. }
  65. return super.renderError(error, disableLog);
  66. }
  67. renderBody() {
  68. const {transferDetails} = this.state;
  69. const options = transferDetails?.organizations.map(org => ({
  70. label: org.slug,
  71. value: org.slug,
  72. }));
  73. const organization = options?.[0]?.value;
  74. return (
  75. <NarrowLayout>
  76. <SettingsPageHeader title={t('Approve Transfer Project Request')} />
  77. <p>
  78. {tct(
  79. 'Projects must be transferred to a specific [organization]. You can grant specific teams access to the project later under the [projectSettings]. (Note that granting access to at least one team is necessary for the project to appear in all parts of the UI.)',
  80. {
  81. organization: <strong>{t('Organization')}</strong>,
  82. projectSettings: <strong>{t('Project Settings')}</strong>,
  83. }
  84. )}
  85. </p>
  86. {transferDetails && (
  87. <p>
  88. {tct(
  89. 'Please select which [organization] you want for the project [project].',
  90. {
  91. organization: <strong>{t('Organization')}</strong>,
  92. project: transferDetails.project.slug,
  93. }
  94. )}
  95. </p>
  96. )}
  97. <Form
  98. onSubmit={this.handleSubmit}
  99. submitLabel={t('Transfer Project')}
  100. submitPriority="danger"
  101. initialData={organization ? {organization} : undefined}
  102. >
  103. <SelectField
  104. options={options}
  105. label={t('Organization')}
  106. name="organization"
  107. style={{borderBottom: 'none'}}
  108. />
  109. </Form>
  110. </NarrowLayout>
  111. );
  112. }
  113. }
  114. export default AcceptProjectTransfer;