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,22 @@
import { correspondenceApi } from "@/lib/api/correspondences";
import { CorrespondenceDetail } from "@/components/correspondences/detail";
import { notFound } from "next/navigation";
export default async function CorrespondenceDetailPage({
params,
}: {
params: { id: string };
}) {
const id = parseInt(params.id);
if (isNaN(id)) {
notFound();
}
const correspondence = await correspondenceApi.getById(id);
if (!correspondence) {
notFound();
}
return <CorrespondenceDetail data={correspondence} />;
}

View File

@@ -1,355 +1,18 @@
// File: app/(dashboard)/correspondences/new/page.tsx
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { format } from "date-fns";
import { CalendarIcon, ChevronLeft, Save, Loader2, Send } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { Calendar } from "@/components/ui/calendar";
import { FileUpload } from "@/components/forms/file-upload";
import { cn } from "@/lib/utils";
// --- Schema Definition ---
const correspondenceSchema = z.object({
projectId: z.string().min(1, "กรุณาเลือกโครงการ"),
originatorId: z.string().min(1, "กรุณาเลือกองค์กรผู้ส่ง"),
type: z.string().min(1, "กรุณาเลือกประเภทเอกสาร"),
discipline: z.string().optional(), // สำหรับ RFA/Letter ที่มีสาขา
subType: z.string().optional(), // สำหรับแบ่งประเภทย่อย
recipientId: z.string().min(1, "กรุณาเลือกผู้รับ (To)"),
subject: z.string().min(5, "หัวข้อต้องยาวอย่างน้อย 5 ตัวอักษร"),
message: z.string().optional(),
replyRequiredBy: z.date().optional(),
});
type FormValues = z.infer<typeof correspondenceSchema>;
// --- Mock Data for Dropdowns ---
const projects = [
{ id: "1", code: "LCBP3-C1", name: "งานก่อสร้างงานทางทะเล (ส่วนที่ 1)" },
{ id: "2", code: "LCBP3-C2", name: "งานก่อสร้างอาคาร (ส่วนที่ 2)" },
];
const organizations = [
{ id: "1", code: "PAT", name: "การท่าเรือฯ (Owner)" },
{ id: "2", code: "CSC", name: "ที่ปรึกษาคุมงาน (Consult)" },
{ id: "3", code: "CNNC", name: "ผู้รับเหมา C1" },
];
const docTypes = [
{ id: "LET", name: "Letter (จดหมาย)" },
{ id: "MEM", name: "Memo (บันทึกข้อความ)" },
{ id: "RFA", name: "RFA (ขออนุมัติ)" },
{ id: "RFI", name: "RFI (ขอข้อมูล)" },
];
const disciplines = [
{ id: "GEN", name: "General (ทั่วไป)" },
{ id: "STR", name: "Structural (โครงสร้าง)" },
{ id: "ARC", name: "Architectural (สถาปัตยกรรม)" },
{ id: "MEP", name: "MEP (งานระบบ)" },
];
export default function CreateCorrespondencePage() {
const router = useRouter();
const [isLoading, setIsLoading] = useState(false);
const [files, setFiles] = useState<File[]>([]);
// React Hook Form
const {
register,
handleSubmit,
setValue,
watch,
formState: { errors },
} = useForm<FormValues>({
resolver: zodResolver(correspondenceSchema),
defaultValues: {
originatorId: "3", // Default เป็น Org ของ User (Mock: CNNC)
},
});
// Watch values to update dynamic parts
const selectedProject = watch("projectId");
const selectedType = watch("type");
const selectedDiscipline = watch("discipline");
// Logic จำลองการ Preview เลขที่เอกสาร (Document Numbering)
const getPreviewNumber = () => {
if (!selectedProject || !selectedType) return "---";
const proj = projects.find(p => p.id === selectedProject)?.code || "PROJ";
const type = selectedType;
const disc = selectedDiscipline ? `-${selectedDiscipline}` : "";
return `${proj}-${type}${disc}-0001 (Draft)`;
};
const onSubmit = async (data: FormValues) => {
setIsLoading(true);
try {
console.log("Form Data:", data);
console.log("Files:", files);
// Simulate API call
await new Promise((resolve) => setTimeout(resolve, 1500));
alert("บันทึกเอกสารเรียบร้อยแล้ว");
router.push("/correspondences");
} catch (error) {
console.error(error);
alert("เกิดข้อผิดพลาดในการบันทึก");
} finally {
setIsLoading(false);
}
};
import { CorrespondenceForm } from "@/components/correspondences/form";
export default function NewCorrespondencePage() {
return (
<div className="max-w-4xl mx-auto space-y-6 pb-10">
{/* Header */}
<div className="flex items-center gap-4">
<Button variant="outline" size="icon" onClick={() => router.back()}>
<ChevronLeft className="h-5 w-5" />
</Button>
<div>
<h2 className="text-2xl font-bold tracking-tight">Create Correspondence</h2>
<p className="text-muted-foreground">
</p>
</div>
<div className="max-w-4xl mx-auto py-6">
<div className="mb-8">
<h1 className="text-3xl font-bold">New Correspondence</h1>
<p className="text-muted-foreground mt-1">
Create a new official letter or communication record.
</p>
</div>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-8">
{/* Section 1: Basic Info */}
<Card>
<CardHeader>
<CardTitle> (Basic Information)</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent className="grid gap-6 md:grid-cols-2">
{/* Project Select */}
<div className="space-y-2">
<Label className="after:content-['*'] after:text-red-500"> (Project)</Label>
<Select onValueChange={(val) => setValue("projectId", val)}>
<SelectTrigger className={errors.projectId ? "border-destructive" : ""}>
<SelectValue placeholder="เลือกโครงการ..." />
</SelectTrigger>
<SelectContent>
{projects.map((p) => (
<SelectItem key={p.id} value={p.id}>{p.name}</SelectItem>
))}
</SelectContent>
</Select>
{errors.projectId && <p className="text-xs text-destructive">{errors.projectId.message}</p>}
</div>
{/* Document Type Select */}
<div className="space-y-2">
<Label className="after:content-['*'] after:text-red-500"> (Type)</Label>
<Select onValueChange={(val) => setValue("type", val)}>
<SelectTrigger className={errors.type ? "border-destructive" : ""}>
<SelectValue placeholder="เลือกประเภท..." />
</SelectTrigger>
<SelectContent>
{docTypes.map((t) => (
<SelectItem key={t.id} value={t.id}>{t.name}</SelectItem>
))}
</SelectContent>
</Select>
{errors.type && <p className="text-xs text-destructive">{errors.type.message}</p>}
</div>
{/* Discipline (Conditional) */}
<div className="space-y-2">
<Label> (Discipline)</Label>
<Select onValueChange={(val) => setValue("discipline", val)}>
<SelectTrigger>
<SelectValue placeholder="ระบุสาขา (ถ้ามี)..." />
</SelectTrigger>
<SelectContent>
{disciplines.map((d) => (
<SelectItem key={d.id} value={d.id}>{d.name}</SelectItem>
))}
</SelectContent>
</Select>
<p className="text-[10px] text-muted-foreground"> RFA/RFI </p>
</div>
{/* Originator (Sender) */}
<div className="space-y-2">
<Label className="after:content-['*'] after:text-red-500"> (From)</Label>
<Select defaultValue="3" onValueChange={(val) => setValue("originatorId", val)} disabled>
<SelectTrigger>
<SelectValue placeholder="Select Originator" />
</SelectTrigger>
<SelectContent>
{organizations.map((o) => (
<SelectItem key={o.id} value={o.id}>{o.name}</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* Document Number Preview */}
<div className="md:col-span-2 p-4 bg-muted/30 rounded-lg border border-dashed flex items-center justify-between">
<span className="text-sm font-medium text-muted-foreground">Preview Document No:</span>
<span className="font-mono text-lg font-bold text-primary">{getPreviewNumber()}</span>
</div>
</CardContent>
</Card>
{/* Section 2: Details & Recipients */}
<Card>
<CardHeader>
<CardTitle> (Details & Recipients)</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
{/* Recipient */}
<div className="space-y-2">
<Label className="after:content-['*'] after:text-red-500"> (To)</Label>
<Select onValueChange={(val) => setValue("recipientId", val)}>
<SelectTrigger className={errors.recipientId ? "border-destructive" : ""}>
<SelectValue placeholder="เลือกหน่วยงานผู้รับ..." />
</SelectTrigger>
<SelectContent>
{organizations.filter(o => o.id !== "3").map((o) => (
<SelectItem key={o.id} value={o.id}>{o.name}</SelectItem>
))}
</SelectContent>
</Select>
{errors.recipientId && <p className="text-xs text-destructive">{errors.recipientId.message}</p>}
</div>
{/* Subject */}
<div className="space-y-2">
<Label className="after:content-['*'] after:text-red-500"> (Subject)</Label>
<Input
placeholder="ระบุหัวข้อเอกสาร..."
className={errors.subject ? "border-destructive" : ""}
{...register("subject")}
/>
{errors.subject && <p className="text-xs text-destructive">{errors.subject.message}</p>}
</div>
{/* Message/Body */}
<div className="space-y-2">
<Label> (Message)</Label>
<Textarea
placeholder="พิมพ์รายละเอียดเพิ่มเติม..."
className="min-h-[120px]"
{...register("message")}
/>
</div>
{/* Reply Required Date */}
<div className="flex flex-col space-y-2">
<Label> (Reply Required By)</Label>
<Popover>
<PopoverTrigger asChild>
<Button
variant={"outline"}
className={cn(
"w-[240px] pl-3 text-left font-normal",
!watch("replyRequiredBy") && "text-muted-foreground"
)}
>
{watch("replyRequiredBy") ? (
format(watch("replyRequiredBy")!, "PPP")
) : (
<span>Pick a date</span>
)}
<CalendarIcon className="ml-auto h-4 w-4 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={watch("replyRequiredBy")}
onSelect={(date) => setValue("replyRequiredBy", date)}
disabled={(date) => date < new Date()}
initialFocus
/>
</PopoverContent>
</Popover>
</div>
</CardContent>
</Card>
{/* Section 3: Attachments */}
<Card>
<CardHeader>
<CardTitle> (Attachments)</CardTitle>
<CardDescription>
PDF, DWG, Office ( 50MB )
</CardDescription>
</CardHeader>
<CardContent>
<FileUpload
onFilesChange={setFiles}
maxFiles={10}
accept=".pdf,.doc,.docx,.xls,.xlsx,.dwg,.zip,.jpg,.png"
/>
</CardContent>
</Card>
{/* Actions */}
<div className="flex justify-end gap-4">
<Button variant="outline" type="button" onClick={() => router.back()} disabled={isLoading}>
</Button>
<Button type="submit" disabled={isLoading} className="min-w-[120px]">
{isLoading ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> Saving...
</>
) : (
<>
<Save className="mr-2 h-4 w-4" /> Save as Draft
</>
)}
</Button>
<Button type="submit" disabled={isLoading} className="min-w-[120px] bg-green-600 hover:bg-green-700">
{isLoading ? (
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
) : (
<Send className="mr-2 h-4 w-4" />
)}
Submit
</Button>
</div>
</form>
<div className="bg-card border rounded-lg p-6 shadow-sm">
<CorrespondenceForm />
</div>
</div>
);
}
}

View File

@@ -1,290 +1,50 @@
// File: app/(dashboard)/correspondences/page.tsx
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import {
Plus,
Search,
Filter,
MoreHorizontal,
FileText,
Calendar,
Eye
} from "lucide-react";
import { CorrespondenceList } from "@/components/correspondences/list";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
import { Checkbox } from "@/components/ui/checkbox";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Card, CardContent, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
import Link from "next/link";
import { Plus } from "lucide-react";
import { correspondenceApi } from "@/lib/api/correspondences";
import { Pagination } from "@/components/common/pagination";
// --- Type Definitions ---
type Correspondence = {
id: string;
documentNumber: string;
subject: string;
type: "Letter" | "Memo" | "RFI" | "Transmittal";
status: "Draft" | "Submitted" | "Approved" | "Rejected";
project: string;
date: string;
from: string;
to: string;
};
// --- Mock Data ---
const mockData: Correspondence[] = [
{
id: "1",
documentNumber: "LCBP3-LET-GEN-001",
subject: "Submission of Monthly Progress Report - January 2025",
type: "Letter",
status: "Submitted",
project: "LCBP3-C1",
date: "2025-01-05",
from: "CNNC",
to: "PAT",
},
{
id: "2",
documentNumber: "LCBP3-RFI-STR-024",
subject: "Clarification on Beam Reinforcement Detail at Zone A",
type: "RFI",
status: "Approved",
project: "LCBP3-C2",
date: "2025-01-10",
from: "ITD-NWR",
to: "TEAM",
},
{
id: "3",
documentNumber: "LCBP3-MEMO-HR-005",
subject: "Site Access Protocol Update",
type: "Memo",
status: "Draft",
project: "LCBP3",
date: "2025-01-12",
from: "PAT",
to: "All Contractors",
},
{
id: "4",
documentNumber: "LCBP3-TRN-STR-011",
subject: "Transmittal of Shop Drawings for Piling Works",
type: "Transmittal",
status: "Submitted",
project: "LCBP3-C1",
date: "2025-01-15",
from: "CNNC",
to: "CSC",
},
];
export default function CorrespondencesPage() {
const router = useRouter();
const [searchTerm, setSearchTerm] = useState("");
const [typeFilter, setTypeFilter] = useState("ALL");
// Filter Logic
const filteredData = mockData.filter((item) => {
const matchesSearch =
item.subject.toLowerCase().includes(searchTerm.toLowerCase()) ||
item.documentNumber.toLowerCase().includes(searchTerm.toLowerCase());
const matchesType = typeFilter === "ALL" || item.type === typeFilter;
return matchesSearch && matchesType;
export default async function CorrespondencesPage({
searchParams,
}: {
searchParams: { page?: string; status?: string; search?: string };
}) {
const page = parseInt(searchParams.page || "1");
const data = await correspondenceApi.getAll({
page,
status: searchParams.status,
search: searchParams.search,
});
const getStatusVariant = (status: string) => {
switch (status) {
case "Approved": return "success";
case "Rejected": return "destructive";
case "Draft": return "secondary";
default: return "default"; // Submitted
}
};
const handleCreate = () => {
router.push("/correspondences/new");
};
return (
<div className="space-y-6">
{/* Header */}
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
<div className="flex justify-between items-center">
<div>
<h2 className="text-2xl font-bold tracking-tight">Correspondences</h2>
<p className="text-muted-foreground">
-
<h1 className="text-3xl font-bold">Correspondences</h1>
<p className="text-muted-foreground mt-1">
Manage official letters and communications
</p>
</div>
<Button onClick={handleCreate} className="w-full md:w-auto">
<Plus className="mr-2 h-4 w-4" />
</Button>
</div>
{/* Toolbar (Search & Filter) */}
<div className="flex flex-col gap-4 md:flex-row md:items-center">
<div className="relative flex-1">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
<Input
placeholder="ค้นหาจากเลขที่เอกสาร หรือ หัวข้อ..."
className="pl-8"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
</div>
<div className="flex gap-2">
<Select defaultValue="ALL" onValueChange={setTypeFilter}>
<SelectTrigger className="w-[150px]">
<SelectValue placeholder="ประเภทเอกสาร" />
</SelectTrigger>
<SelectContent>
<SelectItem value="ALL"></SelectItem>
<SelectItem value="Letter">Letter</SelectItem>
<SelectItem value="Memo">Memo</SelectItem>
<SelectItem value="RFI">RFI</SelectItem>
<SelectItem value="Transmittal">Transmittal</SelectItem>
</SelectContent>
</Select>
<Button variant="outline" size="icon">
<Filter className="h-4 w-4" />
<Link href="/correspondences/new">
<Button>
<Plus className="mr-2 h-4 w-4" />
New Correspondence
</Button>
</div>
</Link>
</div>
{/* Desktop View: Table */}
<div className="hidden rounded-md border bg-card md:block">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[40px]">
<Checkbox />
</TableHead>
<TableHead>Document No.</TableHead>
<TableHead className="w-[400px]">Subject</TableHead>
<TableHead>Type</TableHead>
<TableHead>From/To</TableHead>
<TableHead>Date</TableHead>
<TableHead>Status</TableHead>
<TableHead className="text-right">Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{filteredData.map((item) => (
<TableRow key={item.id} className="cursor-pointer hover:bg-muted/50" onClick={() => router.push(`/correspondences/${item.id}`)}>
<TableCell onClick={(e) => e.stopPropagation()}>
<Checkbox />
</TableCell>
<TableCell className="font-medium text-primary">
{item.documentNumber}
<div className="text-xs text-muted-foreground mt-0.5">{item.project}</div>
</TableCell>
<TableCell>
<span className="line-clamp-2">{item.subject}</span>
</TableCell>
<TableCell>{item.type}</TableCell>
<TableCell>
<div className="text-xs">
<div className="text-muted-foreground">From: <span className="text-foreground font-medium">{item.from}</span></div>
<div className="text-muted-foreground">To: <span className="text-foreground font-medium">{item.to}</span></div>
</div>
</TableCell>
<TableCell>{item.date}</TableCell>
<TableCell>
<Badge variant={getStatusVariant(item.status)}>{item.status}</Badge>
</TableCell>
<TableCell className="text-right">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-8 w-8 p-0">
<span className="sr-only">Open menu</span>
<MoreHorizontal className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Actions</DropdownMenuLabel>
<DropdownMenuItem onClick={(e) => { e.stopPropagation(); router.push(`/correspondences/${item.id}`); }}>
View Details
</DropdownMenuItem>
<DropdownMenuItem>Download PDF</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem>Create Transmittal</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
{/* Filters component could go here */}
{/* Mobile View: Cards */}
<div className="grid gap-4 md:hidden">
{filteredData.map((item) => (
<Card key={item.id} onClick={() => router.push(`/correspondences/${item.id}`)}>
<CardHeader className="pb-2">
<div className="flex justify-between items-start">
<div className="flex flex-col">
<Badge variant="outline" className="w-fit mb-2">{item.type}</Badge>
<CardTitle className="text-base font-bold">{item.documentNumber}</CardTitle>
</div>
<Badge variant={getStatusVariant(item.status)}>{item.status}</Badge>
</div>
</CardHeader>
<CardContent className="pb-2 text-sm">
<p className="line-clamp-2 mb-3">{item.subject}</p>
<div className="grid grid-cols-2 gap-2 text-muted-foreground">
<div className="flex items-center gap-1">
<FileText className="h-3 w-3" /> {item.project}
</div>
<div className="flex items-center gap-1">
<Calendar className="h-3 w-3" /> {item.date}
</div>
</div>
<div className="mt-3 pt-3 border-t grid grid-cols-2 gap-2 text-xs">
<div>
<span className="text-muted-foreground block">From</span>
<span className="font-medium">{item.from}</span>
</div>
<div>
<span className="text-muted-foreground block">To</span>
<span className="font-medium">{item.to}</span>
</div>
</div>
</CardContent>
<CardFooter className="pt-2">
<Button variant="ghost" size="sm" className="w-full text-primary">
<Eye className="mr-2 h-4 w-4" /> View Details
</Button>
</CardFooter>
</Card>
))}
<CorrespondenceList data={data} />
<div className="mt-4">
<Pagination
currentPage={data.page}
totalPages={data.totalPages}
total={data.total}
/>
</div>
</div>
);
}
}

View File

@@ -1,67 +1,39 @@
// File: app/(dashboard)/dashboard/page.tsx
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { StatsCards } from "@/components/dashboard/stats-cards";
import { RecentActivity } from "@/components/dashboard/recent-activity";
import { PendingTasks } from "@/components/dashboard/pending-tasks";
import { QuickActions } from "@/components/dashboard/quick-actions";
import { dashboardApi } from "@/lib/api/dashboard";
export default async function DashboardPage() {
// Fetch data in parallel
const [stats, activities, tasks] = await Promise.all([
dashboardApi.getStats(),
dashboardApi.getRecentActivity(),
dashboardApi.getPendingTasks(),
]);
export default function DashboardPage() {
return (
<div className="flex flex-col gap-4">
{/* Header Section */}
<div className="flex items-center">
<h1 className="text-lg font-semibold md:text-2xl">Dashboard</h1>
</div>
{/* KPI Cards Section */}
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">12</div>
<p className="text-xs text-muted-foreground">
+2
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
RFAs
</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">24</div>
<p className="text-xs text-muted-foreground">
</p>
</CardContent>
</Card>
{/* Add more KPI cards as needed */}
<div className="space-y-8">
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div>
<h1 className="text-3xl font-bold tracking-tight">Dashboard</h1>
<p className="text-muted-foreground mt-1">
Welcome back! Here's an overview of your project status.
</p>
</div>
<QuickActions />
</div>
{/* Main Content Section (My Tasks + Recent Activity) */}
<div className="grid gap-4 md:gap-8 lg:grid-cols-3">
{/* Content Area หลัก (My Tasks) กินพื้นที่ 2 ส่วน */}
<Card className="lg:col-span-2">
<CardHeader>
<CardTitle> (My Tasks)</CardTitle>
</CardHeader>
<CardContent>
<div className="h-[300px] w-full rounded bg-muted/20 flex items-center justify-center text-muted-foreground">
Table Placeholder (My Tasks)
</div>
</CardContent>
</Card>
<StatsCards stats={stats} />
{/* Recent Activity กินพื้นที่ 1 ส่วนด้านขวา */}
<RecentActivity />
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div className="lg:col-span-2">
<RecentActivity activities={activities} />
</div>
<div className="lg:col-span-1">
<PendingTasks tasks={tasks} />
</div>
</div>
</div>
);
}
}

View File

@@ -0,0 +1,112 @@
import { drawingApi } from "@/lib/api/drawings";
import { notFound } from "next/navigation";
import { Button } from "@/components/ui/button";
import { ArrowLeft, Download, FileText, GitCompare } from "lucide-react";
import Link from "next/link";
import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { RevisionHistory } from "@/components/drawings/revision-history";
import { format } from "date-fns";
export default async function DrawingDetailPage({
params,
}: {
params: { id: string };
}) {
const id = parseInt(params.id);
if (isNaN(id)) {
notFound();
}
const drawing = await drawingApi.getById(id);
if (!drawing) {
notFound();
}
return (
<div className="space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<Link href="/drawings">
<Button variant="ghost" size="icon">
<ArrowLeft className="h-5 w-5" />
</Button>
</Link>
<div>
<h1 className="text-2xl font-bold">{drawing.drawing_number}</h1>
<p className="text-muted-foreground">
{drawing.title}
</p>
</div>
</div>
<div className="flex gap-2">
<Button variant="outline">
<Download className="mr-2 h-4 w-4" />
Download Current
</Button>
{drawing.revision_count > 1 && (
<Button variant="outline">
<GitCompare className="mr-2 h-4 w-4" />
Compare Revisions
</Button>
)}
</div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Main Info */}
<div className="lg:col-span-2 space-y-6">
<Card>
<CardHeader>
<div className="flex justify-between items-start">
<CardTitle className="text-xl">Drawing Details</CardTitle>
<Badge>{drawing.type}</Badge>
</div>
</CardHeader>
<CardContent className="space-y-6">
<div className="grid grid-cols-2 gap-6">
<div>
<p className="text-sm font-medium text-muted-foreground">Discipline</p>
<p className="font-medium mt-1">{drawing.discipline?.discipline_name} ({drawing.discipline?.discipline_code})</p>
</div>
<div>
<p className="text-sm font-medium text-muted-foreground">Sheet Number</p>
<p className="font-medium mt-1">{drawing.sheet_number}</p>
</div>
<div>
<p className="text-sm font-medium text-muted-foreground">Scale</p>
<p className="font-medium mt-1">{drawing.scale || "N/A"}</p>
</div>
<div>
<p className="text-sm font-medium text-muted-foreground">Latest Issue Date</p>
<p className="font-medium mt-1">{format(new Date(drawing.issue_date), "dd MMM yyyy")}</p>
</div>
</div>
<Separator />
<div>
<h3 className="font-semibold mb-3">Preview</h3>
<div className="aspect-video bg-muted rounded-lg flex items-center justify-center border-2 border-dashed">
<div className="text-center">
<FileText className="h-12 w-12 mx-auto text-muted-foreground mb-2" />
<p className="text-muted-foreground">PDF Preview Placeholder</p>
</div>
</div>
</div>
</CardContent>
</Card>
</div>
{/* Revisions */}
<div className="space-y-6">
<RevisionHistory revisions={drawing.revisions || []} />
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,43 @@
"use client";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { DrawingList } from "@/components/drawings/list";
import { Button } from "@/components/ui/button";
import { Upload } from "lucide-react";
import Link from "next/link";
export default function DrawingsPage() {
return (
<div className="space-y-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-3xl font-bold">Drawings</h1>
<p className="text-muted-foreground mt-1">
Manage contract and shop drawings
</p>
</div>
<Link href="/drawings/upload">
<Button>
<Upload className="mr-2 h-4 w-4" />
Upload Drawing
</Button>
</Link>
</div>
<Tabs defaultValue="contract" className="w-full">
<TabsList className="grid w-full grid-cols-2 max-w-[400px]">
<TabsTrigger value="contract">Contract Drawings</TabsTrigger>
<TabsTrigger value="shop">Shop Drawings</TabsTrigger>
</TabsList>
<TabsContent value="contract" className="mt-6">
<DrawingList type="CONTRACT" />
</TabsContent>
<TabsContent value="shop" className="mt-6">
<DrawingList type="SHOP" />
</TabsContent>
</Tabs>
</div>
);
}

View File

@@ -0,0 +1,16 @@
import { DrawingUploadForm } from "@/components/drawings/upload-form";
export default function DrawingUploadPage() {
return (
<div className="max-w-4xl mx-auto py-6">
<div className="mb-8">
<h1 className="text-3xl font-bold">Upload Drawing</h1>
<p className="text-muted-foreground mt-1">
Upload a new contract or shop drawing revision.
</p>
</div>
<DrawingUploadForm />
</div>
);
}

View File

@@ -1,7 +1,5 @@
// File: app/(dashboard)/layout.tsx
import { Header } from "@/components/layout/header";
import { Sidebar } from "@/components/layout/sidebar";
import { Navbar } from "@/components/layout/navbar";
import { DashboardShell } from "@/components/layout/dashboard-shell"; // Import Wrapper
export default function DashboardLayout({
children,
@@ -9,17 +7,14 @@ export default function DashboardLayout({
children: React.ReactNode;
}) {
return (
<div className="relative min-h-screen bg-muted/10">
{/* Sidebar (Fixed Position) */}
<div className="flex min-h-screen bg-background">
<Sidebar />
{/* Main Content (Dynamic Margin) */}
<DashboardShell>
<Navbar />
<main className="flex-1 p-4 lg:p-6 overflow-x-hidden">
<div className="flex-1 flex flex-col min-h-screen overflow-hidden">
<Header />
<main className="flex-1 overflow-y-auto p-6 bg-muted/10">
{children}
</main>
</DashboardShell>
</div>
</div>
);
}
}

View File

@@ -0,0 +1,22 @@
import { rfaApi } from "@/lib/api/rfas";
import { RFADetail } from "@/components/rfas/detail";
import { notFound } from "next/navigation";
export default async function RFADetailPage({
params,
}: {
params: { id: string };
}) {
const id = parseInt(params.id);
if (isNaN(id)) {
notFound();
}
const rfa = await rfaApi.getById(id);
if (!rfa) {
notFound();
}
return <RFADetail data={rfa} />;
}

View File

@@ -0,0 +1,16 @@
import { RFAForm } from "@/components/rfas/form";
export default function NewRFAPage() {
return (
<div className="max-w-4xl mx-auto py-6">
<div className="mb-8">
<h1 className="text-3xl font-bold">New RFA</h1>
<p className="text-muted-foreground mt-1">
Create a new Request for Approval.
</p>
</div>
<RFAForm />
</div>
);
}

View File

@@ -0,0 +1,48 @@
import { RFAList } from "@/components/rfas/list";
import { Button } from "@/components/ui/button";
import Link from "next/link";
import { Plus } from "lucide-react";
import { rfaApi } from "@/lib/api/rfas";
import { Pagination } from "@/components/common/pagination";
export default async function RFAsPage({
searchParams,
}: {
searchParams: { page?: string; status?: string; search?: string };
}) {
const page = parseInt(searchParams.page || "1");
const data = await rfaApi.getAll({
page,
status: searchParams.status,
search: searchParams.search,
});
return (
<div className="space-y-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-3xl font-bold">RFAs (Request for Approval)</h1>
<p className="text-muted-foreground mt-1">
Manage approval requests and submissions
</p>
</div>
<Link href="/rfas/new">
<Button>
<Plus className="mr-2 h-4 w-4" />
New RFA
</Button>
</Link>
</div>
<RFAList data={data} />
<div className="mt-4">
<Pagination
currentPage={data.page}
totalPages={data.totalPages}
total={data.total}
/>
</div>
</div>
);
}

View File

@@ -0,0 +1,56 @@
"use client";
import { useState, useEffect } from "react";
import { useSearchParams } from "next/navigation";
import { SearchFilters } from "@/components/search/filters";
import { SearchResults } from "@/components/search/results";
import { searchApi } from "@/lib/api/search";
import { SearchResult, SearchFilters as FilterType } from "@/types/search";
export default function SearchPage() {
const searchParams = useSearchParams();
const query = searchParams.get("q") || "";
const [results, setResults] = useState<SearchResult[]>([]);
const [filters, setFilters] = useState<FilterType>({});
const [loading, setLoading] = useState(false);
useEffect(() => {
const fetchResults = async () => {
setLoading(true);
try {
const data = await searchApi.search({ query, ...filters });
setResults(data);
} catch (error) {
console.error("Search failed", error);
} finally {
setLoading(false);
}
};
fetchResults();
}, [query, filters]);
return (
<div className="space-y-6">
<div>
<h1 className="text-3xl font-bold">Search Results</h1>
<p className="text-muted-foreground mt-1">
{loading
? "Searching..."
: `Found ${results.length} results for "${query}"`
}
</p>
</div>
<div className="grid grid-cols-1 lg:grid-cols-4 gap-6">
<div className="lg:col-span-1">
<SearchFilters onFilterChange={setFilters} />
</div>
<div className="lg:col-span-3">
<SearchResults results={results} query={query} loading={loading} />
</div>
</div>
</div>
);
}