feat: แกไขสวน pages.jsx, layout.jsx

This commit is contained in:
admin
2025-09-27 16:26:22 +07:00
parent db7030883f
commit 83a8cddc82
10 changed files with 1002 additions and 238 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,49 +1,180 @@
// frontend/app/(protected)/layout.jsx
import Link from "next/link";
import { redirect } from "next/navigation";
import { getSession } from "@/lib/auth";
import { can } from "@/lib/rbac";
export const metadata = { title: "DMS | Protected" };
export default async function ProtectedLayout({ children }) {
// ตรวจ session ฝั่งเซิร์ฟเวอร์ ด้วยคุกกี้จริง
const session = await getSession();
if (!session) {
return (
<html><body><script>location.replace('/login');</script></body></html>
);
redirect("/login");
}
const { user } = session;
return (
<section className="mx-auto max-w-7xl p-4 grid grid-cols-12 gap-6">
<section className="grid grid-cols-12 gap-6 p-4 mx-auto max-w-7xl">
<aside className="col-span-12 lg:col-span-3 xl:col-span-3">
<div className="rounded-3xl p-4 border bg-white/70">
<div className="text-sm mb-3">RBAC: <b>{user.role}</b></div>
<div className="p-4 border rounded-3xl bg-white/70">
<div className="mb-3 text-sm">
RBAC: <b>{user.role}</b>
</div>
<nav className="space-y-2">
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/dashboard">แดชบอร</Link>
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/drawings">Drawings</Link>
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/rfas">RFAs</Link>
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/transmittals">Transmittals</Link>
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/correspondences">Correspondences</Link>
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/contracts-volumes">Contracts & Volumes</Link>
<Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/reports">Reports</Link>
{can(user, 'workflow:view') && <Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/workflow">Workflow (n8n)</Link>}
{can(user, 'health:view') && <Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/health">Health</Link>}
{can(user, 'users:manage') && <Link className="block rounded-xl px-4 py-2 bg-white/60 hover:bg-white" href="/users">ใช/บทบาท</Link>}
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/dashboard"
>
แดชบอร
</Link>
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/drawings"
>
Drawings
</Link>
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/rfas"
>
RFAs
</Link>
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/transmittals"
>
Transmittals
</Link>
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/correspondences"
>
Correspondences
</Link>
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/contracts-volumes"
>
Contracts & Volumes
</Link>
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/reports"
>
Reports
</Link>
{can(user, "workflow:view") && (
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/workflow"
>
Workflow (n8n)
</Link>
)}
{can(user, "health:view") && (
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/health"
>
Health
</Link>
)}
{can(user, "users:manage") && (
<Link
className="block px-4 py-2 rounded-xl bg-white/60 hover:bg-white"
href="/users"
>
ใช/บทบาท
</Link>
)}
</nav>
</div>
</aside>
<main className="col-span-12 lg:col-span-9 xl:col-span-9 space-y-6">
{/* ปุ่ม System + Quick Actions เบื้องต้น */}
<main className="col-span-12 space-y-6 lg:col-span-9 xl:col-span-9">
{/* System / Quick Actions */}
<div className="flex items-center gap-2">
<div className="text-lg font-semibold flex-1">Document Management System LCP3 Phase 3</div>
{can(user, 'admin:view') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/admin">Admin</a>}
{can(user, 'users:manage') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/users">ใช/บทบาท</a>}
{can(user, 'health:view') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/health">Health</a>}
{can(user, 'workflow:view') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/workflow">Workflow</a>}
{can(user, 'rfa:create') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/rfas/new">+ RFA</a>}
{can(user, 'drawing:upload') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/drawings/upload">+ Upload Drawing</a>}
{can(user, 'transmittal:create') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/transmittals/new">+ Transmittal</a>}
{can(user, 'correspondence:create') && <a className="px-3 py-2 rounded-xl text-white" style={{background:'#0D5C75'}} href="/correspondences/new">+ หนงสอสอสาร</a>}
<div className="flex-1 text-lg font-semibold">
Document Management System LCP3 Phase 3
</div>
{can(user, "admin:view") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/admin"
>
Admin
</a>
)}
{can(user, "users:manage") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/users"
>
ใช/บทบาท
</a>
)}
{can(user, "health:view") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/health"
>
Health
</a>
)}
{can(user, "workflow:view") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/workflow"
>
Workflow
</a>
)}
{can(user, "rfa:create") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/rfas/new"
>
+ RFA
</a>
)}
{can(user, "drawing:upload") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/drawings/upload"
>
+ Upload Drawing
</a>
)}
{can(user, "transmittal:create") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/transmittals/new"
>
+ Transmittal
</a>
)}
{can(user, "correspondence:create") && (
<a
className="px-3 py-2 text-white rounded-xl"
style={{ background: "#0D5C75" }}
href="/correspondences/new"
>
+ หนงสอสอสาร
</a>
)}
</div>
{children}
</main>
</section>