251205:0000 Just start debug backend/frontend

This commit is contained in:
2025-12-05 00:32:02 +07:00
parent dc8b80c5f9
commit 2865bebdb1
88 changed files with 6751 additions and 1016 deletions

View File

@@ -0,0 +1,66 @@
"use client";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import Link from "next/link";
import { PendingTask } from "@/types/dashboard";
import { AlertCircle, ArrowRight } from "lucide-react";
interface PendingTasksProps {
tasks: PendingTask[];
}
export function PendingTasks({ tasks }: PendingTasksProps) {
return (
<Card className="h-full">
<CardHeader>
<CardTitle className="text-lg flex items-center gap-2">
Pending Tasks
{tasks.length > 0 && (
<Badge variant="destructive" className="rounded-full h-5 w-5 p-0 flex items-center justify-center text-[10px]">
{tasks.length}
</Badge>
)}
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
{tasks.length === 0 ? (
<p className="text-sm text-muted-foreground text-center py-4">
No pending tasks. Good job!
</p>
) : (
tasks.map((task) => (
<Link
key={task.id}
href={task.url}
className="block p-3 bg-muted/40 rounded-lg border hover:bg-muted/60 transition-colors group"
>
<div className="flex items-start justify-between mb-1">
<span className="text-sm font-medium group-hover:text-primary transition-colors">
{task.title}
</span>
{task.daysOverdue > 0 ? (
<Badge variant="destructive" className="text-[10px] h-5 px-1.5">
{task.daysOverdue}d overdue
</Badge>
) : (
<Badge variant="outline" className="text-[10px] h-5 px-1.5 bg-yellow-50 text-yellow-700 border-yellow-200">
Due Soon
</Badge>
)}
</div>
<p className="text-xs text-muted-foreground line-clamp-1 mb-2">
{task.description}
</p>
<div className="flex items-center text-xs text-primary font-medium">
View Details <ArrowRight className="ml-1 h-3 w-3" />
</div>
</Link>
))
)}
</div>
</CardContent>
</Card>
);
}

View File

@@ -0,0 +1,30 @@
"use client";
import { Button } from "@/components/ui/button";
import { PlusCircle, Upload, FileText } from "lucide-react";
import Link from "next/link";
export function QuickActions() {
return (
<div className="flex gap-3 overflow-x-auto pb-2">
<Link href="/rfas/new">
<Button className="bg-blue-600 hover:bg-blue-700">
<PlusCircle className="mr-2 h-4 w-4" />
New RFA
</Button>
</Link>
<Link href="/correspondences/new">
<Button variant="outline">
<FileText className="mr-2 h-4 w-4" />
New Correspondence
</Button>
</Link>
<Link href="/drawings/upload">
<Button variant="outline">
<Upload className="mr-2 h-4 w-4" />
Upload Drawing
</Button>
</Link>
</div>
);
}

View File

@@ -1,87 +1,55 @@
// File: components/dashboard/recent-activity.tsx
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/avatar";
"use client";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import { formatDistanceToNow } from "date-fns";
import { ActivityLog } from "@/types/dashboard";
import Link from "next/link";
// Type จำลองตามโครงสร้าง v_audit_log_details
type AuditLogItem = {
audit_id: number;
username: string;
email: string;
action: string;
entity_type: string;
entity_id: string;
created_at: string;
avatar?: string;
};
interface RecentActivityProps {
activities: ActivityLog[];
}
// Mock Data
const recentActivities: AuditLogItem[] = [
{
audit_id: 1,
username: "Editor01",
email: "editor01@example.com",
action: "rfa.create",
entity_type: "RFA",
entity_id: "LCBP3-RFA-STR-001",
created_at: "2025-11-26T09:00:00Z",
},
{
audit_id: 2,
username: "Superadmin",
email: "admin@example.com",
action: "user.create",
entity_type: "User",
entity_id: "new_user_01",
created_at: "2025-11-26T10:30:00Z",
},
{
audit_id: 3,
username: "Viewer01",
email: "viewer01@example.com",
action: "document.view",
entity_type: "Correspondence",
entity_id: "LCBP3-LET-GEN-005",
created_at: "2025-11-26T11:15:00Z",
},
{
audit_id: 4,
username: "Editor01",
email: "editor01@example.com",
action: "shop_drawing.upload",
entity_type: "Shop Drawing",
entity_id: "SHP-STR-COL-01",
created_at: "2025-11-26T13:45:00Z",
},
];
export function RecentActivity() {
export function RecentActivity({ activities }: RecentActivityProps) {
return (
<Card className="col-span-3 lg:col-span-1">
<Card className="h-full">
<CardHeader>
<CardTitle>Recent Activity</CardTitle>
<CardTitle className="text-lg">Recent Activity</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-8">
{recentActivities.map((item) => (
<div key={item.audit_id} className="flex items-center">
<Avatar className="h-9 w-9">
<AvatarImage src={item.avatar} alt={item.username} />
<AvatarFallback>{item.username[0] + item.username[1]}</AvatarFallback>
<div className="space-y-6">
{activities.map((activity) => (
<div
key={activity.id}
className="flex gap-4 pb-4 border-b last:border-0 last:pb-0"
>
<Avatar className="h-10 w-10 border">
<AvatarFallback className="bg-primary/10 text-primary font-medium">
{activity.user.initials}
</AvatarFallback>
</Avatar>
<div className="ml-4 space-y-1">
<p className="text-sm font-medium leading-none">
{item.username}
</p>
<p className="text-sm text-muted-foreground">
{formatActionMessage(item)}
</p>
</div>
<div className="ml-auto text-xs text-muted-foreground">
{new Date(item.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
<div className="flex-1 space-y-1">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<span className="font-semibold text-sm">{activity.user.name}</span>
<Badge variant="secondary" className="text-[10px] h-5 px-1.5 font-normal">
{activity.action}
</Badge>
</div>
<span className="text-xs text-muted-foreground">
{formatDistanceToNow(new Date(activity.createdAt), {
addSuffix: true,
})}
</span>
</div>
<Link href={activity.targetUrl} className="block group">
<p className="text-sm text-foreground group-hover:text-primary transition-colors">
{activity.description}
</p>
</Link>
</div>
</div>
))}
@@ -90,19 +58,3 @@ export function RecentActivity() {
</Card>
);
}
function formatActionMessage(item: AuditLogItem) {
// Simple formatter for demo. In real app, use translation or mapping.
switch (item.action) {
case "rfa.create":
return `Created RFA ${item.entity_id}`;
case "user.create":
return `Created new user ${item.entity_id}`;
case "document.view":
return `Viewed document ${item.entity_id}`;
case "shop_drawing.upload":
return `Uploaded drawing ${item.entity_id}`;
default:
return `Performed ${item.action}`;
}
}

View File

@@ -0,0 +1,64 @@
"use client";
import { Card } from "@/components/ui/card";
import { FileText, Clipboard, CheckCircle, Clock } from "lucide-react";
import { DashboardStats } from "@/types/dashboard";
interface StatsCardsProps {
stats: DashboardStats;
}
export function StatsCards({ stats }: StatsCardsProps) {
const cards = [
{
title: "Total Correspondences",
value: stats.correspondences,
icon: FileText,
color: "text-blue-600",
bgColor: "bg-blue-50",
},
{
title: "Active RFAs",
value: stats.rfas,
icon: Clipboard,
color: "text-purple-600",
bgColor: "bg-purple-50",
},
{
title: "Approved Documents",
value: stats.approved,
icon: CheckCircle,
color: "text-green-600",
bgColor: "bg-green-50",
},
{
title: "Pending Approvals",
value: stats.pending,
icon: Clock,
color: "text-orange-600",
bgColor: "bg-orange-50",
},
];
return (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
{cards.map((card) => {
const Icon = card.icon;
return (
<Card key={card.title} className="p-6 hover:shadow-sm transition-shadow">
<div className="flex items-center justify-between">
<div>
<p className="text-sm font-medium text-muted-foreground">{card.title}</p>
<p className="text-3xl font-bold mt-2">{card.value}</p>
</div>
<div className={`p-3 rounded-lg ${card.bgColor}`}>
<Icon className={`h-6 w-6 ${card.color}`} />
</div>
</div>
</Card>
);
})}
</div>
);
}