From d3826ee050f27accd89bbd510b0c94dfe255bb11 Mon Sep 17 00:00:00 2001 From: Rajat yadav Date: Sat, 20 Dec 2025 12:58:17 +0530 Subject: [PATCH] Add end field to task creation panel Implemented end date picker in AddTaskDialog for setting task completion dates. Backend now handles end field with proper validation and storage. Updated all related types, handlers and tests to support task end date functionality. --- backend/controllers/add_task.go | 3 ++- backend/models/request_body.go | 1 + backend/utils/tw/add_task.go | 5 ++++- backend/utils/tw/taskwarrior_test.go | 4 ++-- .../HomeComponents/Tasks/AddTaskDialog.tsx | 17 +++++++++++++++++ .../components/HomeComponents/Tasks/Tasks.tsx | 3 +++ .../Tasks/__tests__/AddTaskDialog.test.tsx | 2 ++ .../components/HomeComponents/Tasks/hooks.ts | 7 +++++++ frontend/src/components/utils/types.ts | 1 + 9 files changed, 39 insertions(+), 4 deletions(-) diff --git a/backend/controllers/add_task.go b/backend/controllers/add_task.go index bd372136..cf84c82b 100644 --- a/backend/controllers/add_task.go +++ b/backend/controllers/add_task.go @@ -47,6 +47,7 @@ func AddTaskHandler(w http.ResponseWriter, r *http.Request) { priority := requestBody.Priority dueDate := requestBody.DueDate start := requestBody.Start + end := requestBody.End recur := requestBody.Recur tags := requestBody.Tags annotations := requestBody.Annotations @@ -65,7 +66,7 @@ func AddTaskHandler(w http.ResponseWriter, r *http.Request) { Name: "Add Task", Execute: func() error { logStore.AddLog("INFO", fmt.Sprintf("Adding task: %s", description), uuid, "Add Task") - err := tw.AddTaskToTaskwarrior(email, encryptionSecret, uuid, description, project, priority, dueDateStr, start, recur, tags, annotations) + err := tw.AddTaskToTaskwarrior(email, encryptionSecret, uuid, description, project, priority, dueDateStr, start, end, recur, tags, annotations) if err != nil { logStore.AddLog("ERROR", fmt.Sprintf("Failed to add task: %v", err), uuid, "Add Task") return err diff --git a/backend/models/request_body.go b/backend/models/request_body.go index 8579239c..9e88880c 100644 --- a/backend/models/request_body.go +++ b/backend/models/request_body.go @@ -10,6 +10,7 @@ type AddTaskRequestBody struct { Priority string `json:"priority"` DueDate *string `json:"due"` Start string `json:"start"` + End string `json:"end"` Recur string `json:"recur"` Tags []string `json:"tags"` Annotations []Annotation `json:"annotations"` diff --git a/backend/utils/tw/add_task.go b/backend/utils/tw/add_task.go index 79fe4061..e16878b8 100644 --- a/backend/utils/tw/add_task.go +++ b/backend/utils/tw/add_task.go @@ -10,7 +10,7 @@ import ( ) // add task to the user's tw client -func AddTaskToTaskwarrior(email, encryptionSecret, uuid, description, project, priority, dueDate, start, recur string, tags []string, annotations []models.Annotation) error { +func AddTaskToTaskwarrior(email, encryptionSecret, uuid, description, project, priority, dueDate, start, end, recur string, tags []string, annotations []models.Annotation) error { if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { return fmt.Errorf("error deleting Taskwarrior data: %v", err) } @@ -43,6 +43,9 @@ func AddTaskToTaskwarrior(email, encryptionSecret, uuid, description, project, p if start != "" { cmdArgs = append(cmdArgs, "start:"+start) } + if end != "" { + cmdArgs = append(cmdArgs, "end:"+end) + } // Note: Taskwarrior requires a due date to be set before recur can be set // Only add recur if dueDate is also provided if recur != "" && dueDate != "" { diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index f08fbb18..51121543 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -42,7 +42,7 @@ func TestExportTasks(t *testing.T) { } func TestAddTaskToTaskwarrior(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "", "H", "2025-03-03", "2025-03-01", "daily", nil, []models.Annotation{{Description: "note"}}) + err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "", "H", "2025-03-03", "2025-03-01", "2025-03-05", "daily", nil, []models.Annotation{{Description: "note"}}) if err != nil { t.Errorf("AddTaskToTaskwarrior failed: %v", err) } else { @@ -60,7 +60,7 @@ func TestCompleteTaskInTaskwarrior(t *testing.T) { } func TestAddTaskWithTags(t *testing.T) { - err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "", "H", "2025-03-03", "2025-03-01", "daily", []string{"work", "important"}, []models.Annotation{{Description: "note"}}) + err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "", "H", "2025-03-03", "2025-03-01", "2025-03-05", "daily", []string{"work", "important"}, []models.Annotation{{Description: "note"}}) if err != nil { t.Errorf("AddTaskToTaskwarrior with tags failed: %v", err) } else { diff --git a/frontend/src/components/HomeComponents/Tasks/AddTaskDialog.tsx b/frontend/src/components/HomeComponents/Tasks/AddTaskDialog.tsx index 007ff6f4..8112e48b 100644 --- a/frontend/src/components/HomeComponents/Tasks/AddTaskDialog.tsx +++ b/frontend/src/components/HomeComponents/Tasks/AddTaskDialog.tsx @@ -253,6 +253,23 @@ export const AddTaskdialog = ({ /> +
+ +
+ { + setNewTask({ + ...newTask, + end: date ? format(date, 'yyyy-MM-dd') : '', + }); + }} + placeholder="Select an end date" + /> +
+