index.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {useEffect, useState} from 'react';
  2. import Button from 'sentry/components/button';
  3. import LoadingIndicator from 'sentry/components/loadingIndicator';
  4. import ThemeAndStyleProvider from 'sentry/components/themeAndStyleProvider';
  5. import {t} from 'sentry/locale';
  6. import useApi from 'sentry/utils/useApi';
  7. type Props = {
  8. hash?: boolean | string;
  9. };
  10. function SetupWizard({hash = false}: Props) {
  11. const api = useApi();
  12. const [finished, setFinished] = useState(false);
  13. async function checkFinished() {
  14. try {
  15. await api.requestPromise(`/wizard/${hash}/`);
  16. } catch {
  17. setFinished(true);
  18. window.setTimeout(() => window.close(), 10000);
  19. }
  20. }
  21. useEffect(() => {
  22. const poller = window.setInterval(checkFinished, 1000);
  23. return () => window.clearTimeout(poller);
  24. }, []);
  25. return (
  26. <ThemeAndStyleProvider>
  27. <div className="container">
  28. {!finished ? (
  29. <LoadingIndicator style={{margin: '2em auto'}}>
  30. <div className="row">
  31. <h5>{t('Waiting for wizard to connect')}</h5>
  32. </div>
  33. </LoadingIndicator>
  34. ) : (
  35. <div className="row">
  36. <h5>{t('Return to your terminal to complete your setup')}</h5>
  37. <h5>{t('(This window will close in 10 seconds)')}</h5>
  38. <Button onClick={() => window.close()}>{t('Close browser tab')}</Button>
  39. </div>
  40. )}
  41. </div>
  42. </ThemeAndStyleProvider>
  43. );
  44. }
  45. export default SetupWizard;