setupWizard.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React from 'react';
  2. import {Client} from 'app/api';
  3. import LoadingIndicator from 'app/components/loadingIndicator';
  4. import {t} from 'app/locale';
  5. import withApi from 'app/utils/withApi';
  6. type Props = {
  7. api: Client;
  8. hash?: boolean | string;
  9. };
  10. type State = {
  11. finished: boolean;
  12. };
  13. class SetupWizard extends React.Component<Props, State> {
  14. static defaultProps = {
  15. hash: false,
  16. };
  17. state: State = {
  18. finished: false,
  19. };
  20. UNSAFE_componentWillMount() {
  21. this.pollFinished();
  22. }
  23. pollFinished() {
  24. return new Promise<void>(resolve => {
  25. this.props.api.request(`/wizard/${this.props.hash}/`, {
  26. method: 'GET',
  27. success: () => {
  28. setTimeout(() => this.pollFinished(), 1000);
  29. },
  30. error: () => {
  31. resolve();
  32. this.setState({finished: true});
  33. setTimeout(() => window.close(), 10000);
  34. },
  35. });
  36. });
  37. }
  38. renderSuccess() {
  39. return (
  40. <div className="row">
  41. <h5>{t('Return to your terminal to complete your setup')}</h5>
  42. <h5>{t('(This window will close in 10 seconds)')}</h5>
  43. <button className="btn btn-default" onClick={() => window.close()}>
  44. Close browser tab
  45. </button>
  46. </div>
  47. );
  48. }
  49. renderLoading() {
  50. return (
  51. <div className="row">
  52. <h5>{t('Waiting for wizard to connect')}</h5>
  53. </div>
  54. );
  55. }
  56. render() {
  57. const {finished} = this.state;
  58. return (
  59. <div className="container">
  60. <LoadingIndicator style={{margin: '2em auto'}} finished={finished}>
  61. {finished ? this.renderSuccess() : this.renderLoading()}
  62. </LoadingIndicator>
  63. </div>
  64. );
  65. }
  66. }
  67. export default withApi(SetupWizard);