import NotifBox from './NotifBox' import { useField, removeReset } from '../utils/hooks' import { useNotification } from '../utils/NotifContext' import loginService from '../services/login' import { setToken } from '../utils/requests' import { useUserDispatch } from '../utils/UserContext' import { Card, TextField, Typography, Box, Button } from '@mui/material' const LoginForm = () => { const username = useField('text') const password = useField('password') const setNotif = useNotification() const dispatch = useUserDispatch() const handleLogin = async event => { event.preventDefault() try { const loggedUser = await loginService.login({ username: username.value, password: password.value, }) window.localStorage.setItem( 'loggedBlogAppUser', JSON.stringify(loggedUser) ) dispatch({ type: 'SET_USER', payload: loggedUser }) setToken(loggedUser.token) username.reset() password.reset() } catch (err) { setNotif('Wrong Credentials', 5000) console.error(err) } } return (