From 33c5466d770cced61ee6b117ca0dffd048783706 Mon Sep 17 00:00:00 2001 From: chop Date: Tue, 7 Oct 2025 23:07:15 +0200 Subject: [PATCH] feat: implement 'not_started' task status with validation and UI updates --- src/app/api/project-tasks/[id]/route.js | 8 ++++++++ src/components/ProjectTasksList.js | 3 ++- src/components/TaskStatusDropdownSimple.js | 4 ++++ src/lib/i18n.js | 2 ++ src/lib/init-db.js | 14 +++++++++++++- src/lib/queries/tasks.js | 4 ++-- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/app/api/project-tasks/[id]/route.js b/src/app/api/project-tasks/[id]/route.js index 3ee8cc5..628b093 100644 --- a/src/app/api/project-tasks/[id]/route.js +++ b/src/app/api/project-tasks/[id]/route.js @@ -49,6 +49,14 @@ async function updateProjectTaskStatusHandler(req, { params }) { ); } + const allowedStatuses = ['not_started', 'pending', 'in_progress', 'completed', 'cancelled']; + if (!allowedStatuses.includes(status)) { + return NextResponse.json( + { error: "Invalid status. Must be one of: " + allowedStatuses.join(', ') }, + { status: 400 } + ); + } + updateProjectTaskStatus(id, status, req.user?.id || null); return NextResponse.json({ success: true }); } catch (error) { diff --git a/src/components/ProjectTasksList.js b/src/components/ProjectTasksList.js index c99021d..2632385 100644 --- a/src/components/ProjectTasksList.js +++ b/src/components/ProjectTasksList.js @@ -135,9 +135,10 @@ export default function ProjectTasksList() { groups.completed.push(taskWithStatus); } else if (task.status === "in_progress") { groups.in_progress.push(taskWithStatus); - } else { + } else if (task.status === "pending") { groups.pending.push(taskWithStatus); } + // not_started tasks are not displayed in the UI }); // Sort pending tasks by date_added (newest first) diff --git a/src/components/TaskStatusDropdownSimple.js b/src/components/TaskStatusDropdownSimple.js index 3109052..dc75842 100644 --- a/src/components/TaskStatusDropdownSimple.js +++ b/src/components/TaskStatusDropdownSimple.js @@ -25,6 +25,10 @@ export default function TaskStatusDropdown({ }, []); const statusConfig = { + not_started: { + label: t("taskStatus.not_started"), + variant: "secondary", + }, pending: { label: t("taskStatus.pending"), variant: "warning", diff --git a/src/lib/i18n.js b/src/lib/i18n.js index 446b018..e5eff4a 100644 --- a/src/lib/i18n.js +++ b/src/lib/i18n.js @@ -135,6 +135,7 @@ const translations = { // Task statuses taskStatus: { + not_started: "Nie rozpoczęte", pending: "Oczekujące", in_progress: "W trakcie", completed: "Ukończone", @@ -699,6 +700,7 @@ const translations = { }, taskStatus: { + not_started: "Not Started", pending: "Pending", in_progress: "In Progress", completed: "Completed", diff --git a/src/lib/init-db.js b/src/lib/init-db.js index b797629..c76fcdf 100644 --- a/src/lib/init-db.js +++ b/src/lib/init-db.js @@ -71,7 +71,7 @@ export default function initializeDatabase() { task_template_id INTEGER, custom_task_name TEXT, custom_max_wait_days INTEGER DEFAULT 0, - status TEXT NOT NULL DEFAULT 'pending', + status TEXT NOT NULL DEFAULT 'not_started' CHECK(status IN ('not_started', 'pending', 'in_progress', 'completed', 'cancelled')), date_added TEXT DEFAULT CURRENT_TIMESTAMP, priority TEXT DEFAULT 'normal', FOREIGN KEY (project_id) REFERENCES projects(project_id), @@ -279,6 +279,18 @@ export default function initializeDatabase() { // Column already exists, ignore error } + // Migration: Update task status system - add 'not_started' status + try { + // First, update all existing 'pending' tasks to 'not_started' + db.exec(` + UPDATE project_tasks SET status = 'not_started' WHERE status = 'pending'; + `); + // Note: CHECK constraint will be applied when recreating the table in future migrations + // For now, we'll rely on application-level validation + } catch (e) { + // Migration already done, ignore error + } + // Create indexes for notes user tracking try { db.exec(` diff --git a/src/lib/queries/tasks.js b/src/lib/queries/tasks.js index eb7ebd4..9a0741f 100644 --- a/src/lib/queries/tasks.js +++ b/src/lib/queries/tasks.js @@ -90,7 +90,7 @@ export function createProjectTask(data) { result = stmt.run( data.project_id, data.task_template_id, - data.status || "pending", + data.status || "not_started", data.priority || "normal", data.created_by || null, data.assigned_to || null @@ -114,7 +114,7 @@ export function createProjectTask(data) { data.custom_task_name, data.custom_max_wait_days || 0, data.custom_description || "", - data.status || "pending", + data.status || "not_started", data.priority || "normal", data.created_by || null, data.assigned_to || null