addIntegrationRow.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {useContext} from 'react';
  2. import styled from '@emotion/styled';
  3. import Access from 'sentry/components/acl/access';
  4. import PluginIcon from 'sentry/plugins/components/pluginIcon';
  5. import {space} from 'sentry/styles/space';
  6. import {trackAnalytics} from 'sentry/utils/analytics';
  7. import useOrganization from 'sentry/utils/useOrganization';
  8. import IntegrationButton from 'sentry/views/settings/organizationIntegrations/integrationButton';
  9. import {IntegrationContext} from 'sentry/views/settings/organizationIntegrations/integrationContext';
  10. type Props = {
  11. onClick: () => void;
  12. };
  13. function AddIntegrationRow({onClick}: Props) {
  14. const organization = useOrganization();
  15. const integration = useContext(IntegrationContext);
  16. if (!integration) {
  17. return null;
  18. }
  19. const provider = integration.provider;
  20. const onAddIntegration = () => {
  21. integration.onAddIntegration?.();
  22. onClick();
  23. };
  24. const onExternalClick = () => {
  25. trackAnalytics('onboarding.messaging_integration_external_install_clicked', {
  26. provider_key: provider.key,
  27. organization,
  28. });
  29. onClick();
  30. };
  31. const buttonProps = {
  32. size: 'sm',
  33. priority: 'primary',
  34. 'data-test-id': 'install-button',
  35. };
  36. return (
  37. <RowWrapper>
  38. <IconTextWrapper>
  39. <PluginIcon pluginId={provider.slug} size={40} />
  40. <NameHeader>Connect {provider.name}</NameHeader>
  41. </IconTextWrapper>
  42. <Access access={['org:integrations']} organization={organization}>
  43. {({hasAccess}) => {
  44. return (
  45. <StyledButton
  46. userHasAccess={hasAccess}
  47. onAddIntegration={onAddIntegration}
  48. onExternalClick={onExternalClick}
  49. externalInstallText="Add Installation"
  50. buttonProps={buttonProps}
  51. />
  52. );
  53. }}
  54. </Access>
  55. </RowWrapper>
  56. );
  57. }
  58. const RowWrapper = styled('div')`
  59. display: flex;
  60. border-radius: 4px;
  61. border: 1px solid ${p => p.theme.gray200};
  62. justify-content: space-between;
  63. align-items: center;
  64. padding: ${space(3)} ${space(4)};
  65. `;
  66. const IconTextWrapper = styled('div')`
  67. display: flex;
  68. align-items: center;
  69. gap: ${space(3)};
  70. `;
  71. const NameHeader = styled('h6')`
  72. margin: 0;
  73. `;
  74. const StyledButton = styled(IntegrationButton)`
  75. margin: 0;
  76. `;
  77. export default AddIntegrationRow;