createReleaseIntegrationModal.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import {Fragment} from 'react';
  2. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  3. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  4. import FieldFromConfig from 'sentry/components/forms/fieldFromConfig';
  5. import Form from 'sentry/components/forms/form';
  6. import type {Field} from 'sentry/components/forms/types';
  7. import {t} from 'sentry/locale';
  8. import type {Organization} from 'sentry/types/organization';
  9. import type {Project} from 'sentry/types/project';
  10. import useApi from 'sentry/utils/useApi';
  11. export type CreateReleaseIntegrationModalOptions = {
  12. onCancel: () => void;
  13. onCreateSuccess: (integration) => void;
  14. organization: Organization;
  15. project: Project;
  16. };
  17. type CreateReleaseIntegrationModalProps = CreateReleaseIntegrationModalOptions &
  18. ModalRenderProps;
  19. function CreateReleaseIntegrationModal({
  20. Body,
  21. Header,
  22. closeModal,
  23. project,
  24. organization,
  25. onCreateSuccess,
  26. onCancel,
  27. }: CreateReleaseIntegrationModalProps) {
  28. const api = useApi();
  29. const fields: Field[] = [
  30. {
  31. name: 'name',
  32. type: 'string',
  33. placeholder: `${project.slug} Release Integration`,
  34. label: t('Name'),
  35. help: <Fragment>{t('Name of new integration.')}</Fragment>,
  36. defaultValue: `${project.slug} Release Integration`,
  37. required: true,
  38. },
  39. ];
  40. return (
  41. <Fragment>
  42. <Header>
  43. <h3>{t('Create a Release Integration')}</h3>
  44. </Header>
  45. <Body>
  46. <Form
  47. onCancel={() => {
  48. onCancel();
  49. closeModal();
  50. }}
  51. onSubmit={async (data, onSubmitSuccess, onSubmitError) => {
  52. try {
  53. const integration = await api.requestPromise('/sentry-apps/', {
  54. method: 'POST',
  55. data: {
  56. ...data,
  57. organization: organization.slug,
  58. isAlertable: false,
  59. isInternal: true,
  60. scopes: [
  61. 'project:read',
  62. 'project:write',
  63. 'team:read',
  64. 'team:write',
  65. 'project:releases',
  66. 'event:read',
  67. 'event:write',
  68. 'org:read',
  69. 'org:write',
  70. 'member:read',
  71. 'member:write',
  72. ],
  73. verifyInstall: false,
  74. overview: `This internal integration was auto-generated to setup Releases for the ${project.slug} project. It is needed to provide the token used to create a release. If this integration is deleted, your Releases workflow will stop working!`,
  75. },
  76. });
  77. onSubmitSuccess(integration);
  78. } catch (error) {
  79. onSubmitError(error);
  80. }
  81. }}
  82. onSubmitSuccess={data => {
  83. onCreateSuccess(data);
  84. addSuccessMessage(t('Created Release Integration'));
  85. closeModal();
  86. }}
  87. onSubmitError={() => {
  88. addErrorMessage(t('Something went wrong!'));
  89. }}
  90. >
  91. {fields.map(field => (
  92. <FieldFromConfig key={field.name} field={field} />
  93. ))}
  94. </Form>
  95. </Body>
  96. </Fragment>
  97. );
  98. }
  99. export default CreateReleaseIntegrationModal;