RequestIntegrationModal.tsx 3.5 KB

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