import React, { useState } from 'react'; import { Link } from 'react-router-dom'; import login from '@/api/auth/login'; import { httpErrorToHuman } from '@/api/http'; import LoginFormContainer from '@/components/auth/LoginFormContainer'; import FlashMessageRender from '@/components/FlashMessageRender'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationState } from '@/state/types'; import useRouter from 'use-react-router'; export default () => { const [ username, setUsername ] = useState(''); const [ password, setPassword ] = useState(''); const [ isLoading, setLoading ] = useState(false); const { history } = useRouter(); const { clearFlashes, addFlash } = useStoreActions((actions: Actions) => actions.flashes); const submit = (e: React.FormEvent) => { e.preventDefault(); setLoading(true); clearFlashes(); login(username!, password!) .then(response => { if (response.complete) { // @ts-ignore window.location = response.intended || '/'; return; } history.replace('/login/checkpoint', { token: response.confirmationToken }); }) .catch(error => { console.error(error); setLoading(false); addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) }); }); }; const canSubmit = () => username && password && username.length > 0 && password.length > 0; return (

Login to Continue

setUsername(e.target.value)} disabled={isLoading} />
setPassword(e.target.value)} disabled={isLoading} />
Forgot password?
); };