redirectToProject.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {Component, Fragment} from 'react';
  2. import {withRouter, WithRouterProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  5. import Button from 'sentry/components/button';
  6. import Text from 'sentry/components/text';
  7. import {t, tct} from 'sentry/locale';
  8. import recreateRoute from 'sentry/utils/recreateRoute';
  9. type Props = ModalRenderProps &
  10. WithRouterProps & {
  11. slug: string;
  12. };
  13. type State = {
  14. timer: number;
  15. };
  16. class RedirectToProjectModal extends Component<Props, State> {
  17. state: State = {
  18. timer: 5,
  19. };
  20. componentDidMount() {
  21. setInterval(() => {
  22. if (this.state.timer <= 1) {
  23. window.location.assign(this.newPath);
  24. return;
  25. }
  26. this.setState(state => ({
  27. timer: state.timer - 1,
  28. }));
  29. }, 1000);
  30. }
  31. get newPath() {
  32. const {params, slug} = this.props;
  33. return recreateRoute('', {
  34. ...this.props,
  35. params: {
  36. ...params,
  37. projectId: slug,
  38. },
  39. });
  40. }
  41. render() {
  42. const {slug, Header, Body} = this.props;
  43. return (
  44. <Fragment>
  45. <Header>{t('Redirecting to New Project...')}</Header>
  46. <Body>
  47. <div>
  48. <Text>
  49. <p>{t('The project slug has been changed.')}</p>
  50. <p>
  51. {tct(
  52. 'You will be redirected to the new project [project] in [timer] seconds...',
  53. {
  54. project: <strong>{slug}</strong>,
  55. timer: `${this.state.timer}`,
  56. }
  57. )}
  58. </p>
  59. <ButtonWrapper>
  60. <Button priority="primary" href={this.newPath}>
  61. {t('Continue to %s', slug)}
  62. </Button>
  63. </ButtonWrapper>
  64. </Text>
  65. </div>
  66. </Body>
  67. </Fragment>
  68. );
  69. }
  70. }
  71. export default withRouter(RedirectToProjectModal);
  72. export {RedirectToProjectModal};
  73. const ButtonWrapper = styled('div')`
  74. display: flex;
  75. justify-content: flex-end;
  76. `;