reboot alterflixhub
This commit is contained in:
commit
1e84023a44
188 files changed
+31629
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router";
|
||||
|
||||
const inputClass =
|
||||
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none focus:border-[#A92626]";
|
||||
|
||||
export default function AdminLoginRoute() {
|
||||
const navigate = useNavigate();
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function submit(event: React.FormEvent) {
|
||||
event.preventDefault();
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const response = await fetch("/api/admin/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const payload = (await response.json().catch(() => ({}))) as {
|
||||
statusMessage?: string;
|
||||
message?: string;
|
||||
};
|
||||
setError(payload.statusMessage ?? payload.message ?? "เข้าสู่ระบบไม่สำเร็จ");
|
||||
return;
|
||||
}
|
||||
navigate("/admin");
|
||||
} catch {
|
||||
setError("เชื่อมต่อเซิร์ฟเวอร์ไม่ได้");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-[#0D0D0D] px-5 text-white">
|
||||
<form
|
||||
onSubmit={submit}
|
||||
className="w-full max-w-sm rounded-2xl border border-[#303030] bg-[#141414] p-6"
|
||||
>
|
||||
<h1 className="text-2xl font-semibold">เข้าสู่ระบบหลังบ้าน</h1>
|
||||
<p className="mt-1 text-sm text-[#999]">AlterFlixHub · เฉพาะผู้ดูแล</p>
|
||||
|
||||
<label className="mt-6 block text-sm text-[#B3B3B3]">
|
||||
ชื่อผู้ใช้
|
||||
<input
|
||||
value={username}
|
||||
onChange={(event) => setUsername(event.target.value)}
|
||||
autoComplete="username"
|
||||
className={`mt-1 ${inputClass}`}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<label className="mt-4 block text-sm text-[#B3B3B3]">
|
||||
รหัสผ่าน
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
className={`mt-1 ${inputClass}`}
|
||||
/>
|
||||
</label>
|
||||
|
||||
{error ? (
|
||||
<p role="alert" className="mt-4 text-sm text-[#D47272]">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={busy}
|
||||
className="mt-6 h-10 w-full rounded-lg bg-[#8F0808] text-sm font-medium transition hover:bg-[#a30a0a] disabled:opacity-60"
|
||||
>
|
||||
{busy ? "กำลังเข้าสู่ระบบ…" : "เข้าสู่ระบบ"}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user