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

View File

@@ -126,7 +126,6 @@ export default function initializeDatabase() {
} catch (e) { } catch (e) {
// Column already exists, ignore error // Column already exists, ignore error
} }
// Migration: Copy data from geo_info to coordinates and drop geo_info // Migration: Copy data from geo_info to coordinates and drop geo_info
try { try {
db.exec(` db.exec(`
@@ -138,4 +137,13 @@ export default function initializeDatabase() {
} catch (e) { } catch (e) {
// Column migration already done or geo_info doesn't exist, ignore error // Column migration already done or geo_info doesn't exist, ignore error
} }
// Migration: Add date_started column to project_tasks table
try {
db.exec(`
ALTER TABLE project_tasks ADD COLUMN date_started TEXT;
`);
} catch (e) {
// Column already exists, ignore error
}
} }

View File

@@ -90,12 +90,35 @@ export function createProjectTask(data) {
// Update project task status // Update project task status
export function updateProjectTaskStatus(taskId, status) { export function updateProjectTaskStatus(taskId, status) {
const stmt = db.prepare(` // First get the current status to check if we're transitioning from pending to in_progress
UPDATE project_tasks const getCurrentStatus = db.prepare(
SET status = ? "SELECT status FROM project_tasks WHERE id = ?"
WHERE id = ? );
`); const currentTask = getCurrentStatus.get(taskId);
return stmt.run(status, taskId);
let stmt;
if (
currentTask &&
currentTask.status === "pending" &&
status === "in_progress"
) {
// Starting a task - set date_started
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?, date_started = CURRENT_TIMESTAMP
WHERE id = ?
`);
return stmt.run(status, taskId);
} else {
// Just updating status without changing date_started
stmt = db.prepare(`
UPDATE project_tasks
SET status = ?
WHERE id = ?
`);
return stmt.run(status, taskId);
}
} }
// Delete a project task // Delete a project task