SplitInstallationIdModal.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {useCallback, useEffect, useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import {addSuccessMessage} from 'sentry/actionCreators/indicator';
  4. import {Button} from 'sentry/components/button';
  5. import TextCopyInput from 'sentry/components/textCopyInput';
  6. type Props = {
  7. closeModal: () => void;
  8. installationId: string;
  9. };
  10. /**
  11. * This component is a hack for Split.
  12. * It will display the installation ID after installation so users can copy it and paste it in Split's website.
  13. * We also have a link for users to click so they can go to Split's website.
  14. */
  15. export function SplitInstallationIdModal(props: Props) {
  16. const openAdminIntegrationTimeoutRef = useRef<number | undefined>(undefined);
  17. useEffect(() => {
  18. return () => {
  19. window.clearTimeout(openAdminIntegrationTimeoutRef.current);
  20. };
  21. }, []);
  22. const onCopy = useCallback(async () => {
  23. // This hack is needed because the normal copying methods with TextCopyInput do not work correctly
  24. await navigator.clipboard.writeText(props.installationId);
  25. }, [props.installationId]);
  26. const handleContinue = useCallback(() => {
  27. onCopy();
  28. addSuccessMessage('Copied to clipboard');
  29. window.clearTimeout(openAdminIntegrationTimeoutRef.current);
  30. openAdminIntegrationTimeoutRef.current = window.setTimeout(() => {
  31. window.open('https://app.split.io/org/admin/integrations');
  32. }, 2000);
  33. }, [onCopy]);
  34. // no need to translate this temporary component
  35. return (
  36. <div>
  37. <ItemHolder>
  38. Copy this Installation ID and click to continue. You will use it to finish setup
  39. on Split.io.
  40. </ItemHolder>
  41. <ItemHolder>
  42. <TextCopyInput onCopy={onCopy}>{props.installationId}</TextCopyInput>
  43. </ItemHolder>
  44. <ButtonHolder>
  45. <Button size="sm" onClick={props.closeModal}>
  46. Close
  47. </Button>
  48. <Button size="sm" priority="primary" onClick={handleContinue}>
  49. Copy and Open Link
  50. </Button>
  51. </ButtonHolder>
  52. </div>
  53. );
  54. }
  55. const ItemHolder = styled('div')`
  56. margin: 10px;
  57. `;
  58. const ButtonHolder = styled(ItemHolder)`
  59. text-align: right;
  60. & button {
  61. margin: 5px;
  62. }
  63. `;