RequestIntegrationButton.tsx 1.7 KB

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