260220:1600 20260220 TASK-BEFE-001 Refactor by ADR-014 #3
All checks were successful
Build and Deploy / deploy (push) Successful in 1m35s

This commit is contained in:
admin
2026-02-20 16:00:26 +07:00
parent 634178fbab
commit 068e76d701
6 changed files with 443 additions and 144 deletions

View File

@@ -1,4 +1,4 @@
import { AdminSidebar } from '@/components/admin/sidebar';
import { AdminSidebar, AdminMobileSidebar } from '@/components/admin/sidebar';
import { auth } from '@/lib/auth';
@@ -16,9 +16,17 @@ export default async function AdminLayout({ children }: { children: React.ReactN
}
return (
<div className="flex h-screen w-full bg-background">
<div className="flex h-screen w-full bg-background overflow-hidden">
<AdminSidebar />
<div className="flex-1 overflow-auto bg-muted/10 p-4">{children}</div>
<div className="flex-1 flex flex-col min-h-screen overflow-hidden">
{/* Mobile Header for Admin Panel */}
<div className="h-16 border-b flex items-center px-4 md:hidden shrink-0 bg-white">
<AdminMobileSidebar />
<h2 className="text-lg font-semibold ml-4">LCBP3-DMS Admin</h2>
</div>
{/* Main Content */}
<div className="flex-1 overflow-auto bg-muted/10 p-4">{children}</div>
</div>
</div>
);
}

View File

@@ -4,19 +4,7 @@ import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { useState } from 'react';
import { cn } from '@/lib/utils';
import {
Users,
Building2,
Settings,
FileText,
Activity,
GitGraph,
Shield,
BookOpen,
FileStack,
ChevronDown,
ChevronRight,
} from 'lucide-react';
import { Settings, Activity, Shield, FileStack, ChevronDown, ChevronRight } from 'lucide-react';
interface MenuItem {
href?: string;
@@ -25,7 +13,7 @@ interface MenuItem {
children?: { href: string; label: string }[];
}
const menuItems: MenuItem[] = [
export const menuItems: MenuItem[] = [
{
label: 'Access Control',
icon: Shield,
@@ -169,3 +157,122 @@ export function AdminSidebar() {
</aside>
);
}
import { Sheet, SheetContent, SheetTrigger, SheetTitle } from '@/components/ui/sheet';
import { Button } from '@/components/ui/button';
import { Menu } from 'lucide-react';
export function AdminMobileSidebar() {
const pathname = usePathname();
const [open, setOpen] = useState(false);
const [expandedMenus, setExpandedMenus] = useState<string[]>(
menuItems
.filter((item) => item.children?.some((child) => pathname.startsWith(child.href)))
.map((item) => item.label)
);
const toggleMenu = (label: string) => {
setExpandedMenus((prev) => (prev.includes(label) ? prev.filter((l) => l !== label) : [...prev, label]));
};
return (
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
<Button variant="ghost" size="icon" className="md:hidden">
<Menu className="h-5 w-5" />
<span className="sr-only">Toggle admin menu</span>
</Button>
</SheetTrigger>
<SheetContent side="left" className="w-64 p-0">
<SheetTitle className="sr-only">Admin Navigation</SheetTitle>
<div className="h-16 flex items-center px-4 border-b">
<span className="text-lg font-bold tracking-tight">Admin Console</span>
</div>
<div className="flex-1 overflow-y-auto py-4 h-[calc(100vh-4rem)]">
<nav className="space-y-1 px-2">
{menuItems.map((item) => {
const Icon = item.icon;
if (item.children) {
const isExpanded = expandedMenus.includes(item.label);
const hasActiveChild = item.children.some((child) => pathname.startsWith(child.href));
return (
<div key={item.label}>
<button
onClick={() => toggleMenu(item.label)}
className={cn(
'w-full flex items-center justify-between gap-3 px-3 py-2 rounded-lg transition-colors text-sm font-medium',
hasActiveChild
? 'bg-primary/10 text-primary'
: 'text-muted-foreground hover:bg-muted hover:text-foreground'
)}
>
<span className="flex items-center gap-3">
<Icon className="h-4 w-4" />
<span>{item.label}</span>
</span>
{isExpanded ? <ChevronDown className="h-4 w-4" /> : <ChevronRight className="h-4 w-4" />}
</button>
{isExpanded && (
<div className="ml-4 mt-1 space-y-1 border-l pl-4">
{item.children.map((child) => {
const isActive = pathname === child.href;
return (
<Link
key={child.href}
href={child.href}
onClick={() => setOpen(false)}
className={cn(
'block px-3 py-1.5 rounded-lg transition-colors text-sm',
isActive
? 'bg-primary text-primary-foreground shadow-sm'
: 'text-muted-foreground hover:bg-muted hover:text-foreground'
)}
>
{child.label}
</Link>
);
})}
</div>
)}
</div>
);
}
const isActive = pathname.startsWith(item.href!);
return (
<Link
key={item.href}
href={item.href!}
onClick={() => setOpen(false)}
className={cn(
'flex items-center gap-3 px-3 py-2 rounded-lg transition-colors text-sm font-medium',
isActive
? 'bg-primary text-primary-foreground shadow-sm'
: 'text-muted-foreground hover:bg-muted hover:text-foreground'
)}
>
<Icon className="h-4 w-4" />
<span>{item.label}</span>
</Link>
);
})}
</nav>
<div className="p-4 mt-8 border-t absolute bottom-0 w-full left-0 bg-background">
<Link
href="/dashboard"
onClick={() => setOpen(false)}
className="text-sm text-muted-foreground hover:text-foreground flex items-center gap-2"
>
Back to Dashboard
</Link>
</div>
</div>
</SheetContent>
</Sheet>
);
}

View File

@@ -1,4 +1,4 @@
"use client";
'use client';
import {
ColumnDef,
@@ -7,26 +7,16 @@ import {
useReactTable,
getSortedRowModel,
SortingState,
} from "@tanstack/react-table";
import { useState } from "react";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
} from '@tanstack/react-table';
import { useState } from 'react';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
}
export function DataTable<TData, TValue>({
columns,
data,
}: DataTableProps<TData, TValue>) {
export function DataTable<TData, TValue>({ columns, data }: DataTableProps<TData, TValue>) {
const [sorting, setSorting] = useState<SortingState>([]);
const table = useReactTable({
@@ -41,19 +31,14 @@ export function DataTable<TData, TValue>({
});
return (
<div className="rounded-md border">
<div className="rounded-md border overflow-x-auto">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<TableHead key={header.id}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
</TableHead>
))}
</TableRow>
@@ -62,14 +47,9 @@ export function DataTable<TData, TValue>({
<TableBody>
{table.getRowModel().rows?.length ? (
table.getRowModel().rows.map((row) => (
<TableRow
key={row.id}
data-state={row.getIsSelected() && "selected"}
>
<TableRow key={row.id} data-state={row.getIsSelected() && 'selected'}>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</TableCell>
<TableCell key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</TableCell>
))}
</TableRow>
))

View File

@@ -1,16 +1,17 @@
"use client";
'use client';
import { UserMenu } from "./user-menu";
import { Button } from "@/components/ui/button";
import { GlobalSearch } from "./global-search";
import { NotificationsDropdown } from "./notifications-dropdown";
import { UserMenu } from './user-menu';
import { GlobalSearch } from './global-search';
import { NotificationsDropdown } from './notifications-dropdown';
import { MobileSidebar } from './sidebar';
export function Header() {
return (
<header className="h-16 border-b bg-white flex items-center justify-between px-6 sticky top-0 z-10">
<div className="flex items-center gap-4 flex-1">
<h2 className="text-lg font-semibold text-gray-800">LCBP3-DMS</h2>
<div className="ml-4 w-full max-w-md">
<MobileSidebar />
<h2 className="text-lg font-semibold text-gray-800 hidden md:block">LCBP3-DMS</h2>
<div className="ml-0 md:ml-4 w-full max-w-md">
<GlobalSearch />
</div>
</div>

View File

@@ -1,8 +1,8 @@
"use client";
'use client';
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { cn } from '@/lib/utils';
import {
LayoutDashboard,
FileText,
@@ -14,10 +14,79 @@ import {
Menu,
Layers,
BookOpen,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import { useState } from "react";
import { Can } from "@/components/common/can";
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { useState } from 'react';
import { Can } from '@/components/common/can';
export const mainNavItems = [
{
title: 'Dashboard',
href: '/dashboard',
icon: LayoutDashboard,
permission: null, // Everyone can see
},
{
title: 'Correspondences',
href: '/correspondences',
icon: FileText,
permission: null,
},
{
title: 'RFAs',
href: '/rfas',
icon: FileCheck,
permission: null,
},
{
title: 'Drawings',
href: '/drawings',
icon: PenTool,
permission: null,
},
{
title: 'Circulations',
href: '/circulation',
icon: Layers, // Start with generic icon, maybe update import if needed
permission: null,
},
{
title: 'Transmittals',
href: '/transmittals',
icon: FileText,
permission: null,
},
{
title: 'Search',
href: '/search',
icon: Search,
permission: null,
},
{
title: 'Admin Panel',
href: '/admin',
icon: Shield,
permission: null,
},
{
title: 'Security',
href: '/admin/access-control/roles',
icon: Shield,
permission: 'system.manage_security',
},
{
title: 'System Logs',
href: '/admin/monitoring/system-logs/numbering',
icon: Layers,
permission: 'system.view_logs',
},
{
title: 'Reference Data',
href: '/admin/doc-control/reference',
icon: BookOpen,
permission: 'master_data.view',
},
];
interface SidebarProps {
className?: string;
@@ -27,94 +96,21 @@ export function Sidebar({ className }: SidebarProps) {
const pathname = usePathname();
const [collapsed, setCollapsed] = useState(false);
const navItems = [
{
title: "Dashboard",
href: "/dashboard",
icon: LayoutDashboard,
permission: null, // Everyone can see
},
{
title: "Correspondences",
href: "/correspondences",
icon: FileText,
permission: null,
},
{
title: "RFAs",
href: "/rfas",
icon: FileCheck,
permission: null,
},
{
title: "Drawings",
href: "/drawings",
icon: PenTool,
permission: null,
},
{
title: "Circulations",
href: "/circulation",
icon: Layers, // Start with generic icon, maybe update import if needed
permission: null,
},
{
title: "Transmittals",
href: "/transmittals",
icon: FileText,
permission: null,
},
{
title: "Search",
href: "/search",
icon: Search,
permission: null,
},
{
title: "Admin Panel",
href: "/admin",
icon: Shield,
permission: null,
},
{
title: "Security",
href: "/admin/security/roles",
icon: Shield,
permission: "system.manage_security",
},
{
title: "System Logs",
href: "/admin/system-logs/numbering",
icon: Layers,
permission: "system.view_logs",
},
{
title: "Reference Data",
href: "/admin/reference",
icon: BookOpen,
permission: "master_data.view",
},
];
return (
<div
className={cn(
"flex flex-col h-screen border-r bg-card transition-all duration-300",
collapsed ? "w-16" : "w-64",
'hidden md:flex flex-col h-screen border-r bg-card transition-all duration-300',
collapsed ? 'w-16' : 'w-64',
className
)}
>
<div className="h-16 flex items-center justify-between px-4 border-b">
{!collapsed && (
<span className="text-lg font-bold text-primary truncate">
LCBP3 DMS
</span>
)}
{!collapsed && <span className="text-lg font-bold text-primary truncate">LCBP3 DMS</span>}
<Button
variant="ghost"
size="icon"
onClick={() => setCollapsed(!collapsed)}
className={cn("ml-auto", collapsed && "mx-auto")}
className={cn('ml-auto', collapsed && 'mx-auto')}
>
<Menu className="h-5 w-5" />
</Button>
@@ -122,7 +118,7 @@ export function Sidebar({ className }: SidebarProps) {
<div className="flex-1 overflow-y-auto py-4">
<nav className="grid gap-1 px-2">
{navItems.map((item, index) => {
{mainNavItems.map((item, index) => {
const isActive = pathname.startsWith(item.href);
const LinkComponent = (
@@ -130,9 +126,9 @@ export function Sidebar({ className }: SidebarProps) {
key={index}
href={item.href}
className={cn(
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",
isActive ? "bg-accent text-accent-foreground" : "text-muted-foreground",
collapsed && "justify-center px-2"
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground',
isActive ? 'bg-accent text-accent-foreground' : 'text-muted-foreground',
collapsed && 'justify-center px-2'
)}
title={collapsed ? item.title : undefined}
>
@@ -158,8 +154,8 @@ export function Sidebar({ className }: SidebarProps) {
<Link
href="/settings"
className={cn(
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",
collapsed && "justify-center px-2"
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground',
collapsed && 'justify-center px-2'
)}
title="Settings"
>
@@ -170,3 +166,70 @@ export function Sidebar({ className }: SidebarProps) {
</div>
);
}
import { Sheet, SheetContent, SheetTrigger, SheetTitle } from '@/components/ui/sheet';
export function MobileSidebar() {
const pathname = usePathname();
const [open, setOpen] = useState(false);
return (
<Sheet open={open} onOpenChange={setOpen}>
<SheetTrigger asChild>
<Button variant="ghost" size="icon" className="md:hidden">
<Menu className="h-5 w-5" />
<span className="sr-only">Toggle navigation menu</span>
</Button>
</SheetTrigger>
<SheetContent side="left" className="w-64 p-0">
<SheetTitle className="sr-only">Mobile Navigation</SheetTitle>
<div className="h-16 flex items-center px-4 border-b">
<span className="text-lg font-bold text-primary truncate">LCBP3 DMS</span>
</div>
<div className="flex-1 overflow-y-auto py-4 h-[calc(100vh-4rem)]">
<nav className="grid gap-1 px-2">
{mainNavItems.map((item, index) => {
const isActive = pathname.startsWith(item.href);
const LinkComponent = (
<Link
key={index}
href={item.href}
onClick={() => setOpen(false)}
className={cn(
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground',
isActive ? 'bg-accent text-accent-foreground' : 'text-muted-foreground'
)}
>
<item.icon className="h-5 w-5" />
<span>{item.title}</span>
</Link>
);
if (item.permission) {
return (
<Can key={index} permission={item.permission}>
{LinkComponent}
</Can>
);
}
return LinkComponent;
})}
</nav>
<div className="p-4 mt-auto border-t absolute bottom-0 w-full left-0 bg-background">
<Link
href="/settings"
onClick={() => setOpen(false)}
className="flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
>
<Settings className="h-5 w-5" />
<span>Settings</span>
</Link>
</div>
</div>
</SheetContent>
</Sheet>
);
}

View File

@@ -0,0 +1,140 @@
"use client"
import * as React from "react"
import * as SheetPrimitive from "@radix-ui/react-dialog"
import { cva, type VariantProps } from "class-variance-authority"
import { X } from "lucide-react"
import { cn } from "@/lib/utils"
const Sheet = SheetPrimitive.Root
const SheetTrigger = SheetPrimitive.Trigger
const SheetClose = SheetPrimitive.Close
const SheetPortal = SheetPrimitive.Portal
const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
ref={ref}
/>
))
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName
const sheetVariants = cva(
"fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",
{
variants: {
side: {
top: "inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
bottom:
"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
left: "inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
right:
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
},
},
defaultVariants: {
side: "right",
},
}
)
interface SheetContentProps
extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
VariantProps<typeof sheetVariants> {}
const SheetContent = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Content>,
SheetContentProps
>(({ side = "right", className, children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(sheetVariants({ side }), className)}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<X className="h-4 w-4" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
))
SheetContent.displayName = SheetPrimitive.Content.displayName
const SheetHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className
)}
{...props}
/>
)
SheetHeader.displayName = "SheetHeader"
const SheetFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
SheetFooter.displayName = "SheetFooter"
const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold text-foreground", className)}
{...props}
/>
))
SheetTitle.displayName = SheetPrimitive.Title.displayName
const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
SheetDescription.displayName = SheetPrimitive.Description.displayName
export {
Sheet,
SheetPortal,
SheetOverlay,
SheetTrigger,
SheetClose,
SheetContent,
SheetHeader,
SheetFooter,
SheetTitle,
SheetDescription,
}