createReleaseIntegrationModal.tsx 3.2 KB

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