Multi-page public site (Next.js), Node/Express backend with Postgres, and Vite admin/account app, restructured from a single-page layout into dedicated service, promotions, cases, about, FAQ, and blog pages for SEO. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013otXCiTZsxdZ4SJKZ9wUky
66 lines
2.5 KiB
React
66 lines
2.5 KiB
React
import { useState } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { Terminal } from 'lucide-react';
|
|
import { api } from '../lib/api.js';
|
|
|
|
export default function Login() {
|
|
const navigate = useNavigate();
|
|
const [username, setUsername] = useState('');
|
|
const [password, setPassword] = useState('');
|
|
const [error, setError] = useState('');
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function handleSubmit(e) {
|
|
e.preventDefault();
|
|
setBusy(true);
|
|
setError('');
|
|
try {
|
|
await api.login(username, password);
|
|
navigate('/admin/dashboard');
|
|
} catch (err) {
|
|
setError(err.message === 'invalid credentials' ? 'Неверный логин или пароль' : 'Не удалось войти, попробуйте ещё раз');
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center px-5 bg-slate-50 dark:bg-slate-950">
|
|
<form onSubmit={handleSubmit} className="w-full max-w-sm rounded-lg border p-6 bg-white border-slate-200 dark:bg-slate-900 dark:border-slate-800">
|
|
<div className="flex items-center gap-2 mb-1">
|
|
<Terminal className="h-5 w-5 text-emerald-500" />
|
|
<h1 className="font-bold font-display text-base">Админ-панель</h1>
|
|
</div>
|
|
<p className="text-xs mb-5 text-slate-400 dark:text-slate-500">Доступ только для сотрудников TopSysOps.</p>
|
|
|
|
<label className="text-xs block mb-1">Логин</label>
|
|
<input
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
autoComplete="username"
|
|
className="w-full rounded-md border px-3 py-2 text-sm bg-transparent mb-3 border-slate-300 dark:border-slate-700"
|
|
/>
|
|
|
|
<label className="text-xs block mb-1">Пароль</label>
|
|
<input
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
autoComplete="current-password"
|
|
className="w-full rounded-md border px-3 py-2 text-sm bg-transparent mb-4 border-slate-300 dark:border-slate-700"
|
|
/>
|
|
|
|
{error && <p className="text-xs text-rose-500 mb-4">{error}</p>}
|
|
|
|
<button
|
|
type="submit"
|
|
disabled={busy}
|
|
className="w-full py-2.5 rounded-md bg-emerald-500 text-white text-sm font-medium hover:bg-emerald-600 transition-colors disabled:opacity-60"
|
|
>
|
|
{busy ? 'Входим...' : 'Войти'}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|