import { useState } from "react"; import { useNavigate, useLocation } from "react-router-dom"; import { toast } from "react-toastify" import useAuth from "../../auth/auth"; import FormField from "../../components/FormField" import "./register.css" const Register = () => { const { setToken } = useAuth(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const navigate = useNavigate(); const location = useLocation(); const searchPath = new URLSearchParams(location.search); const redirectPath = searchPath.get("to") || "/"; const [usernameEmpty, setUsernameEmpty] = useState(false); const [passwordEmpty, setPasswordEmpty] = useState(false); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setUsernameEmpty(!username); setPasswordEmpty(!password); if (!username || !password) { return; } // TODO: request to API - register if (username === "user" && password === "user") { const token = "newusertodo.jwt.token"; setToken(token); navigate(redirectPath, { replace: true }); } else { toast.error("Wrong login or password"); } }; return (