import { LoadingButton } from "@mui/lab"; import { Box, Button, Drawer, TextField, Typography } from "@mui/material"; import { useAtom, useAtomValue } from "jotai"; import { FormEvent, useEffect, useRef } from "react"; import { cancelPasswordAuthAtom, passwordAtom, passwordLoginAtom, passwordPreloginAtom, usernameAtom, } from "../../atoms/portal"; export default function PasswordAuth() { const [visible, cancelPasswordAuth] = useAtom(cancelPasswordAuthAtom); const { authMessage, labelUsername, labelPassword } = useAtomValue(passwordPreloginAtom); const [username, setUsername] = useAtom(usernameAtom); const [password, setPassword] = useAtom(passwordAtom); const [loading, passwordLogin] = useAtom(passwordLoginAtom); const usernameRef = useRef(null); useEffect(() => { if (visible) { setTimeout(() => { usernameRef.current?.querySelector("input")?.focus(); }, 0); } }, [visible]); function handleSubmit(e: FormEvent) { e.preventDefault(); passwordLogin(username, password); } return (
{authMessage} setUsername(e.target.value.trim())} InputProps={{ readOnly: loading }} /> setPassword(e.target.value)} InputProps={{ readOnly: loading }} /> Login
); }