RequestIntegrationButton.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import {openModal} from 'sentry/actionCreators/modal';
  4. import {Button} from 'sentry/components/button';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {IntegrationType, Organization} from 'sentry/types';
  8. import RequestIntegrationModal from './RequestIntegrationModal';
  9. type Props = {
  10. name: string;
  11. organization: Organization;
  12. slug: string;
  13. type: IntegrationType;
  14. };
  15. type State = {
  16. isOpen: boolean;
  17. isSent: boolean;
  18. };
  19. export default class RequestIntegrationButton extends Component<Props, State> {
  20. state: State = {
  21. isOpen: false,
  22. isSent: false,
  23. };
  24. openRequestModal() {
  25. this.setState({isOpen: true});
  26. openModal(
  27. renderProps => (
  28. <RequestIntegrationModal
  29. {...this.props}
  30. {...renderProps}
  31. onSuccess={() => this.setState({isSent: true})}
  32. />
  33. ),
  34. {
  35. onClose: () => this.setState({isOpen: false}),
  36. }
  37. );
  38. }
  39. render() {
  40. const {isOpen, isSent} = this.state;
  41. let buttonText;
  42. if (isOpen) {
  43. buttonText = t('Requesting Installation');
  44. } else if (isSent) {
  45. buttonText = t('Installation Requested');
  46. } else {
  47. buttonText = t('Request Installation');
  48. }
  49. return (
  50. <StyledRequestIntegrationButton
  51. data-test-id="request-integration-button"
  52. disabled={isOpen || isSent}
  53. onClick={() => this.openRequestModal()}
  54. priority="primary"
  55. size="sm"
  56. >
  57. {buttonText}
  58. </StyledRequestIntegrationButton>
  59. );
  60. }
  61. }
  62. const StyledRequestIntegrationButton = styled(Button)`
  63. margin-left: ${space(1)};
  64. `;