feat: Implement project search functionality and task management features

- Added search functionality to the Project List page, allowing users to filter projects by name, WP, plot, or investment number.
- Created a new Project Tasks page to manage tasks across all projects, including filtering by status and priority.
- Implemented task status updates and deletion functionality.
- Added a new Task Template Edit page for modifying existing task templates.
- Enhanced Task Template Form to include a description field and loading state during submission.
- Updated UI components for better user experience, including badges for task status and priority.
- Introduced new database queries for managing contracts and projects, including fetching tasks related to projects.
- Added migrations to the database for new columns and improved data handling.
This commit is contained in:
Chop
2025-06-02 23:21:04 +02:00
parent b06aad72b8
commit 35569846bc
24 changed files with 2019 additions and 169 deletions

View File

@@ -5,16 +5,39 @@ import Link from "next/link";
import { Card, CardHeader, CardContent } from "@/components/ui/Card";
import Button from "@/components/ui/Button";
import Badge from "@/components/ui/Badge";
import { Input } from "@/components/ui/Input";
export default function ProjectListPage() {
const [projects, setProjects] = useState([]);
const [searchTerm, setSearchTerm] = useState("");
const [filteredProjects, setFilteredProjects] = useState([]);
useEffect(() => {
fetch("/api/projects")
.then((res) => res.json())
.then(setProjects);
.then((data) => {
setProjects(data);
setFilteredProjects(data);
});
}, []);
// Filter projects based on search term
useEffect(() => {
if (!searchTerm.trim()) {
setFilteredProjects(projects);
} else {
const filtered = projects.filter((project) => {
const searchLower = searchTerm.toLowerCase();
return (
project.project_name?.toLowerCase().includes(searchLower) ||
project.wp?.toLowerCase().includes(searchLower) ||
project.plot?.toLowerCase().includes(searchLower) ||
project.investment_number?.toLowerCase().includes(searchLower)
);
});
setFilteredProjects(filtered);
}
}, [searchTerm, projects]);
async function handleDelete(id) {
const confirmed = confirm("Are you sure you want to delete this project?");
if (!confirmed) return;
@@ -22,11 +45,14 @@ export default function ProjectListPage() {
const res = await fetch(`/api/projects/${id}`, {
method: "DELETE",
});
if (res.ok) {
setProjects((prev) => prev.filter((p) => p.project_id !== id));
}
}
const handleSearchChange = (e) => {
setSearchTerm(e.target.value);
};
return (
<div className="min-h-screen bg-gray-50">
<div className="max-w-6xl mx-auto p-6">
@@ -52,10 +78,115 @@ export default function ProjectListPage() {
</svg>
Add Project
</Button>
</Link>
</Link>{" "}
</div>{" "}
{/* Search Bar */}
<div className="mb-8">
<div className="bg-white rounded-lg shadow-sm border border-gray-200 p-4">
<div className="flex items-center space-x-4">
<div className="flex-1 relative">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<svg
className="h-5 w-5 text-gray-400"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
</div>
<Input
type="text"
placeholder="Search by project name, WP, plot, or investment number..."
value={searchTerm}
onChange={handleSearchChange}
className="pl-10 pr-10 w-full border-gray-300 focus:border-blue-500 focus:ring-blue-500"
/>
{searchTerm && (
<button
onClick={() => setSearchTerm("")}
className="absolute inset-y-0 right-0 pr-3 flex items-center"
>
<svg
className="h-5 w-5 text-gray-400 hover:text-gray-600 transition-colors"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
)}
</div>
</div>
{searchTerm && (
<div className="mt-3 pt-3 border-t border-gray-100">
<div className="flex items-center justify-between">
<p className="text-sm text-gray-600">
Found{" "}
<span className="font-medium text-gray-900">
{filteredProjects.length}
</span>{" "}
project
{filteredProjects.length !== 1 ? "s" : ""} matching
<span className="font-medium text-blue-600">
{" "}
&quot;{searchTerm}&quot;
</span>
</p>
{filteredProjects.length === 0 && (
<Button
variant="outline"
size="sm"
onClick={() => setSearchTerm("")}
>
Clear Search
</Button>
)}
</div>
</div>
)}
</div>
</div>
{projects.length === 0 ? (
{filteredProjects.length === 0 && searchTerm ? (
<Card>
<CardContent className="text-center py-12">
<div className="text-gray-400 mb-4">
<svg
className="w-16 h-16 mx-auto"
fill="currentColor"
viewBox="0 0 20 20"
>
<path
fillRule="evenodd"
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
clipRule="evenodd"
/>
</svg>
</div>
<h3 className="text-lg font-medium text-gray-900 mb-2">
No projects found
</h3>
<p className="text-gray-500 mb-6">
No projects match your search criteria. Try adjusting your
search terms.
</p>
<Button variant="outline" onClick={() => setSearchTerm("")}>
Clear Search
</Button>
</CardContent>
</Card>
) : projects.length === 0 ? (
<Card>
<CardContent className="text-center py-12">
<div className="text-gray-400 mb-4">
@@ -83,68 +214,63 @@ export default function ProjectListPage() {
</CardContent>
</Card>
) : (
<div className="space-y-4">
{projects.map((project) => (
<Card
<div className="bg-white rounded-lg shadow overflow-hidden">
{/* Header Row */}
<div className="grid grid-cols-12 gap-4 p-4 bg-gray-100 border-b font-semibold text-sm text-gray-700">
{" "}
<div className="col-span-1">Number</div>
<div className="col-span-3">Project Name</div>
<div className="col-span-2">WP</div>
<div className="col-span-1">City</div>
<div className="col-span-2">Address</div>
<div className="col-span-1">Plot</div>{" "}
<div className="col-span-1">Finish Date</div>
<div className="col-span-1">Actions</div>
</div>{" "}
{/* Data Rows */}
{filteredProjects.map((project, index) => (
<div
key={project.project_id}
className="hover:shadow-md transition-shadow"
className={`grid grid-cols-12 gap-4 p-4 border-b hover:bg-gray-50 transition-colors items-center ${
index % 2 === 0 ? "bg-white" : "bg-gray-25"
}`}
>
<CardContent className="p-6">
<div className="flex items-start justify-between">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-3 mb-2">
<Link
href={`/projects/${project.project_id}`}
className="text-xl font-semibold text-blue-600 hover:text-blue-800 transition-colors truncate"
>
{project.project_name}
</Link>
<Badge variant="primary" size="sm">
{project.project_number}
</Badge>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4 text-sm text-gray-600 mb-4">
<div>
<span className="font-medium">Location:</span>{" "}
{project.city}
</div>
<div>
<span className="font-medium">Finish Date:</span>{" "}
{project.finish_date}
</div>
<div>
<span className="font-medium">Contract:</span>{" "}
{project.contract_number}
</div>
</div>
<div className="flex items-center gap-4">
<Link href={`/projects/${project.project_id}`}>
<Button variant="outline" size="sm">
View Details
</Button>
</Link>
<Link href={`/projects/${project.project_id}/edit`}>
<Button variant="secondary" size="sm">
Edit
</Button>
</Link>
</div>
</div>
<div className="ml-4 flex-shrink-0">
<Button
variant="danger"
size="sm"
onClick={() => handleDelete(project.project_id)}
>
Delete
</Button>
</div>
</div>
</CardContent>
</Card>
<div className="col-span-1">
<Badge variant="primary" size="sm">
{project.project_number}
</Badge>
</div>{" "}
<div className="col-span-3">
<Link
href={`/projects/${project.project_id}`}
className="font-medium text-blue-600 hover:text-blue-800 transition-colors truncate block"
>
{project.project_name}
</Link>
</div>
<div className="col-span-2 text-sm text-gray-600 truncate">
{project.wp || "N/A"}
</div>
<div className="col-span-1 text-sm text-gray-600 truncate">
{project.city || "N/A"}
</div>
<div className="col-span-2 text-sm text-gray-600 truncate">
{project.address || "N/A"}
</div>
<div className="col-span-1 text-sm text-gray-600 truncate">
{project.plot || "N/A"}
</div>{" "}
<div className="col-span-1 text-sm text-gray-600 truncate">
{project.finish_date || "N/A"}
</div>
<div className="col-span-1">
<Link href={`/projects/${project.project_id}`}>
<Button variant="outline" size="sm">
View
</Button>
</Link>
</div>
</div>
))}
</div>
)}