fixbugadmin1
This commit is contained in:
@@ -12,16 +12,16 @@ const LoginWindow: React.FC<LoginWindowProps> = ({
|
||||
onLogin,
|
||||
onGuestMode,
|
||||
loginError,
|
||||
inputRef
|
||||
inputRef
|
||||
}) => {
|
||||
const [id, setId] = useState('');
|
||||
const [isCardDetected, setIsCardDetected] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
// ✅ Используем переданный реф или внутренний
|
||||
const internalInputRef = useRef<HTMLInputElement>(null);
|
||||
const activeInputRef = inputRef || internalInputRef;
|
||||
|
||||
// ✅ При монтировании — фокус на поле ввода
|
||||
// ✅ Фокус при монтировании
|
||||
useEffect(() => {
|
||||
if (activeInputRef.current) {
|
||||
setTimeout(() => {
|
||||
@@ -30,10 +30,11 @@ const LoginWindow: React.FC<LoginWindowProps> = ({
|
||||
}
|
||||
}, [activeInputRef]);
|
||||
|
||||
// ✅ При ошибке — фокус на поле ввода
|
||||
// ✅ При ошибке — очищаем поле и ставим фокус
|
||||
useEffect(() => {
|
||||
if (loginError) {
|
||||
setId('');
|
||||
setId(''); // ✅ Очищаем поле
|
||||
setIsLoading(false);
|
||||
if (activeInputRef.current) {
|
||||
setTimeout(() => {
|
||||
activeInputRef.current?.focus();
|
||||
@@ -92,10 +93,27 @@ const LoginWindow: React.FC<LoginWindowProps> = ({
|
||||
};
|
||||
}, [onLogin]);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (id.trim()) {
|
||||
onLogin(id.trim());
|
||||
const trimmedId = id.trim();
|
||||
|
||||
if (!trimmedId) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
await onLogin(trimmedId);
|
||||
// ✅ При успешном входе — очищаем поле
|
||||
setId('');
|
||||
} catch (error) {
|
||||
// ✅ При ошибке — очищаем поле
|
||||
setId('');
|
||||
setIsLoading(false);
|
||||
} finally {
|
||||
// ✅ В любом случае снимаем блокировку
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -190,7 +208,7 @@ const LoginWindow: React.FC<LoginWindowProps> = ({
|
||||
</label>
|
||||
<input
|
||||
ref={activeInputRef}
|
||||
type="text"
|
||||
type="password"
|
||||
id="id"
|
||||
value={id}
|
||||
onChange={(e) => setId(e.target.value)}
|
||||
|
||||
Reference in New Issue
Block a user