|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import { useParams, Link } from "react-router"; |
| 3 | +import { projectService } from "../services/projectService"; |
| 4 | +import { Button } from "@/components/ui/button"; |
| 5 | +import { ArrowLeft, LayoutDashboard, Settings } from "lucide-react"; |
| 6 | + |
| 7 | + |
| 8 | +export default function ProjectDashboard() { |
| 9 | + const { id } = useParams<{ id: string }>(); |
| 10 | + const [project, setProject] = useState<{ id: number; name: string; desc: string; created_at: string } | null>(null); |
| 11 | + const [isLoading, setIsLoading] = useState(true); |
| 12 | + const [error, setError] = useState<string | null>(null); |
| 13 | + |
| 14 | + useEffect(() => { |
| 15 | + const fetchProject = async () => { |
| 16 | + if (!id) return; |
| 17 | + setIsLoading(true); |
| 18 | + try { |
| 19 | + const data = await projectService.getProjectById(id); |
| 20 | + setProject(data); |
| 21 | + } catch (err: any) { // eslint-disable-line @typescript-eslint/no-explicit-any |
| 22 | + setError("Failed to load project details."); |
| 23 | + console.error(err); |
| 24 | + } finally { |
| 25 | + setIsLoading(false); |
| 26 | + } |
| 27 | + }; |
| 28 | + |
| 29 | + fetchProject(); |
| 30 | + }, [id]); |
| 31 | + |
| 32 | + if (isLoading) { |
| 33 | + return ( |
| 34 | + <div className="flex items-center justify-center h-screen bg-slate-50"> |
| 35 | + <div className="animate-spin rounded-full h-12 w-12 border-b-2 border-sky-600"></div> |
| 36 | + </div> |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + if (error || !project) { |
| 41 | + return ( |
| 42 | + <div className="flex flex-col items-center justify-center h-screen bg-slate-50"> |
| 43 | + <h2 className="text-2xl font-bold text-sky-900 mb-4">{error || "Project not found"}</h2> |
| 44 | + <Link to="/"> |
| 45 | + <Button variant="outline"> |
| 46 | + <ArrowLeft className="mr-2 h-4 w-4" /> |
| 47 | + Back to Home |
| 48 | + </Button> |
| 49 | + </Link> |
| 50 | + </div> |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + return ( |
| 55 | + <div className="flex flex-col h-screen bg-slate-50 relative overflow-hidden"> |
| 56 | + {/* Subtle Background */} |
| 57 | + <div className="absolute inset-0 bg-[linear-gradient(to_right,#e0f2fe_1px,transparent_1px),linear-gradient(to_bottom,#e0f2fe_1px,transparent_1px)] bg-size-[24px_24px] mask-[radial-gradient(ellipse_60%_50%_at_50%_0%,#000_70%,transparent_100%)] opacity-90 pointer-events-none"></div> |
| 58 | + |
| 59 | + {/* Sidebar (Mockup for now, or just a simple header) */} |
| 60 | + {/* Let's stick to a clean layout similar to Home but focused on the project */} |
| 61 | + |
| 62 | + <header className="flex items-center justify-between px-6 py-4 bg-white/50 backdrop-blur-md border-b border-sky-100 z-20"> |
| 63 | + <div className="flex items-center space-x-4"> |
| 64 | + <Link to="/"> |
| 65 | + <Button variant="ghost" size="icon" className="text-sky-700 hover:text-sky-900 hover:bg-sky-100"> |
| 66 | + <ArrowLeft className="h-5 w-5" /> |
| 67 | + </Button> |
| 68 | + </Link> |
| 69 | + <div> |
| 70 | + <h1 className="text-xl font-bold text-sky-900 tracking-tight">{project.name}</h1> |
| 71 | + <p className="text-xs text-sky-500 font-medium">Project Dashboard</p> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + <div className="flex items-center space-x-2"> |
| 75 | + <Button variant="ghost" size="icon" className="text-sky-700 hover:text-sky-900 hover:bg-sky-100"> |
| 76 | + <LayoutDashboard className="h-5 w-5" /> |
| 77 | + </Button> |
| 78 | + <Button variant="ghost" size="icon" className="text-sky-700 hover:text-sky-900 hover:bg-sky-100"> |
| 79 | + <Settings className="h-5 w-5" /> |
| 80 | + </Button> |
| 81 | + </div> |
| 82 | + </header> |
| 83 | + |
| 84 | + <main className="flex-1 p-8 z-10 overflow-y-auto"> |
| 85 | + <div className="max-w-5xl mx-auto"> |
| 86 | + <div className="bg-white/60 backdrop-blur-sm p-8 rounded-2xl shadow-sm border border-sky-100 mb-8"> |
| 87 | + <h2 className="text-2xl font-semibold text-sky-900 mb-4">Welcome to {project.name}</h2> |
| 88 | + <p className="text-sky-700/80 leading-relaxed mb-6"> |
| 89 | + {project.desc || "No description provided for this project."} |
| 90 | + </p> |
| 91 | + <div className="flex items-center space-x-4 text-sm text-sky-500"> |
| 92 | + <span>Created on {new Date(project.created_at).toLocaleDateString()}</span> |
| 93 | + {/* Potential place for more stats like '3 Members', '5 Tasks', etc. */} |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + |
| 97 | + {/* Placeholder for future dashboard widgets */} |
| 98 | + <div className="grid grid-cols-1 md:grid-cols-3 gap-6"> |
| 99 | + <div className="bg-white/40 backdrop-blur-sm p-6 rounded-xl border border-sky-100 h-48 flex items-center justify-center text-sky-300"> |
| 100 | + Widget Placeholder |
| 101 | + </div> |
| 102 | + <div className="bg-white/40 backdrop-blur-sm p-6 rounded-xl border border-sky-100 h-48 flex items-center justify-center text-sky-300"> |
| 103 | + Widget Placeholder |
| 104 | + </div> |
| 105 | + <div className="bg-white/40 backdrop-blur-sm p-6 rounded-xl border border-sky-100 h-48 flex items-center justify-center text-sky-300"> |
| 106 | + Widget Placeholder |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </main> |
| 111 | + </div> |
| 112 | + ); |
| 113 | +} |
0 commit comments