-
+
{notes.length === 0 ? (
diff --git a/src/app/tasks/templates/[id]/edit/page.js b/src/app/tasks/templates/[id]/edit/page.js
index 3fa63e6..d357906 100644
--- a/src/app/tasks/templates/[id]/edit/page.js
+++ b/src/app/tasks/templates/[id]/edit/page.js
@@ -6,10 +6,11 @@ import Button from "@/components/ui/Button";
import TaskTemplateForm from "@/components/TaskTemplateForm";
export default async function EditTaskTemplatePage({ params }) {
+ const { id } = await params;
// Fetch the task template
const template = db
.prepare("SELECT * FROM tasks WHERE task_id = ? AND is_standard = 1")
- .get(params.id);
+ .get(id);
if (!template) {
notFound();
diff --git a/src/components/ProjectTaskForm.js b/src/components/ProjectTaskForm.js
index 01fc409..434ea2a 100644
--- a/src/components/ProjectTaskForm.js
+++ b/src/components/ProjectTaskForm.js
@@ -10,6 +10,7 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) {
const [selectedTemplate, setSelectedTemplate] = useState("");
const [customTaskName, setCustomTaskName] = useState("");
const [customMaxWaitDays, setCustomMaxWaitDays] = useState("");
+ const [customDescription, setCustomDescription] = useState("");
const [priority, setPriority] = useState("normal");
const [isSubmitting, setIsSubmitting] = useState(false);
@@ -40,6 +41,7 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) {
} else {
requestData.custom_task_name = customTaskName.trim();
requestData.custom_max_wait_days = parseInt(customMaxWaitDays) || 0;
+ requestData.custom_description = customDescription.trim();
}
const res = await fetch("/api/project-tasks", {
@@ -47,12 +49,12 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) {
headers: { "Content-Type": "application/json" },
body: JSON.stringify(requestData),
});
-
if (res.ok) {
// Reset form
setSelectedTemplate("");
setCustomTaskName("");
setCustomMaxWaitDays("");
+ setCustomDescription("");
setPriority("normal");
if (onTaskAdded) onTaskAdded();
} else {
@@ -141,6 +143,18 @@ export default function ProjectTaskForm({ projectId, onTaskAdded }) {
min="0"
/>
+
+
+
)}
diff --git a/src/components/ProjectTasksSection.js b/src/components/ProjectTasksSection.js
index f447101..cbd3a85 100644
--- a/src/components/ProjectTasksSection.js
+++ b/src/components/ProjectTasksSection.js
@@ -9,12 +9,34 @@ import Badge from "./ui/Badge";
export default function ProjectTasksSection({ projectId }) {
const [projectTasks, setProjectTasks] = useState([]);
const [loading, setLoading] = useState(true);
+ const [taskNotes, setTaskNotes] = useState({});
+ const [newNote, setNewNote] = useState({});
+ const [loadingNotes, setLoadingNotes] = useState({});
useEffect(() => {
const fetchProjectTasks = async () => {
try {
const res = await fetch(`/api/project-tasks?project_id=${projectId}`);
const tasks = await res.json();
setProjectTasks(tasks);
+
+ // Fetch notes for each task
+ const notesPromises = tasks.map(async (task) => {
+ try {
+ const notesRes = await fetch(`/api/task-notes?task_id=${task.id}`);
+ const notes = await notesRes.json();
+ return { taskId: task.id, notes };
+ } catch (error) {
+ console.error(`Failed to fetch notes for task ${task.id}:`, error);
+ return { taskId: task.id, notes: [] };
+ }
+ });
+
+ const notesResults = await Promise.all(notesPromises);
+ const notesMap = {};
+ notesResults.forEach(({ taskId, notes }) => {
+ notesMap[taskId] = notes;
+ });
+ setTaskNotes(notesMap);
} catch (error) {
console.error("Failed to fetch project tasks:", error);
} finally {
@@ -24,12 +46,30 @@ export default function ProjectTasksSection({ projectId }) {
fetchProjectTasks();
}, [projectId]);
-
const refetchTasks = async () => {
try {
const res = await fetch(`/api/project-tasks?project_id=${projectId}`);
const tasks = await res.json();
setProjectTasks(tasks);
+
+ // Refresh notes for all tasks
+ const notesPromises = tasks.map(async (task) => {
+ try {
+ const notesRes = await fetch(`/api/task-notes?task_id=${task.id}`);
+ const notes = await notesRes.json();
+ return { taskId: task.id, notes };
+ } catch (error) {
+ console.error(`Failed to fetch notes for task ${task.id}:`, error);
+ return { taskId: task.id, notes: [] };
+ }
+ });
+
+ const notesResults = await Promise.all(notesPromises);
+ const notesMap = {};
+ notesResults.forEach(({ taskId, notes }) => {
+ notesMap[taskId] = notes;
+ });
+ setTaskNotes(notesMap);
} catch (error) {
console.error("Failed to fetch project tasks:", error);
}
@@ -55,7 +95,6 @@ export default function ProjectTasksSection({ projectId }) {
alert("Error updating task status");
}
};
-
const handleDeleteTask = async (taskId) => {
if (!confirm("Are you sure you want to delete this task?")) return;
try {
@@ -72,6 +111,59 @@ export default function ProjectTasksSection({ projectId }) {
alert("Error deleting task");
}
};
+
+ const handleAddNote = async (taskId) => {
+ const noteContent = newNote[taskId]?.trim();
+ if (!noteContent) return;
+
+ setLoadingNotes((prev) => ({ ...prev, [taskId]: true }));
+
+ try {
+ const res = await fetch("/api/task-notes", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ task_id: taskId,
+ note: noteContent,
+ }),
+ });
+
+ if (res.ok) {
+ // Refresh notes for this task
+ const notesRes = await fetch(`/api/task-notes?task_id=${taskId}`);
+ const notes = await notesRes.json();
+ setTaskNotes((prev) => ({ ...prev, [taskId]: notes }));
+ setNewNote((prev) => ({ ...prev, [taskId]: "" }));
+ } else {
+ alert("Failed to add note");
+ }
+ } catch (error) {
+ alert("Error adding note");
+ } finally {
+ setLoadingNotes((prev) => ({ ...prev, [taskId]: false }));
+ }
+ };
+
+ const handleDeleteNote = async (noteId, taskId) => {
+ if (!confirm("Are you sure you want to delete this note?")) return;
+
+ try {
+ const res = await fetch(`/api/task-notes?note_id=${noteId}`, {
+ method: "DELETE",
+ });
+
+ if (res.ok) {
+ // Refresh notes for this task
+ const notesRes = await fetch(`/api/task-notes?task_id=${taskId}`);
+ const notes = await notesRes.json();
+ setTaskNotes((prev) => ({ ...prev, [taskId]: notes }));
+ } else {
+ alert("Failed to delete note");
+ }
+ } catch (error) {
+ alert("Error deleting note");
+ }
+ };
const getPriorityVariant = (priority) => {
switch (priority) {
case "urgent":
@@ -177,8 +269,15 @@ export default function ProjectTasksSection({ projectId }) {
>
{task.priority}
-
-
+ {" "}
+ {/* Task Description */}
+ {task.description && (
+
+
+ {task.description}
+
+
+ )}
Max wait days:{" "}
@@ -193,8 +292,7 @@ export default function ProjectTasksSection({ projectId }) {
{new Date(task.date_added).toLocaleDateString()}
-
-
+
Status:
@@ -217,6 +315,80 @@ export default function ProjectTasksSection({ projectId }) {
{task.status.replace("_", " ")}
+ {/* Notes Section */}
+
+
+ Notes ({taskNotes[task.id]?.length || 0})
+
+
+ {/* Existing Notes */}
+ {taskNotes[task.id] &&
+ taskNotes[task.id].length > 0 && (
+
+ {taskNotes[task.id].map((note) => (
+
+
+
+ {note.note}
+
+
+ {new Date(
+ note.note_date
+ ).toLocaleDateString()}{" "}
+ at{" "}
+ {new Date(
+ note.note_date
+ ).toLocaleTimeString()}
+
+
+
+
+ ))}
+
+ )}
+
+ {/* Add New Note */}
+
+
+ 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);
+ }
+ }}
+ />
+
+
+
diff --git a/src/lib/init-db.js b/src/lib/init-db.js
index ab30ca6..ef08fdd 100644
--- a/src/lib/init-db.js
+++ b/src/lib/init-db.js
@@ -81,7 +81,6 @@ export default function initializeDatabase() {
} catch (e) {
// Column already exists, ignore error
}
-
// Migration: Add description column to tasks table
try {
db.exec(`
@@ -90,4 +89,13 @@ export default function initializeDatabase() {
} catch (e) {
// Column already exists, ignore error
}
+
+ // Migration: Add description column to project_tasks table
+ try {
+ db.exec(`
+ ALTER TABLE project_tasks ADD COLUMN custom_description TEXT;
+ `);
+ } catch (e) {
+ // Column already exists, ignore error
+ }
}
diff --git a/src/lib/queries/notes.js b/src/lib/queries/notes.js
index 0bc5af1..b1befbe 100644
--- a/src/lib/queries/notes.js
+++ b/src/lib/queries/notes.js
@@ -12,3 +12,20 @@ export function addNoteToProject(project_id, note) {
note
);
}
+
+export function getNotesByTaskId(task_id) {
+ return db
+ .prepare(`SELECT * FROM notes WHERE task_id = ? ORDER BY note_date DESC`)
+ .all(task_id);
+}
+
+export function addNoteToTask(task_id, note) {
+ db.prepare(`INSERT INTO notes (task_id, note) VALUES (?, ?)`).run(
+ task_id,
+ note
+ );
+}
+
+export function deleteNote(note_id) {
+ db.prepare(`DELETE FROM notes WHERE note_id = ?`).run(note_id);
+}
diff --git a/src/lib/queries/tasks.js b/src/lib/queries/tasks.js
index 3e11c81..6640f6a 100644
--- a/src/lib/queries/tasks.js
+++ b/src/lib/queries/tasks.js
@@ -16,6 +16,7 @@ export function getAllProjectTasks() {
pt.*,
COALESCE(pt.custom_task_name, t.name) as task_name,
COALESCE(pt.custom_max_wait_days, t.max_wait_days) as max_wait_days,
+ COALESCE(pt.custom_description, t.description) as description,
CASE
WHEN pt.task_template_id IS NOT NULL THEN 'template'
ELSE 'custom'
@@ -42,6 +43,7 @@ export function getProjectTasks(projectId) {
pt.*,
COALESCE(pt.custom_task_name, t.name) as task_name,
COALESCE(pt.custom_max_wait_days, t.max_wait_days) as max_wait_days,
+ COALESCE(pt.custom_description, t.description) as description,
CASE
WHEN pt.task_template_id IS NOT NULL THEN 'template'
ELSE 'custom'
@@ -72,13 +74,14 @@ export function createProjectTask(data) {
} else {
// Creating custom task
const stmt = db.prepare(`
- INSERT INTO project_tasks (project_id, custom_task_name, custom_max_wait_days, status, priority)
- VALUES (?, ?, ?, ?, ?)
+ INSERT INTO project_tasks (project_id, custom_task_name, custom_max_wait_days, custom_description, status, priority)
+ VALUES (?, ?, ?, ?, ?, ?)
`);
return stmt.run(
data.project_id,
data.custom_task_name,
data.custom_max_wait_days || 0,
+ data.custom_description || "",
data.status || "pending",
data.priority || "normal"
);