diff --git a/admin/src/pages/Login/Login.jsx b/admin/src/pages/Login/Login.jsx new file mode 100644 index 0000000..1845493 --- /dev/null +++ b/admin/src/pages/Login/Login.jsx @@ -0,0 +1,43 @@ +import TextBox from "@/common/components/TextBox"; +import {faKey, faUser} from "@fortawesome/free-solid-svg-icons"; +import Button from "@/common/components/Button"; +import {useContext, useRef, useState} from "react"; +import {createSession} from "@/common/utils/RequestUtil.js"; +import LoginContext from "@/common/contexts/Login"; +import "./styles.sass"; + +export const Login = () => { + const setToken = useContext(LoginContext); + + const usernameRef = useRef(null); + const passwordRef = useRef(null); + + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + + const updateUsername = (e) => setUsername(e.target.value); + const updatePassword = (e) => setPassword(e.target.value); + + const showError = () => { + usernameRef.current.classList.add("shake"); + passwordRef.current.classList.add("shake"); + } + + const onLogin = async () => { + const token = await createSession(username, password); + if (token === null) return showError(); + + setToken(token); + } + + return ( +
+
e.preventDefault()}> +

MyLinks

+ + +
+ ) +} \ No newline at end of file