- บทความจากหลังบ้าน: /for-film-lovers, /for-cinemas (ArticlePage + ArticleEditor แบบบล็อกย่อหน้า/รูป) - แชร์: ปุ่มบนการ์ดและท้ายหน้ารายละเอียด · ลิงก์ย่อ /c/<slug> (302) · ธีมแก้วตาม DESIGN.md - PWA: manifest/sw/offline + ถอดการล็อกซูม (WCAG 1.4.4) + touch target ≥44px - แอนิเมชัน reveal: IntersectionObserver + gate ด้วย html.fx-motion · เคารพ prefers-reduced-motion - ค้นหา: normalize/ตัดวรรณยุกต์ + AND หลายคำ + จัดอันดับ · รองรับ /?q= จาก SearchAction - SEO: pageMeta (canonical/OG/Twitter) + JSON-LD (WebSite/Organization/BreadcrumbList/MovieTheater/Article) - ไม่ฝังโดเมนในโค้ด: origin มาจาก request (x-forwarded-host/proto) ทั้ง canonical, sitemap, robots, ลิงก์แชร์ - กัน AI: robots.txt (Nitro route, บล็อก AI 21 ตัว) + ai.txt + OG image 1200x630 - เอกสาร: README สรุปโปรเจกต์, DESIGN.md (motion/PWA/SEO/ข้อมูล), architecture.html, admin-guide - tests: 135 ผ่าน (16 ไฟล์)
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-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>
|
|
);
|
|
}
|