diff --git a/backend/controllers/edit_task.go b/backend/controllers/edit_task.go index 5ca9f18..3c55c50 100644 --- a/backend/controllers/edit_task.go +++ b/backend/controllers/edit_task.go @@ -48,6 +48,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) { project := requestBody.Project start := requestBody.Start entry := requestBody.Entry + wait := requestBody.Wait if taskID == "" { http.Error(w, "taskID is required", http.StatusBadRequest) @@ -59,7 +60,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) { Name: "Edit Task", Execute: func() error { logStore.AddLog("INFO", fmt.Sprintf("Editing task ID: %s", taskID), uuid, "Edit Task") - err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry) + err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry, wait) if err != nil { logStore.AddLog("ERROR", fmt.Sprintf("Failed to edit task ID %s: %v", taskID, err), uuid, "Edit Task") return err diff --git a/backend/models/request_body.go b/backend/models/request_body.go index 961fd2c..87edaf0 100644 --- a/backend/models/request_body.go +++ b/backend/models/request_body.go @@ -33,6 +33,7 @@ type EditTaskRequestBody struct { Project string `json:"project"` Start string `json:"start"` Entry string `json:"entry"` + Wait string `json:"wait"` } type CompleteTaskRequestBody struct { Email string `json:"email"` diff --git a/backend/utils/tw/edit_task.go b/backend/utils/tw/edit_task.go index f77c8b2..5e36166 100644 --- a/backend/utils/tw/edit_task.go +++ b/backend/utils/tw/edit_task.go @@ -7,7 +7,7 @@ import ( "strings" ) -func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string) error { +func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, wait string) error { if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil { return fmt.Errorf("error deleting Taskwarrior data: %v", err) } @@ -39,6 +39,16 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st } } + // Handle wait date + if wait != "" { + // Convert `2025-11-29` -> `2025-11-29T00:00:00` + formattedWait := wait + "T00:00:00" + + if err := utils.ExecCommand("task", taskID, "modify", "wait:"+formattedWait); err != nil { + return fmt.Errorf("failed to set wait date %s: %v", formattedWait, err) + } + } + // Handle tags if len(tags) > 0 { for _, tag := range tags { diff --git a/backend/utils/tw/taskwarrior_test.go b/backend/utils/tw/taskwarrior_test.go index 02b9248..e4d378b 100644 --- a/backend/utils/tw/taskwarrior_test.go +++ b/backend/utils/tw/taskwarrior_test.go @@ -23,7 +23,7 @@ func TestSyncTaskwarrior(t *testing.T) { } func TestEditTaskInATaskwarrior(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior() failed: %v", err) } else { @@ -68,7 +68,7 @@ func TestAddTaskWithTags(t *testing.T) { } func TestEditTaskWithTagAddition(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior with tag addition failed: %v", err) } else { @@ -77,7 +77,7 @@ func TestEditTaskWithTagAddition(t *testing.T) { } func TestEditTaskWithTagRemoval(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior with tag removal failed: %v", err) } else { @@ -86,7 +86,7 @@ func TestEditTaskWithTagRemoval(t *testing.T) { } func TestEditTaskWithMixedTagOperations(t *testing.T) { - err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") + err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z") if err != nil { t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err) } else { diff --git a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx index 1a447aa..125e7fa 100644 --- a/frontend/src/components/HomeComponents/Tasks/Tasks.tsx +++ b/frontend/src/components/HomeComponents/Tasks/Tasks.tsx @@ -118,6 +118,8 @@ export const Tasks = ( const [editedProject, setEditedProject] = useState( _selectedTask?.project || '' ); + const [isEditingWaitDate, setIsEditingWaitDate] = useState(false); + const [editedWaitDate, setEditedWaitDate] = useState(''); const [isEditingStartDate, setIsEditingStartDate] = useState(false); const [editedStartDate, setEditedStartDate] = useState(''); const [isEditingEntryDate, setIsEditingEntryDate] = useState(false); @@ -324,7 +326,8 @@ export const Tasks = ( taskID: string, project: string, start: string, - entry: string + entry: string, + wait: string ) { try { await editTaskOnBackend({ @@ -338,6 +341,7 @@ export const Tasks = ( project, start, entry, + wait, }); console.log('Task edited successfully!'); @@ -382,7 +386,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.wait ); setIsEditing(false); }; @@ -398,11 +403,31 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.wait ); setIsEditingProject(false); }; + const handleWaitDateSaveClick = (task: Task) => { + task.wait = editedWaitDate; + + handleEditTaskOnBackend( + props.email, + props.encryptionSecret, + props.UUID, + task.description, + task.tags, + task.id.toString(), + task.project, + task.start, + task.entry || '', + task.wait + ); + + setIsEditingWaitDate(false); + }; + const handleStartDateSaveClick = (task: Task) => { task.start = editedStartDate; @@ -415,7 +440,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.wait ); setIsEditingStartDate(false); @@ -433,7 +459,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry + task.entry, + task.wait ); setIsEditingEntryDate(false); @@ -529,7 +556,8 @@ export const Tasks = ( task.id.toString(), task.project, task.start, - task.entry || '' + task.entry || '', + task.wait ); setIsEditingTags(false); // Exit editing mode @@ -1154,7 +1182,65 @@ export const Tasks = ( Wait: - {formattedDate(task.wait)} + {isEditingWaitDate ? ( + + + setEditedWaitDate( + date + ? format( + date, + 'yyyy-MM-dd' + ) + : '' + ) + } + /> + + + handleWaitDateSaveClick(task) + } + > + + + + + setIsEditingWaitDate(false) + } + > + + + + ) : ( + <> + + {formattedDate(task.wait)} + + { + setIsEditingWaitDate(true); + setEditedWaitDate( + task?.wait ?? '' + ); + }} + > + + + > + )} diff --git a/frontend/src/components/HomeComponents/Tasks/hooks.ts b/frontend/src/components/HomeComponents/Tasks/hooks.ts index 83be616..26f9f34 100644 --- a/frontend/src/components/HomeComponents/Tasks/hooks.ts +++ b/frontend/src/components/HomeComponents/Tasks/hooks.ts @@ -91,6 +91,7 @@ export const editTaskOnBackend = async ({ project, start, entry, + wait, }: { email: string; encryptionSecret: string; @@ -102,6 +103,7 @@ export const editTaskOnBackend = async ({ project: string; start: string; entry: string; + wait: string; }) => { const response = await fetch(`${backendURL}edit-task`, { method: 'POST', @@ -115,6 +117,7 @@ export const editTaskOnBackend = async ({ project, start, entry, + wait, }), headers: { 'Content-Type': 'application/json',