RequestIntegrationModal.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {Fragment} from 'react';
  2. import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
  3. import type {ModalRenderProps} from 'sentry/actionCreators/modal';
  4. import {Button} from 'sentry/components/button';
  5. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  6. import TextareaField from 'sentry/components/forms/fields/textareaField';
  7. import {t} from 'sentry/locale';
  8. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  9. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  10. import type RequestIntegrationButton from './RequestIntegrationButton';
  11. type Props = {
  12. onSuccess: () => void;
  13. } & RequestIntegrationButton['props'] &
  14. ModalRenderProps &
  15. DeprecatedAsyncComponent['props'];
  16. type State = {
  17. isSending: boolean;
  18. message: string;
  19. } & DeprecatedAsyncComponent['state'];
  20. /**
  21. * This modal serves as a non-owner's confirmation step before sending
  22. * organization owners an email requesting a new organization integration. It
  23. * lets the user attach an optional message to be included in the email.
  24. */
  25. export default class RequestIntegrationModal extends DeprecatedAsyncComponent<
  26. Props,
  27. State
  28. > {
  29. state: State = {
  30. ...this.getDefaultState(),
  31. isSending: false,
  32. message: '',
  33. };
  34. sendRequest = () => {
  35. const {organization, slug, type} = this.props;
  36. const {message} = this.state;
  37. trackIntegrationAnalytics('integrations.request_install', {
  38. integration_type: type,
  39. integration: slug,
  40. organization,
  41. });
  42. const endpoint = `/organizations/${organization.slug}/integration-requests/`;
  43. this.api.request(endpoint, {
  44. method: 'POST',
  45. data: {
  46. providerSlug: slug,
  47. providerType: type,
  48. message,
  49. },
  50. success: this.handleSubmitSuccess,
  51. error: this.handleSubmitError,
  52. });
  53. };
  54. handleSubmitSuccess = () => {
  55. const {closeModal, onSuccess} = this.props;
  56. addSuccessMessage(t('Request successfully sent.'));
  57. this.setState({isSending: false});
  58. onSuccess();
  59. closeModal();
  60. };
  61. handleSubmitError = () => {
  62. addErrorMessage('Error sending the request');
  63. this.setState({isSending: false});
  64. };
  65. render() {
  66. const {Header, Body, Footer, name} = this.props;
  67. const buttonText = this.state.isSending ? t('Sending Request') : t('Send Request');
  68. return (
  69. <Fragment>
  70. <Header>
  71. <h4>{t('Request %s Installation', name)}</h4>
  72. </Header>
  73. <Body>
  74. <TextBlock>
  75. {t(
  76. 'Looks like your organization owner, manager, or admin needs to install %s. Want to send them a request?',
  77. name
  78. )}
  79. </TextBlock>
  80. <TextBlock>
  81. {t(
  82. '(Optional) You’ve got good reasons for installing the %s Integration. Share them with your organization owner.',
  83. name
  84. )}
  85. </TextBlock>
  86. <TextareaField
  87. inline={false}
  88. flexibleControlStateSize
  89. stacked
  90. name="message"
  91. type="string"
  92. onChange={value => this.setState({message: value})}
  93. placeholder={t('Optional message…')}
  94. />
  95. <TextBlock>
  96. {t(
  97. 'When you click “Send Request”, we’ll email your request to your organization’s owners. So just keep that in mind.'
  98. )}
  99. </TextBlock>
  100. </Body>
  101. <Footer>
  102. <Button onClick={this.sendRequest}>{buttonText}</Button>
  103. </Footer>
  104. </Fragment>
  105. );
  106. }
  107. }