/* eslint-disable react/jsx-max-depth */ /* eslint-disable import/no-relative-parent-imports */ /* eslint-disable eslint/no-void */ /* eslint-disable typescript/no-deprecated */ import {useState, type ReactNode, type FormEvent} from 'react'; import {Button, TextField, Dialog, DialogActions, DialogContent, DialogTitle, Typography, Alert, Box} from '@mui/material'; import {useAuth} from '../contexts/AuthContext.js'; import {trpc} from '../trpc.js'; import {useNavigate} from 'react-router-dom'; export const Login = (): ReactNode => { const [email, setEmail] = useState('demo@example.com'); const [password, setPassword] = useState('password'); const [error, setError] = useState(null); const {login} = useAuth(); const navigate = useNavigate(); const loginMutation = trpc.auth.login.useMutation({ onSuccess: (data) => { login(data.token, data.user); void navigate('/dashboard'); }, onError: (err) => { setError(err.message); }, }); const handleSubmit = (e: FormEvent): void => { e.preventDefault(); setError(null); loginMutation.mutate({email, password}); }; return (
Login {error !== null && {error}} Use demo@example.com / password to login. { setEmail(e.currentTarget.value); }} /> { setPassword(e.currentTarget.value); }} />
); };