addIntegrationRow.tsx 2.7 KB

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