1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import {Component, Fragment} from 'react';
- // eslint-disable-next-line no-restricted-imports
- import {withRouter, WithRouterProps} from 'react-router';
- import styled from '@emotion/styled';
- import {ModalRenderProps} from 'sentry/actionCreators/modal';
- import Button from 'sentry/components/button';
- import Text from 'sentry/components/text';
- import {t, tct} from 'sentry/locale';
- import recreateRoute from 'sentry/utils/recreateRoute';
- type Props = ModalRenderProps &
- WithRouterProps & {
- slug: string;
- };
- type State = {
- timer: number;
- };
- class RedirectToProjectModal extends Component<Props, State> {
- state: State = {
- timer: 5,
- };
- componentDidMount() {
- this.redirectInterval = window.setInterval(() => {
- if (this.state.timer <= 1) {
- window.location.assign(this.newPath);
- return;
- }
- this.setState(state => ({
- timer: state.timer - 1,
- }));
- }, 1000);
- }
- componentWillUnmount() {
- if (this.redirectInterval) {
- window.clearInterval(this.redirectInterval);
- }
- }
- redirectInterval: number | null = null;
- get newPath() {
- const {params, slug} = this.props;
- return recreateRoute('', {
- ...this.props,
- params: {
- ...params,
- projectId: slug,
- },
- });
- }
- render() {
- const {slug, Header, Body} = this.props;
- return (
- <Fragment>
- <Header>{t('Redirecting to New Project...')}</Header>
- <Body>
- <div>
- <Text>
- <p>{t('The project slug has been changed.')}</p>
- <p>
- {tct(
- 'You will be redirected to the new project [project] in [timer] seconds...',
- {
- project: <strong>{slug}</strong>,
- timer: `${this.state.timer}`,
- }
- )}
- </p>
- <ButtonWrapper>
- <Button priority="primary" href={this.newPath}>
- {t('Continue to %s', slug)}
- </Button>
- </ButtonWrapper>
- </Text>
- </div>
- </Body>
- </Fragment>
- );
- }
- }
- export default withRouter(RedirectToProjectModal);
- export {RedirectToProjectModal};
- const ButtonWrapper = styled('div')`
- display: flex;
- justify-content: flex-end;
- `;
|