acceptProjectTransfer.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {RouteComponentProps} from 'react-router';
  2. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  3. import Form from 'sentry/components/forms/form';
  4. import SelectField from 'sentry/components/forms/selectField';
  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]. ' +
  73. 'You can grant specific teams access to the project later under the [projectSettings]. ' +
  74. '(Note that granting access to at least one team is necessary for the project to ' +
  75. 'appear in all parts of the UI.)',
  76. {
  77. organization: <strong>{t('Organization')}</strong>,
  78. projectSettings: <strong>{t('Project Settings')}</strong>,
  79. }
  80. )}
  81. </p>
  82. {transferDetails && (
  83. <p>
  84. {tct(
  85. 'Please select which [organization] you want for the project [project].',
  86. {
  87. organization: <strong>{t('Organization')}</strong>,
  88. project: transferDetails.project.slug,
  89. }
  90. )}
  91. </p>
  92. )}
  93. <Form
  94. onSubmit={this.handleSubmit}
  95. submitLabel={t('Transfer Project')}
  96. submitPriority="danger"
  97. initialData={organization ? {organization} : undefined}
  98. >
  99. <SelectField
  100. options={options}
  101. label={t('Organization')}
  102. name="organization"
  103. style={{borderBottom: 'none'}}
  104. />
  105. </Form>
  106. </NarrowLayout>
  107. );
  108. }
  109. }
  110. export default AcceptProjectTransfer;