import * as React from 'react'; import { RouteComponentProps, StaticContext } from 'react-router'; import { connect } from 'react-redux'; import { pushFlashMessage, clearAllFlashMessages } from '@/redux/actions/flash'; import NetworkErrorMessage from '@/components/NetworkErrorMessage'; import MessageBox from '@/components/MessageBox'; import { Link } from 'react-router-dom'; import loginCheckpoint from '@/api/auth/loginCheckpoint'; import { httpErrorToHuman } from '@/api/http'; type State = Readonly<{ isLoading: boolean; errorMessage?: string; code: string; }>; class LoginCheckpointContainer extends React.PureComponent, State> { state: State = { code: '', isLoading: false, }; componentDidMount () { const { state } = this.props.location; if (!state || !state.token) { this.props.history.replace('/login'); } } onChangeHandler = (e: React.ChangeEvent) => { if (e.target.value.length > 6) { e.target.value = e.target.value.substring(0, 6); return e.preventDefault(); } this.setState({ code: e.target.value }); }; submit = (e: React.FormEvent) => { e.preventDefault(); this.setState({ isLoading: true }, () => { loginCheckpoint(this.props.location.state.token, this.state.code) .then(response => { if (response.complete) { // @ts-ignore window.location = response.intended || '/'; } }) .catch(error => { console.error(error); this.setState({ errorMessage: httpErrorToHuman(error), isLoading: false }); }); }); }; render () { return (

Device Checkpoint

This account is protected with two-factor authentication. A valid authentication token must be provided in order to continue.
Return to Login
); } } const mapDispatchToProps = { pushFlashMessage, clearAllFlashMessages, }; export default connect(null, mapDispatchToProps)(LoginCheckpointContainer);