waitingForWizardToConnect.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {useCallback, useEffect, useRef, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import {IconCheckmark} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {space} from 'sentry/styles/space';
  7. import type {Organization} from 'sentry/types/organization';
  8. import useApi from 'sentry/utils/useApi';
  9. import {useSetupWizardCompletedAnalytics} from 'sentry/views/setupWizard/utils/setupWizardAnalytics';
  10. export function WaitingForWizardToConnect({
  11. hash,
  12. organizations,
  13. }: {
  14. hash: string;
  15. organizations: Organization[];
  16. }) {
  17. const api = useApi();
  18. const closeTimeoutRef = useRef<number | undefined>(undefined);
  19. const [finished, setFinished] = useState(false);
  20. const trackWizardCompleted = useSetupWizardCompletedAnalytics(organizations);
  21. useEffect(() => {
  22. return () => {
  23. if (closeTimeoutRef.current) {
  24. window.clearTimeout(closeTimeoutRef.current);
  25. }
  26. };
  27. }, []);
  28. const checkFinished = useCallback(async () => {
  29. if (finished) {
  30. return;
  31. }
  32. try {
  33. await api.requestPromise(`/wizard/${hash}/`);
  34. } catch {
  35. setFinished(true);
  36. window.clearTimeout(closeTimeoutRef.current);
  37. closeTimeoutRef.current = window.setTimeout(() => window.close(), 10000);
  38. trackWizardCompleted();
  39. }
  40. }, [api, hash, trackWizardCompleted, finished]);
  41. useEffect(() => {
  42. const pollingInterval = window.setInterval(checkFinished, 1000);
  43. return () => window.clearInterval(pollingInterval);
  44. }, [checkFinished]);
  45. return !finished ? (
  46. <LoadingIndicator style={{margin: '2em auto'}}>
  47. <h5>{t('Waiting for wizard to connect')}</h5>
  48. </LoadingIndicator>
  49. ) : (
  50. <SuccessWrapper>
  51. <SuccessCheckmark color="green300" size="xl" isCircled />
  52. <SuccessHeading>
  53. {t('Return to your terminal to complete your setup.')}
  54. </SuccessHeading>
  55. </SuccessWrapper>
  56. );
  57. }
  58. const SuccessCheckmark = styled(IconCheckmark)`
  59. flex-shrink: 0;
  60. `;
  61. const SuccessHeading = styled('h5')`
  62. margin: 0;
  63. `;
  64. const SuccessWrapper = styled('div')`
  65. display: flex;
  66. align-items: center;
  67. gap: ${space(3)};
  68. `;