- iOS Safari: ฟอร์ม ≥16px บนมือถือ (กัน auto-zoom โดยไม่ต้องล็อก user-scalable), input[type=search] appearance:none, tap-highlight transparent, text-size-adjust 100% - ย้ายบล็อก cross-engine เข้า @layer base — เดิม unlayered ทับ text-sm ทำให้ desktop เพี้ยนเป็น 16px - admin 3 จุด min-h-screen → min-h-dvh - DESIGN.md: ขยายหัวข้อเป็น Chromium/Firefox/Safari + กฎ @layer · sw VERSION v2.0.3
108 lines
3.8 KiB
TypeScript
108 lines
3.8 KiB
TypeScript
import { useState } from "react";
|
|
import { useNavigate } from "react-router";
|
|
|
|
import { resolvePageOrigin } from "@/lib/page-origin";
|
|
import { originFromMatches, pageMeta } from "@/lib/seo";
|
|
|
|
const inputClass =
|
|
"w-full rounded-lg border border-[#303030] bg-[#141414] px-3 py-2 text-sm text-white outline-none focus:border-[#A92626]";
|
|
|
|
/** meta() ของ route ลูกอ่าน origin ที่ root loader หาไว้ (ไม่ฝังโดเมน) */
|
|
type MetaArgs = { matches?: Array<{ id?: string; data?: unknown }> };
|
|
|
|
/** หน้าล็อกอินหลังบ้าน — ไม่ให้ search engine เก็บ */
|
|
export async function loader({ request }: { request: Request }) {
|
|
return { origin: resolvePageOrigin(request) };
|
|
}
|
|
|
|
export function meta({ loaderData }: { loaderData?: { origin?: string } }) {
|
|
return pageMeta({
|
|
origin: loaderData?.origin ?? "",
|
|
title: "เข้าสู่ระบบหลังบ้าน — AlterFlixHub",
|
|
description: "หน้าสำหรับผู้ดูแลเว็บไซต์เท่านั้น",
|
|
path: "/admin/login",
|
|
noIndex: true,
|
|
});
|
|
}
|
|
|
|
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-dvh 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>
|
|
);
|
|
}
|