feat: Enhance project task management with expandable notes and descriptions, and add date_started column for task tracking

This commit is contained in:
Chop
2025-06-19 22:01:39 +02:00
parent 78b2474a9f
commit d40af1ff31
3 changed files with 273 additions and 158 deletions

View File

@@ -1,6 +1,6 @@
"use client";
import { useState, useEffect } from "react";
import React, { useState, useEffect } from "react";
import ProjectTaskForm from "./ProjectTaskForm";
import { Card, CardHeader, CardContent } from "./ui/Card";
import Button from "./ui/Button";
@@ -13,6 +13,8 @@ export default function ProjectTasksSection({ projectId }) {
const [newNote, setNewNote] = useState({});
const [loadingNotes, setLoadingNotes] = useState({});
const [showAddTaskModal, setShowAddTaskModal] = useState(false);
const [expandedDescriptions, setExpandedDescriptions] = useState({});
const [expandedNotes, setExpandedNotes] = useState({});
useEffect(() => {
const fetchProjectTasks = async () => {
try {
@@ -241,7 +243,6 @@ export default function ProjectTasksSection({ projectId }) {
return "default";
}
};
const getStatusVariant = (status) => {
switch (status) {
case "completed":
@@ -256,6 +257,20 @@ export default function ProjectTasksSection({ projectId }) {
return "default";
}
};
const toggleDescription = (taskId) => {
setExpandedDescriptions((prev) => ({
...prev,
[taskId]: !prev[taskId],
}));
};
const toggleNotes = (taskId) => {
setExpandedNotes((prev) => ({
...prev,
[taskId]: !prev[taskId],
}));
};
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
@@ -369,159 +384,228 @@ export default function ProjectTasksSection({ projectId }) {
</p>
</div>
) : (
<div className="divide-y divide-gray-200">
{projectTasks.map((task) => (
<div
key={task.id}
className="p-6 hover:bg-gray-50 transition-colors"
>
<div className="flex items-start justify-between">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-3 mb-3">
<h4 className="text-base font-medium text-gray-900 truncate">
{task.task_name}
</h4>
<Badge
variant={getPriorityVariant(task.priority)}
size="sm"
>
{task.priority}
</Badge>
</div>{" "}
{/* Task Description */}
{task.description && (
<div className="mb-4">
<p className="text-sm text-gray-700 bg-gray-50 p-3 rounded-md">
{task.description}
</p>
</div>
)}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3 text-sm text-gray-600 mb-4">
<div>
<span className="font-medium">Max wait days:</span>{" "}
{task.max_wait_days}
</div>
<div>
<span className="font-medium">Type:</span>{" "}
{task.task_type || "template"}
</div>
<div>
<span className="font-medium">Added:</span>{" "}
{new Date(task.date_added).toLocaleDateString()}
</div>
</div>
<div className="flex items-center gap-3 mb-4">
<span className="text-sm font-medium text-gray-700">
Status:
</span>
<select
value={task.status}
onChange={(e) =>
handleStatusChange(task.id, e.target.value)
}
className="px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors"
>
<option value="pending">Pending</option>
<option value="in_progress">In Progress</option>
<option value="completed">Completed</option>
<option value="cancelled">Cancelled</option>
</select>
<Badge
variant={getStatusVariant(task.status)}
size="sm"
>
{task.status.replace("_", " ")}
</Badge>
</div>
{/* Notes Section */}
<div className="border-t pt-4">
<h5 className="text-sm font-medium text-gray-900 mb-3">
Notes ({taskNotes[task.id]?.length || 0})
</h5>
{/* Existing Notes */}
{taskNotes[task.id] &&
taskNotes[task.id].length > 0 && (
<div className="space-y-2 mb-3">
{taskNotes[task.id].map((note) => (
<div
key={note.note_id}
className="bg-blue-50 p-3 rounded-md flex justify-between items-start"
<div className="overflow-x-auto">
<table className="w-full">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Task
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Priority
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Max Wait
</th>{" "}
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Date Started
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Status
</th>
<th className="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Actions
</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{projectTasks.map((task) => (
<React.Fragment key={task.id}>
{/* Main task row */}
<tr className="hover:bg-gray-50 transition-colors">
<td className="px-4 py-4">
<div className="flex items-center gap-2">
<h4 className="text-sm font-medium text-gray-900">
{task.task_name}
</h4>
{task.description && (
<button
onClick={() => toggleDescription(task.id)}
className="text-gray-400 hover:text-gray-600 transition-colors"
title="Toggle description"
>
<svg
className={`w-4 h-4 transform transition-transform ${
expandedDescriptions[task.id]
? "rotate-180"
: ""
}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<div className="flex-1">
<p className="text-sm text-gray-800">
{note.note}
</p>
<p className="text-xs text-gray-500 mt-1">
{new Date(
note.note_date
).toLocaleDateString()}{" "}
at{" "}
{new Date(
note.note_date
).toLocaleTimeString()}
</p>
</div>
<button
onClick={() =>
handleDeleteNote(note.note_id, task.id)
}
className="ml-2 text-red-500 hover:text-red-700 text-xs font-bold"
title="Delete note"
>
×
</button>
</div>
))}
</div>
)}
{/* Add New Note */}
<div className="flex gap-2">
<input
type="text"
placeholder="Add a note..."
value={newNote[task.id] || ""}
onChange={(e) =>
setNewNote((prev) => ({
...prev,
[task.id]: e.target.value,
}))
}
className="flex-1 px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
onKeyPress={(e) => {
if (e.key === "Enter") {
handleAddNote(task.id);
}
}}
/>
<Button
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 9l-7 7-7-7"
/>
</svg>
</button>
)}
</div>
</td>
<td className="px-4 py-4">
<Badge
variant={getPriorityVariant(task.priority)}
size="sm"
variant="primary"
onClick={() => handleAddNote(task.id)}
disabled={
loadingNotes[task.id] || !newNote[task.id]?.trim()
}
>
{loadingNotes[task.id] ? "Adding..." : "Add"}
</Button>
</div>
</div>
</div>
{task.priority}
</Badge>
</td>
<td className="px-4 py-4 text-sm text-gray-600">
{task.max_wait_days} days
</td>{" "}
<td className="px-4 py-4 text-sm text-gray-600">
{task.date_started
? new Date(task.date_started).toLocaleDateString()
: "Not started"}
</td>
<td className="px-4 py-4">
<div className="flex items-center gap-2">
<select
value={task.status}
onChange={(e) =>
handleStatusChange(task.id, e.target.value)
}
className="text-xs px-2 py-1 border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
>
<option value="pending">Pending</option>
<option value="in_progress">In Progress</option>
<option value="completed">Completed</option>
<option value="cancelled">Cancelled</option>
</select>
<Badge
variant={getStatusVariant(task.status)}
size="sm"
>
{task.status.replace("_", " ")}
</Badge>
</div>
</td>
<td className="px-4 py-4">
<div className="flex items-center gap-2">
<button
onClick={() => toggleNotes(task.id)}
className="text-xs text-blue-600 hover:text-blue-800 font-medium"
title={`${taskNotes[task.id]?.length || 0} notes`}
>
Notes ({taskNotes[task.id]?.length || 0})
</button>
<Button
variant="danger"
size="sm"
onClick={() => handleDeleteTask(task.id)}
className="text-xs"
>
Delete
</Button>
</div>
</td>
</tr>
<div className="ml-4 flex-shrink-0">
<Button
variant="danger"
size="sm"
onClick={() => handleDeleteTask(task.id)}
className="text-xs"
>
Delete
</Button>
</div>
</div>
</div>
))}
{/* Description row (expandable) */}
{task.description && expandedDescriptions[task.id] && (
<tr className="bg-blue-50">
<td colSpan="6" className="px-4 py-3">
<div className="text-sm text-gray-700">
<span className="font-medium text-gray-900">
Description:
</span>
<p className="mt-1">{task.description}</p>
</div>
</td>
</tr>
)}
{/* Notes row (expandable) */}
{expandedNotes[task.id] && (
<tr className="bg-gray-50">
<td colSpan="6" className="px-4 py-4">
<div className="space-y-3">
<h5 className="text-sm font-medium text-gray-900">
Notes ({taskNotes[task.id]?.length || 0})
</h5>
{/* Existing Notes */}
{taskNotes[task.id] &&
taskNotes[task.id].length > 0 && (
<div className="space-y-2">
{taskNotes[task.id].map((note) => (
<div
key={note.note_id}
className="bg-white p-3 rounded border flex justify-between items-start"
>
<div className="flex-1">
<p className="text-sm text-gray-800">
{note.note}
</p>
<p className="text-xs text-gray-500 mt-1">
{new Date(
note.note_date
).toLocaleDateString()}{" "}
at{" "}
{new Date(
note.note_date
).toLocaleTimeString()}
</p>
</div>
<button
onClick={() =>
handleDeleteNote(
note.note_id,
task.id
)
}
className="ml-2 text-red-500 hover:text-red-700 text-xs font-bold"
title="Delete note"
>
×
</button>
</div>
))}
</div>
)}
{/* Add New Note */}
<div className="flex gap-2">
<input
type="text"
placeholder="Add a note..."
value={newNote[task.id] || ""}
onChange={(e) =>
setNewNote((prev) => ({
...prev,
[task.id]: e.target.value,
}))
}
className="flex-1 px-3 py-1.5 text-sm border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
onKeyPress={(e) => {
if (e.key === "Enter") {
handleAddNote(task.id);
}
}}
/>
<Button
size="sm"
variant="primary"
onClick={() => handleAddNote(task.id)}
disabled={
loadingNotes[task.id] ||
!newNote[task.id]?.trim()
}
>
{loadingNotes[task.id] ? "Adding..." : "Add"}
</Button>
</div>
</div>
</td>
</tr>
)}
</React.Fragment>
))}
</tbody>
</table>
</div>
)}
</CardContent>