import React, { useState } from 'react'; import { Link, RouteComponentProps } from 'react-router-dom'; import loginCheckpoint from '@/api/auth/loginCheckpoint'; import { httpErrorToHuman } from '@/api/http'; import LoginFormContainer from '@/components/auth/LoginFormContainer'; import { Actions, useStoreActions } from 'easy-peasy'; import { StaticContext } from 'react-router'; import FlashMessageRender from '@/components/FlashMessageRender'; import { ApplicationStore } from '@/state'; export default ({ history, location: { state } }: RouteComponentProps<{}, StaticContext, { token?: string }>) => { const [ code, setCode ] = useState(''); const [ isLoading, setIsLoading ] = useState(false); const { clearFlashes, addFlash } = useStoreActions((actions: Actions) => actions.flashes); if (!state || !state.token) { history.replace('/auth/login'); return null; } const onChangeHandler = (e: React.ChangeEvent) => { if (e.target.value.length <= 6) { setCode(e.target.value); } }; const submit = (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); clearFlashes(); loginCheckpoint(state.token!, code) .then(response => { if (response.complete) { // @ts-ignore window.location = response.intended || '/'; } }) .catch(error => { console.error(error); addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) }); setIsLoading(false); }); }; return (

Device Checkpoint

Return to Login
); };