import React from 'react'; import { Input } from 'semantic-ui-react'; import cityBackground from '../../assets/city_background.jpg'; import Logo from '../../components/logo/Logo'; import { xhrPost } from '../../services/xhr'; import { Message } from 'semantic-ui-react'; import { useHistory } from 'react-router'; import { useDispatch } from 'react-redux'; import './login.less'; export default function Login() { const dispatch = useDispatch(); const [username, setUserName] = React.useState(''); const [password, setPassword] = React.useState(''); const [error, setError] = React.useState(null); const history = useHistory(); const tryLogin = async () => { if (username.length === 0 || password.length === 0) { setError('Username and password are mandatory.'); return; } try { await xhrPost('/api/login', { username, password, }); setError(null); } catch (Exception) { setError('Login not successful...'); return; } await dispatch.user.getCurrentUser(); history.push('/jobs'); }; return (
{error && } setUserName(e.target.value)} /> setPassword(e.target.value)} />
); } Login.displayName = 'Login';