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'; import Spinner from '@/components/elements/Spinner'; import styled from 'styled-components'; import { breakpoint } from 'styled-components-breakpoint'; const Container = styled.div` ${breakpoint('sm')` ${tw`w-4/5 mx-auto`} `}; ${breakpoint('md')` ${tw`p-10`} `}; ${breakpoint('lg')` ${tw`w-3/5`} `}; ${breakpoint('xl')` ${tw`w-full`} max-width: 660px; `}; `; 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
); };