acceptProjectTransfer.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {RouteComponentProps} from 'react-router';
  2. import {addErrorMessage, addSuccessMessage} 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 {Organization, Project} from 'sentry/types';
  8. import AsyncView from 'sentry/views/asyncView';
  9. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  10. type Props = RouteComponentProps<{}, {}>;
  11. type TransferDetails = {
  12. organizations: Organization[];
  13. project: Project;
  14. };
  15. type State = {
  16. transferDetails: TransferDetails | null;
  17. } & AsyncView['state'];
  18. class AcceptProjectTransfer extends AsyncView<Props, State> {
  19. disableErrorReport = false;
  20. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  21. const query = this.props.location.query;
  22. return [['transferDetails', '/accept-transfer/', {query}]];
  23. }
  24. getTitle() {
  25. return t('Accept Project Transfer');
  26. }
  27. handleSubmit = formData => {
  28. this.api.request('/accept-transfer/', {
  29. method: 'POST',
  30. data: {
  31. data: this.props.location.query.data,
  32. organization: formData.organization,
  33. },
  34. success: () => {
  35. const orgSlug = formData.organization;
  36. this.props.router.push(`/${orgSlug}`);
  37. addSuccessMessage(t('Project successfully transferred'));
  38. },
  39. error: error => {
  40. const errorMsg =
  41. error && error.responseJSON && typeof error.responseJSON.detail === 'string'
  42. ? error.responseJSON.detail
  43. : '';
  44. addErrorMessage(
  45. t('Unable to transfer project') + errorMsg ? `: ${errorMsg}` : ''
  46. );
  47. },
  48. });
  49. };
  50. renderError(error) {
  51. let disableLog = false;
  52. // Check if there is an error message with `transferDetails` endpoint
  53. // If so, show as toast and ignore, otherwise log to sentry
  54. if (error && error.responseJSON && typeof error.responseJSON.detail === 'string') {
  55. addErrorMessage(error.responseJSON.detail);
  56. disableLog = true;
  57. }
  58. return super.renderError(error, disableLog);
  59. }
  60. renderBody() {
  61. const {transferDetails} = this.state;
  62. const options = transferDetails?.organizations.map(org => ({
  63. label: org.slug,
  64. value: org.slug,
  65. }));
  66. const organization = options?.[0]?.value;
  67. return (
  68. <NarrowLayout>
  69. <SettingsPageHeader title={t('Approve Transfer Project Request')} />
  70. <p>
  71. {tct(
  72. '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.)',
  73. {
  74. organization: <strong>{t('Organization')}</strong>,
  75. projectSettings: <strong>{t('Project Settings')}</strong>,
  76. }
  77. )}
  78. </p>
  79. {transferDetails && (
  80. <p>
  81. {tct(
  82. 'Please select which [organization] you want for the project [project].',
  83. {
  84. organization: <strong>{t('Organization')}</strong>,
  85. project: transferDetails.project.slug,
  86. }
  87. )}
  88. </p>
  89. )}
  90. <Form
  91. onSubmit={this.handleSubmit}
  92. submitLabel={t('Transfer Project')}
  93. submitPriority="danger"
  94. initialData={organization ? {organization} : undefined}
  95. >
  96. <SelectField
  97. options={options}
  98. label={t('Organization')}
  99. name="organization"
  100. style={{borderBottom: 'none'}}
  101. />
  102. </Form>
  103. </NarrowLayout>
  104. );
  105. }
  106. }
  107. export default AcceptProjectTransfer;